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

家住魔仙堡 提交于 2019-12-10 14:24:27

问题


When I try to restart nginx with sudo /etc/init.d/nginx restart I get the message from the subject.

I discovered that the reason is most likely that the script doesn't know how to stop the deamon because the pid file (/var/run/nginx.pid) is not created on start.

I have two installations on two different servers... one was compiled from source and the other came with phusion passenger.

I tried this command:

start-stop-daemon --start --quiet --pidfile /var/run/nginx.pid --exec /usr/sbin/nginx -- -c /etc/nginx/nginx.conf

on both machines and on one the pid file is created and on the other it is not - on that machine the paths are a bit different (but I don't think this is relevant):

start-stop-daemon --start --quiet --pidfile /var/run/nginx.pid --exec /opt/nginx/sbin/nginx -- -c /opt/nginx/conf/nginx.conf

The process starts and pid is not written...

I'm on Debian...

Any suggestions?


回答1:


The solution is to uncomment this line in nginx.conf:

pid        /var/run/nginx.pid;

It looks like different installations do it differently but the right thing is to uncomment it.




回答2:


I was able to fix this by running the following fuser command

$ sudo fuser -k 80/tcp

which kills whatever process is using port 80..hopefully didn't screw anything else.

Credit for this goes to: https://goo.gl/6oc0xD




回答3:


$ sudo nginx -t 

to see all processes, sometimes you do not have the full permission



来源:https://stackoverflow.com/questions/15983050/restarting-nginx-nginxnginx-emerg-bind-to-0-0-0-080-failed-98-address-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!