nginx经验分享

  • 如果我们在使用启动nginx时,遇到这样的提示:

nginx: [alert] could not open error log file: open() "/usr/local/var/log/nginx/error.log" failed (13: Permission denied)

那代表我们没有操作权限,只需要在命令前加上sudo,即可以最高权限去操作,如:

sudo nginx
sudo nginx -s reload | stop | reopen
  • 如果我们在启动nginx时报错,例如这样的提示:

nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)

那代表80端口被占用(包括nginx本身已启动占用的80端口)

我们只需要停止占用占用80端口的服务即可,例如停止已开启的nginx

sudo nginx -s stop
  • 如果我们在停止或者重启nginx的时候报错,例如这样的提示:

nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)

是因为没有找到nginx.pid这个文件,当我们停止nginx时(nginx -s stop) ,nginx 会把 /usr/local/var/run/ 路径下名为nginx.pid 的文件删掉

我们可以直接启动nginx,重新生成nginx.pid文件即可

nginx 或 sudo nginx
  • 若直接启动还是报错,那查看一下nginx配置文件
nginx -t 或 sudo nginx -t

一般是这样的提示:

nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok

nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

然后我们指定下conf文件:

nginx -c /usr/local/etc/nginx/nginx.conf
或 sudo nginx -c /usr/local/etc/nginx/nginx.conf

再重启nginx就好啦

 

posted @ 2020-03-12 22:26  Scar007  阅读(231)  评论(0编辑  收藏  举报