Nginx: Job for nginx.service failed because the co

2020-05-11 05:53发布

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.

标签: nginx
16条回答
Animai°情兽
2楼-- · 2020-05-11 06:23

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2020-05-11 06:24

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

查看更多
Explosion°爆炸
4楼-- · 2020-05-11 06:24
  • use these command to

    1. sudo service apache2 stop

    2. sudo apt-get purge apache2

    3. sudo apt-get update

    4. sudo apt-get install nginx

    5. sudo service nginx restart

查看更多
我只想做你的唯一
5楼-- · 2020-05-11 06:26

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.

查看更多
萌系小妹纸
6楼-- · 2020-05-11 06:32

May come in handy to check syntax of Nginx's configuration files by running:

nginx -t -c /etc/nginx/nginx.conf
查看更多
贼婆χ
7楼-- · 2020-05-11 06:32
$ ps ax | grep nginx<br>
$ kill -9 PIDs
$ service nginx start



or set back /etc/nginx/sites-available/default

location / {
     # First attempt to serve request as file, then
     # as directory, then fall back to displaying a 404.

     try_files $uri $uri/ =404;
}

查看更多
登录 后发表回答