I got a problem which I have been trying to fix for a few days now and I don't know what to do, have been looking for answers but all of those I found didn't help me.
I am kinda new here and I really hope that someone can help me. You can tell me which informations I need to give in hope for finding a solution.
$ 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.
When something cannot bind to a port, it's 5% because it's not started by root (sticky suid bit, sudo) and 94% because another application is already bound to that port.
Make sure nginx is really shutdown and you don't try to start it twice by accident.
Make sure you don't have Apache or other services running that use port 80.
Utilize
netstat -a | grep tcp
to find out more.This worked for me:
First, go to
cd /etc/nginx
and make the changes in nginx.conf and make the default port to listen from 80 to any of your choice 85 or something.
Then use this command to bind that port type for nginx to use it:
semanage port -a -t PORT_TYPE -p tcp 85
where PORT_TYPE is one of the following: http_cache_port_t, http_port_t, jboss_management_port_t, jboss_messaging_port_t, ntop_port_t, puppet_port_t.
Then run:
sudo systemctl start nginx; #sudo systemctl status nginx
[you should see active status]; #sudo systemctl enable nginx
use these command to
sudo service apache2 stop
sudo apt-get purge apache2
sudo apt-get update
sudo apt-get install nginx
sudo service nginx restart
I had the same problem when I used Vesta, which uses nginx with apache. The problem was that after applying all updates Apache started listening to 443 for https. The solution was just to comment out the 443 stuff in ports.conf. This is because nginx also uses this port.
May come in handy to check syntax of Nginx's configuration files by running:
or set back
/etc/nginx/sites-available/default