启动报错
报错提示:nginx: [alert] could not open error log file: open() "/usr/local/var/log/nginx/error.log" failed
这个错误代表我们没有操作权限,需要权限操作只需要在命令前加上sudo,即可以最高权限去操作:
sudo nginx
sudo nginx -s reload | stop | reopen
报错提示:nginx: [emerg] bind() to 0.0.0.0:80 failed
这个错误代表80端口被占用(包括nginx本身已启动占用的80端口),我们只需要停止占用占用80端口的服务即可,我们可以先查看80端口的占用(查看方式参考 Linux进程命令),然后停掉正在使用的80端口的服务。例如停止已开启的nginx:
sudo nginx -s stop
启动或停止报错
错误提示:nginx: [error] open() "/usr/local/var/run/nginx.pid" failed
是因为没有找到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就好啦
Comments | NOTHING