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条回答
啃猪蹄的小仙女
2楼-- · 2020-05-11 06:32

For my case, I need to run

sudo nginx -t

It will check if Nginx configuration is correct or not, if not, it will show you which configuration causes the error.

Then you need to go to /etc/nginx/sites-available to fix the broken configuration.

After that, you can restart Nginx without any problem.

sudo systemctl restart nginx
查看更多
ゆ 、 Hurt°
3楼-- · 2020-05-11 06:34

In my case, nginx was not able to open the log file which is located here /var/log/nginx/error.log

This was because I had deleted the log directory to free up space in root (which turned out to be stupid)

I then created a log folder in var and an nginx folder in log.

Then simply run sudo service nginx start

查看更多
别忘想泡老子
4楼-- · 2020-05-11 06:34

Check df -h if you are under centOS system

查看更多
SAY GOODBYE
5楼-- · 2020-05-11 06:37

change the port may help as 80 port is already using somewhere

vi /etc/nginx/sites-available/default

Change the port:

listen 8080 default_server;
listen [::]:8080 default_server;

And then restart the nginx server

nginx -t
service nginx restart
查看更多
可以哭但决不认输i
6楼-- · 2020-05-11 06:39

Try to debug with command:

$ service nginx configtest

Which outputs something like:

Testing nginx configuration: nginx: [emerg] unknown directive "stub_status" in /etc/nginx/sites-enabled/nginx_status:11
nginx: configuration file /etc/nginx/nginx.conf test failed

And fix those warnings

Then restart nginx

查看更多
该账号已被封号
7楼-- · 2020-05-11 06:40

Try set a user in nginx.conf, maybe that's why he can not start the service:

User www-data;
查看更多
登录 后发表回答