如下图:
以下是我的做法,供参考:
1.首先,把后端代码恢复到上一次没报错之前的版本,因为nginx报错不一定绝对是nginx的问题,先把系统恢复成可以运行的状态,这是控制变量法呀。
2.重新加载nginx的配置文件
nginx -c /usr/local/webserver/nginx/conf/nginx.conf
如果你不能全局运行nginx命令,请加上nginx的路径。-c后面的参数为nginx配置文件所在路径这是要求nginx重新添加配置文件地址。
nginx -s reload
重新加载文件
3.重新运行,可以看到会出现如下错误:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
可以看到,是进程端口被占用了,可以看系统是否已有nginx在运行。
运行命令:ps -aux | grep nginx
然后对照,发现第一个和第二个的pid分别为130616,130635,kill掉即可。
kill 130616
kill 130635
问题解决,再次运行nginx,一切正常