Page 1 of 2

nginx failed to restart

Posted: Wed Jun 29, 2016 10:18 am
by rohanmcdermott
Hi,

Im getting a bunch of emails every day at the same time with the following:

Code: Select all

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Stopping nginx: [FAILED]
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 127.0.0.1:8084 failed (98: Address already in use)
nginx: [emerg] bind() to (*myip*):443 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 127.0.0.1:8084 failed (98: Address already in use)
nginx: [emerg] bind() to (*myip*):443 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 127.0.0.1:8084 failed (98: Address already in use)
nginx: [emerg] bind() to (*myip*):443 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 127.0.0.1:8084 failed (98: Address already in use)
nginx: [emerg] bind() to (*myip*):443 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 127.0.0.1:8084 failed (98: Address already in use)
nginx: [emerg] bind() to (*myip*):443 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[FAILED]

Could someone please let me know how I could fix this?

Re: nginx failed to restart

Posted: Wed Jun 29, 2016 11:54 am
by skurudo
Begin with something like this:

Code: Select all

service apache2 stop
service nginx stop
killall apache2
killall nginx
service nginx start
service apache2 start
PS: OS? VestaCP version?

Re: nginx failed to restart

Posted: Wed Jun 29, 2016 12:02 pm
by rohanmcdermott
Hi,

Thanks for the fast reply.

All commands involving apache2 aren't working (apache2: unrecognised service)

OS: CentOS 6.6
Vesta Ver: 0.9.8-16

Re: nginx failed to restart

Posted: Wed Jun 29, 2016 12:36 pm
by rohanmcdermott
When I do: service httpd restart

I see:

Code: Select all

Starting httpd: [Wed Jun 29 14:35:21 2016] [warn] The Alias directive in /etc/ht
tpd/conf/httpd.conf at line 257 will probably never match because it overlaps an
 earlier Alias.

Re: nginx failed to restart

Posted: Wed Jun 29, 2016 4:47 pm
by skurudo
rohanmcdermott wrote:All commands involving apache2 aren't working (apache2: unrecognised service)
apache2 in CentOS has different name - httpd

Re: nginx failed to restart

Posted: Wed Jun 29, 2016 4:48 pm
by skurudo
rohanmcdermott wrote:When I do: service httpd restart

Code: Select all

Starting httpd: [Wed Jun 29 14:35:21 2016] [warn] The Alias directive in /etc/ht
tpd/conf/httpd.conf at line 257 will probably never match because it overlaps an
 earlier Alias.
Try to Rebuild Web first.

Re: nginx failed to restart

Posted: Fri Jul 08, 2016 7:37 pm
by arharp
I'm having a very similar problem. When I stop nginx with "service nginx stop" there aren't any error messages, but nginx continues to run. When I try to restart nginx with "service nginx restart" I get the following:

Code: Select all

root@host:~# 
Job for nginx.service failed. See "systemctl status nginx.service" and "journalctl -xe" for details.
The output for "systemctl status nginx.service" is:

Code: Select all

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2016-07-08 14:26:57 CDT; 34s ago
  Process: 3002 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 2999 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

Jul 08 14:26:56 host nginx[3002]: nginx: [emerg] bind() to {MYIP}:80 failed (98: Address already in use)
Jul 08 14:26:56 host nginx[3002]: nginx: [emerg] bind() to 127.0.0.1:8084 failed (98: Address already in use)
Jul 08 14:26:56 host nginx[3002]: nginx: [emerg] bind() to {MYIP}:80 failed (98: Address already in use)
Jul 08 14:26:57 host nginx[3002]: nginx: [emerg] bind() to 127.0.0.1:8084 failed (98: Address already in use)
Jul 08 14:26:57 host nginx[3002]: nginx: [emerg] bind() to {MYIP}:80 failed (98: Address already in use)
Jul 08 14:26:57 host nginx[3002]: nginx: [emerg] still could not bind()
Jul 08 14:26:57 host systemd[1]: nginx.service: control process exited, code=exited status=1
Jul 08 14:26:57 host systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Jul 08 14:26:57 host systemd[1]: Unit nginx.service entered failed state.
Jul 08 14:26:57 host systemd[1]: nginx.service failed.
Here are the nginx processes that are running:

Code: Select all

ps -ef | grep nginx
root       405     1  0 14:16 ?        00:00:00 nginx: master process /usr/sbin/nginx
www-data   408   405  0 14:16 ?        00:00:00 nginx: worker process
www-data   409   405  0 14:16 ?        00:00:00 nginx: worker process
www-data   410   405  0 14:16 ?        00:00:00 nginx: cache manager process
root       785     1  0 14:16 ?        00:00:00 nginx: master process /usr/local/vesta/nginx/sbin/vesta-nginx
admin      791   785  0 14:16 ?        00:00:00 nginx: worker process
root      3231  2120  0 14:30 pts/0    00:00:00 grep nginx
If I kill the nginx processes with the following code and then restart nginx it works without any problems.

Code: Select all

pkill nginx && service nginx restart && service vesta restart
However, the next time my server is rebooted I have the same exact issue with nginx failing to restart. Any ideas what could be going on? I've searched all over the web and I'm completely stumped.

Re: nginx failed to restart

Posted: Sat Jul 09, 2016 2:12 am
by arharp
I should've mentioned that I'm running the Nginx + PHP-FPM configuration. Apache is not installed and I double-checked that there's no apache2.service or httpd.service. When the system starts up it's Nginx that's bound to port 80, I'm just unable to control the instance with the service or systemctl commands.

Re: nginx failed to restart

Posted: Mon Jul 18, 2016 9:03 am
by radardotnet424
rohanmcdermott wrote:Hi,

Im getting a bunch of emails every day at the same time with the following:

Code: Select all

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Stopping nginx: [FAILED] 
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 127.0.0.1:8084 failed (98: Address already in use)
nginx: [emerg] bind() to (*myip*):443 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 127.0.0.1:8084 failed (98: Address already in use)
nginx: [emerg] bind() to (*myip*):443 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 127.0.0.1:8084 failed (98: Address already in use)
nginx: [emerg] bind() to (*myip*):443 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 127.0.0.1:8084 failed (98: Address already in use)
nginx: [emerg] bind() to (*myip*):443 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 127.0.0.1:8084 failed (98: Address already in use)
nginx: [emerg] bind() to (*myip*):443 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[FAILED]

Could someone please let me know how I could fix this?
Is there any solution?

Re: nginx failed to restart

Posted: Tue Jul 19, 2016 3:39 pm
by arharp
I still haven't been able to figure it out. I'm starting to think my only recourse is to start over from scratch.