nginx.service failed because the control process exited
$ systemctl status nginx.service nginx.service - Startup script for nginx service Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Tue 2016-03-08 13:23:35 GMT; 2min 20s ago Mar 08 13:23:33 startdedicated.com nginx[8315]: nginx: [emerg] bind() to ------------ f...e) Mar 08 13:23:33 startdedicated.com nginx[8315]: nginx: [emerg] bind() to ----- f...e) Mar 08 13:23:34 startdedicated.com nginx[8315]: nginx: [emerg] bind() to ----- f...e) Mar 08 13:23:34 startdedicated.com nginx[8315]: nginx: [emerg] bind() to ----- f...e) Mar 08 13:23:35 startdedicated.com nginx[8315]: nginx: [emerg] bind() to ----- f...e) Mar 08 13:23:35 .startdedicated.com nginx[8315]: nginx: [emerg] still could not bind() Mar 08 13:23:35 startdedicated.com systemd[1]: nginx.service: control process exited, code=...=1 Mar 08 13:23:35 startdedicated.com systemd[1]: Failed to start Startup script for nginx service. Mar 08 13:23:35 startdedicated.com systemd[1]: Unit nginx.service entered failed state. Mar 08 13:23:35 startdedicated.com systemd[1]: nginx.service failed.
Checking NGINX status with status page Edit your NGINX site configuration file and add the following block of code within the server directive. This will allow localhost (127.0. 0.1) to access the page example.com/nginx_status to see the NGINX status page.
Try to run the following two commands:
sudo fuser -k 80/tcp
sudo fuser -k 443/tcp
Then execute
sudo service nginx restart
If that worked, your hosting provider might be installing Apache on your server by default during a fresh install, so keep reading for a more permenant fix. If that didn't work, keep reading to identify the issue.
Run nginx -t
and if it doesn't return anything, I would verify Nginx error log. By default, it should be located in /var/log/nginx/error.log
.
You can open it with any text editor: sudo nano /var/log/nginx/error.log
Can you find something suspicious there?
The second log you can check is the following
sudo nano /var/log/syslog
When I had this issue, it was because my hosting provider was automatically installing Apache during a clean install. It was blocking port 80.
When I executed sudo nano /var/log/nginx/error.log
I got the following as the error log:
2018/08/04 06:17:33 [emerg] 634#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2018/08/04 06:17:33 [emerg] 634#0: bind() to [::]:80 failed (98: Address already in use) 2018/08/04 06:17:33 [emerg] 634#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
What the above error is telling is that it was not able to bind nginx to port 80 because it was already in use.
To fix this, you need to run the following:
yum install net-tools
sudo netstat -tulpn
When you execute the above you will get something like the following:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1762/httpd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1224/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1528/sendmail:acce tcp6 0 0 :::22 :::* LISTEN 1224/sshd
You can see that port 80 is blocked by httpd (Apache). This could also be port 443 if you are using SSL.
Get the PID of the process that uses port 80 or 443. And send the kill command changing the <PID>
value:
sudo kill -2 <PID>
Note in my example the PID value of Apache was 1762
so I would execute sudo kill -2 1762
Aternatively you can execute the following:
sudo fuser -k 80/tcp
sudo fuser -k 443/tcp
Now that port 80 or 443 is clear, you can start Nginx by running the following:
sudo service nginx restart
It is also advisable to remove whatever was previously blocking port 80 & 443. This will avoid any conflict in the future. Since Apache (httpd) was blocking my ports I removed it by running the following:
yum remove httpd httpd-devel httpd-manual httpd-tools mod_auth_kerb mod_auth_mysql mod_auth_pgsql mod_authz_ldap mod_dav_svn mod_dnssd mod_nss mod_perl mod_revocator mod_ssl mod_wsgi
In my case, it's because of apache server is running somehow. So I stop apache then restart nginx. Work like a charm!
sudo /etc/init.d/apache2 stop sudo systemctl restart nginx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With