I try to start this service but i can´t, the error below occur:
root@zabbix:/home/appliance# systemctl status nginx.service
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 Wed 2018-07-25 18:33:26 UTC; 1min 27s ago
Process: 30040 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Process: 30037 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Jul 25 18:33:25 zabbix nginx[30040]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:25 zabbix nginx[30040]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:25 zabbix nginx[30040]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:26 zabbix nginx[30040]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:26 zabbix nginx[30040]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:26 zabbix nginx[30040]: nginx: [emerg] still could not bind()
Jul 25 18:33:26 zabbix systemd[1]: nginx.service: Control process exited, code=exited status=1
Jul 25 18:33:26 zabbix systemd[1]: *******Failed to start A high performance web server*** and a reverse proxy server.****
Jul 25 18:33:26 zabbix systemd[1]: nginx.service: Unit entered failed state.
Jul 25 18:33:26 zabbix systemd[1]: nginx.service: Failed with result 'exit-code'.
asked Jul 25, 2018 at 18:43
You already have a process bound to the HTTP port 80. (Specially after upgrading systems! it will start apache2 by default)
So first try this:
sudo service apache2 stop
sudo systemctl restart nginx
If problem is not solved then run this command sudo lsof -i:80
to get a list of processes using the port and then stop or disable web server.
Try to stop the process which are using the port 80 using:
sudo fuser -k 80/tcp
sudo systemctl restart nginx
In some cases it may be some issues in the configuration file.
You can use nginx -t -c /etc/nginx/nginx.conf
command to find any miss-configuration.
In some cases this error is caused by a default Nginx site already on port 80. Removing default config works if you don’t need a default one!
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
answered May 31, 2020 at 12:13
Mahdi YounesiMahdi Younesi
6,5192 gold badges19 silver badges50 bronze badges
5
For me this error was caused by a default
nginx site already on port 80. Removing default site worked
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
answered Dec 13, 2019 at 21:54
frmbelzfrmbelz
1,86924 silver badges24 bronze badges
1
You already have a process bound to the HTTP port 80.
You can run command sudo lsof -i:80
to get a list of processes using the port and then stop/disable web server.
answered Jul 25, 2018 at 21:16
Try to stop the process which are using the port 80:
sudo fuser -k 80/tcp
snoob dogg
2,5102 gold badges27 silver badges49 bronze badges
answered Feb 18, 2019 at 11:01
2
Try to stop the process which is using port 80:
sudo fuser -k 80/tcp
When you did restart using
sudo systemctl restart nginx
answered Sep 26, 2020 at 5:01
SudhanSudhan
1813 silver badges12 bronze badges
It may be some issues in the configuration file. You can use this
nginx -t -c /etc/nginx/nginx.conf
command to find any bugs in the configuration file. If you find the bugs resolve that run the sudo service nginx restart
again. It will work.
Please check the reference here
answered Nov 1, 2019 at 8:19
sanzmalzsanzmalz
4184 silver badges12 bronze badges
In my experience, this error can be triggered in several different situations (which might have the same root, but are perceived as different scenarios).
Not only port 80
Depending on your nginx config, you should also try port 443:
sudo lsof -i:80
sudo lsof -i:443
You should be able to check your nginx listen ports in /etc/nginx/sites-enabled
(under Debian)
Special case
In my case, there was an nginx instance running, that would block itself from restarting. It would not go down with sudo systemctl stop nginx
. I had to use sudo killall nginx
and could then use sudo systemctl start nginx
.
Config error
I also experienced the exact same error message on a config error.
You can check your nginx config with /usr/sbin/nginx -c /etc/nginx/nginx.conf@ (this will also test all virtual host files (
/etc/nginx/sites-enabled`)
answered Sep 13, 2020 at 8:59
DarkTrickDarkTrick
1,8531 gold badge15 silver badges33 bronze badges
i had same issue, was because i have apache and nginx on same server !
so when i typed sudo reboot it didn’t work because it started apache while am using nginx so i just run this two commands
sudo systemctl stop apache2
then
sudo systemctl start nginx
then sudo systemctl disable apache2
so next time i reboot not going to face same issue
help from aws services support
answered Dec 2, 2020 at 23:38
1
I had to use:
sudo killall nginx
And could then use;
sudo systemctl start nginx
benson23
11.2k8 gold badges17 silver badges33 bronze badges
answered Feb 24, 2022 at 21:44
0
For me stopping apache service solved the problem
sudo service apache2 stop
answered Oct 31, 2020 at 3:38
sudaynsudayn
1,09411 silver badges14 bronze badges
0
I had this problem too. I checked the /etc/nginx/site-available/default
file and I have forgotten to close the bracket (syntax error).
סטנלי גרונן
2,87923 gold badges48 silver badges66 bronze badges
answered May 8, 2020 at 4:43
Just restart the nginx server. It should resolve your problem
sudo systemctl restart nginx
answered Oct 22, 2022 at 14:05
I was using gunicorn with nginx, found that service was not active.
sudo systemctl enable gunicorn.socket
sudo systemctl start gunicorn.socket
sudo systemctl restart nginx
Worked for me.
if your gunicorn is active, please make sure it’s working fine.
you can also go through the logs(errors) via nginx logs
from
sudo tail -f /var/log/nginx/error.log
answered Aug 20, 2022 at 11:56
I recently tried to install LetsEncrypt certificate, but I couldn’t start nginx again. when I run the command service nginx status
.
I get this error message:
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 Tue 2018-02-20 16:17:49 CET; 8min
ago
Process: 1439 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on;
master_process on; (code=exited, status=1/FAILURE)
Feb 20 16:17:47 django-s-1vcpu-1gb-lon1-01 systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 20 16:17:49 django-s-1vcpu-1gb-lon1-01 nginx[1439]: nginx: [emerg] "location" directive is not allowed here in /etc/nginx/nginx.conf:87
Feb 20 16:17:49 django-s-1vcpu-1gb-lon1-01 nginx[1439]: nginx: configuration file /etc/nginx/nginx.conf test failed
Feb 20 16:17:49 django-s-1vcpu-1gb-lon1-01 systemd[1]: nginx.service: Control process exited, code=exited status=1
Feb 20 16:17:49 django-s-1vcpu-1gb-lon1-01 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Feb 20 16:17:49 django-s-1vcpu-1gb-lon1-01 systemd[1]: nginx.service: Unit entered failed
Feb 20 16:17:49 django-s-1vcpu-1gb-lon1-01 systemd[1]: nginx.service: Failed with result 'exit-code'.
And here is /etc/nginx/sites-avalible/django
:
upstream app_server {
server unix:/home/django/gunicorn.socket fail_timeout=0;
}
server {
#listen 80 default_server;
#listen [::]:80 default_server ipv6only=on;
listen 443 ssl;
server_name nettside.no;
ssl_certificate /etc/letsencrypt/live/nettside.no/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/nettside.no/privkey.pem;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 4G;
server_name nettside.no;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/django/django_project/django_project/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/django/django_project/static;
}
# Proxy the static assests for the Django Admin panel
location /static/admin {
alias /home/django/django_project/static/admin;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://app_server;
}
}
server {
listen 80;
server_name nettside.no;
return 301 https://$host$request_uri;
}
I have run nginx -t
and it returns successful.
On boot I see messages about nginx has failed to start, and it wont start when I try nginx
or service nginx start
Instead i get a message to check journal -xn
and systemctl
.
Here is what I get when I check those… Can someone help me get this running?
root@e:/home/matt# systemctl status nginx.service • nginx.service -
A high performance web server and a reverse proxy server Loaded:
loaded (/lib/systemd/system/nginx.service; enabled) Active: failed
(Result: exit-code) since Mon 2015-02-16 13:36:23 EST; 22s ago
Process: 1071 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on;
master_process on; (code=exited, status=1/FAILURE)
Feb 16 13:36:23 e nginx[1071]: nginx: [emerg] "daemon" directive is
duplicate in /etc/nginx/nginx.conf:87 Feb 16 13:36:23 e nginx[1071]:
nginx: configuration file /etc/nginx/nginx.conf test failed Feb 16
13:36:23 e systemd[1]: nginx.service: control process exited,
code=exited status=1 Feb 16 13:36:23 e systemd[1]: Failed to start A
high performance web server and a reverse proxy server. Feb 16
13:36:23 e systemd[1]: Unit nginx.service entered failed state.
root@e:/home/matt# journalctl -xn
-- Logs begin at Mon 2015-02-16 13:34:47 EST, end at Mon 2015-02-16 13:41:06 EST. -- Feb 16 13:36:23 e systemd[1]: Failed to start A high
performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has failed.
--
-- The result is failed. Feb 16 13:36:23 e systemd[1]: Unit nginx.service entered failed state. Feb 16 13:39:01 e CRON[1086]:
pam_unix(cron:session): session opened for user root by (uid=0) Feb 16
13:39:01 e CRON[1087]: (root) CMD ( [ -x /usr/lib/php5/sessionclean ]
&& /usr/lib/php5/sessionclean) Feb 16 13:39:01 e CRON[1086]:
pam_unix(cron:session): session closed for user root Feb 16 13:41:06 e
nginx[1129]: nginx: [emerg] "daemon" directive is duplicate in
/etc/nginx/nginx.conf:87 Feb 16 13:41:06 e nginx[1129]: nginx:
configuration file /etc/nginx/nginx.conf test failed Feb 16 13:41:06 e
systemd[1]: nginx.service: control process exited, code=exited
status=1 Feb 16 13:41:06 e systemd[1]: Failed to start A high
performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has failed.
--
-- The result is failed. Feb 16 13:41:06 e systemd[1]: Unit nginx.service entered failed state.
systemctl status nginx.service outputs:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2019-01-23 19:04:12 +03; 1min 1s ago
Docs: man:nginx(8)
Process: 10511 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Jan 23 19:04:12 linux systemd[1]: Starting A high performance web server and a reverse proxy server...
Jan 23 19:04:12 linux nginx[10511]: nginx: [emerg] a duplicate default server for [::]:80 in /etc/nginx/sites-enabled/default:23
Jan 23 19:04:12 linux nginx[10511]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jan 23 19:04:12 linux systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Jan 23 19:04:12 linux systemd[1]: nginx.service: Failed with result 'exit-code'.
Jan 23 19:04:12 linux systemd[1]: Failed to start A high performance web server and a reverse proxy server.
journalctl -xe outputs:
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- An ExecStartPre= process belonging to unit nginx.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 1.
Jan 23 19:10:15 linux systemd[1]: nginx.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The unit nginx.service has entered the 'failed' state with result 'exit-code'.
Jan 23 19:10:15 linux systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: A start job for unit nginx.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A start job for unit nginx.service has finished with a failure.
--
-- The job identifier is 2656 and the job result is failed.
Jan 23 19:10:15 linux sudo[10625]: pam_unix(sudo:session): session closed for user root
Jan 23 19:10:23 linux sudo[10631]: lvlzyro : TTY=pts/0 ; PWD=/home/lvlzyro ; USER=root ; COMMAND=/usr/bin/journalctl -xe
Jan 23 19:10:23 linux sudo[10631]: pam_unix(sudo:session): session opened for user root by (uid=0)
nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
What should I do to fix it? Thanks for your attention btw.