天天看点

mac环境brew安装nginx通用配置

安装:

brew install nginx      

以下是安装完成之后打印出来的提示信息

Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:
  brew services start nginx
Or, if you don't want/need a background service you can just run:
  nginx      

按照提示启动

brew services start nginx      

查看状态:

nginx -t      

如果报错

nginx: [emerg] open() "/usr/local/var/run/nginx.pid" failed (13: Permission denied)      

权限问题

sudo chown -R $(whoami)  /usr/local/var/run  # 具体路径参考报错提示中的路径      

重启nginx服务器

brew services stop nginx   # 停止
brew services start nginx   # 启动      

提示中默认显示8080端口

http://127.0.0.1:8080/

网页中出现下面的文字,就启动成功了

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.      

静态服务器

在路径

/usr/local/var/www

下放入文件

mytest.html

内容如下:

<h1>hello nginx! 2018-07-10</h1>      

通过链接访问测试: 

http://127.0.0.1:8080/mytest.html

通用配置

user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}

http {

    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    client_max_body_size 20M;
    include conf.d/*.conf;
}
      

注意到

include conf.d/*.conf;

 这样就可以将conf.d这个文件夹中的所有配置文件加载进来,实现单独配置,互不影响。

继续阅读