Server

Mac平台nginx相关安装配置

2017-02-14  本文已影响202人  宇行信

安装

我们通过brew来安装nginx
brew install nginx

我在安装过程中出现一个小问题,报了这样一个错误:
Error: Could not symlink share/man/man8/nginx.8 /usr/local/share/man/man8 is not writable.
从上面看大体意思就是/usr/local/share/man/man8这个目录对当前用户无写权限,所以我们给这个目录加上就可以了

drwxr-xr-x   38 SeanLiu  admin  1292  2 13 17:28 man1
drwxr-xr-x  103 SeanLiu  admin  3502  2 13 17:28 man3
drwxr-xr-x    7 root     admin   238  1 22 18:31 man8
-rw-r--r--    1 root     admin  1583  2 10 08:19 whatis

注意事项:

  1. nginx默认安装路径:
    /usr/local/Cellar/nginx/1.10.3
  2. nginx配置文件路径:
    /usr/local/etc/nginx
  3. nginx启动命令
    nginx
  4. 如果出现nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)错误,其实是8080端口被占用了,我们可以通过修改默认端口来避免错误:
    vim /usr/local/etc/nginx/nginx.conf
server {
    listen       8081;  #修改这里为其他端口如8081
    server_name  localhost;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
   }

最后保存重新运行

  1. 更改默认web路径
    默认路径为/usr/local/Cellar/nginx/1.10.3/html
server {
    listen       8081;  #修改这里为其他端口如8081
    server_name  localhost;

    #access_log  logs/host.access.log  main;

    location / {
        root   html; #修改这里的路径为自己的路径 如/Users/xxx/www
        index  index.html index.htm;
   }

然后重启nginx 执行 nginx -s reload 就可以了

  1. 停止
    首先查找到nginx的进程号:
    ps -ef | grep nginx
root       713     1  0 00:15 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data   717   713  0 00:15 ?        00:00:00 nginx: worker process
root      5345  4226  0 15:23 pts/1    00:00:00 grep --color=auto nginx

执行命令 kill -QUIT 713
另外还有两种:
快速停止

`kill -TERM 713`或者`kill -INT 713`

强行停止
pkill -9 nginx

  1. 验证nginx配置文件是否正确
    nginx -t
    出现下面则配置正确
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
上一篇 下一篇

猜你喜欢

热点阅读