Nginx Restart failed - Need help

I do not know what happened to the NGINX installation on my RASPI 4. A few days ago I deleted an folder in the directory “/var/www”. After this the test of Nginx “nginx -t” told me an error of a symlink to the deleted directory. I unlinked the symlink and the error was fixed.

But at the same time the NGINX server had problems. (Maybe after an update?)

The command “sudo systemctl reload nginx” told to me:

root@DietPi:/# sudo systemctl reload nginx
nginx.service is not active, cannot reload.
root@DietPi:/# sudo systemctl start nginx
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
root@DietPi:/# systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2022-03-28 07:51:51 BST; 18s ago
       Docs: man:nginx(8)
    Process: 24616 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 24617 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
        CPU: 47ms

Mar 28 07:51:49 DietPi nginx[24617]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 28 07:51:49 DietPi nginx[24617]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Mar 28 07:51:50 DietPi nginx[24617]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 28 07:51:50 DietPi nginx[24617]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Mar 28 07:51:50 DietPi nginx[24617]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 28 07:51:50 DietPi nginx[24617]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Mar 28 07:51:51 DietPi nginx[24617]: nginx: [emerg] still could not bind()
Mar 28 07:51:51 DietPi systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Mar 28 07:51:51 DietPi systemd[1]: nginx.service: Failed with result 'exit-code'.
Mar 28 07:51:51 DietPi systemd[1]: Failed to start A high performance web server and a reverse proxy server.

After this I stopped NGINX and started again:

sudo systemctl start nginx
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.

systemctl status nginx.service:

● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2022-03-28 07:53:33 BST; 9min ago
       Docs: man:nginx(8)
    Process: 24634 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 24635 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
        CPU: 47ms

Mar 28 07:53:32 DietPi nginx[24635]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 28 07:53:32 DietPi nginx[24635]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Mar 28 07:53:32 DietPi nginx[24635]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 28 07:53:32 DietPi nginx[24635]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Mar 28 07:53:33 DietPi nginx[24635]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 28 07:53:33 DietPi nginx[24635]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Mar 28 07:53:33 DietPi nginx[24635]: nginx: [emerg] still could not bind()
Mar 28 07:53:33 DietPi systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Mar 28 07:53:33 DietPi systemd[1]: nginx.service: Failed with result 'exit-code'.
Mar 28 07:53:33 DietPi systemd[1]: Failed to start A high performance web server and a reverse proxy server.

journalctl -xe: (The output is much longer than this posting!)

-- Journal begins at Sat 2022-03-26 13:03:50 GMT, ends at Mon 2022-03-28 07:53:33 BST. --
Mar 27 07:30:01 DietPi CRON[11345]: (root) CMD (   PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker local)
Mar 27 07:30:01 DietPi CRON[11344]: pam_unix(cron:session): session closed for user root
Mar 27 07:39:01 DietPi CRON[11403]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Mar 27 07:39:01 DietPi CRON[11404]: (root) CMD (  [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi)
Mar 27 07:39:01 DietPi systemd[1]: Starting Clean php session files...
░░ Subject: A start job for unit phpsessionclean.service has begun execution
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit phpsessionclean.service has begun execution.
░░ 
░░ The job identifier is 3433.
Mar 27 07:39:01 DietPi CRON[11403]: pam_unix(cron:session): session closed for user root
Mar 27 07:39:01 DietPi systemd[1]: phpsessionclean.service: Succeeded.
░░ Subject: Unit succeeded
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The unit phpsessionclean.service has successfully entered the 'dead' state.
Mar 27 07:39:01 DietPi systemd[1]: Finished Clean php session files.
░░ Subject: A start job for unit phpsessionclean.service has finished successfully
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit phpsessionclean.service has finished successfully.
░░ 
░░ The job identifier is 3433.
Mar 27 07:40:01 DietPi CRON[11456]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Mar 27 07:40:01 DietPi CRON[11457]: (root) CMD (   PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker local)
Mar 27 07:40:01 DietPi CRON[11456]: pam_unix(cron:session): session closed for user root
Mar 27 07:50:01 DietPi CRON[11518]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Mar 27 07:50:01 DietPi CRON[11519]: (root) CMD (   PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker local)
Mar 27 07:50:01 DietPi CRON[11518]: pam_unix(cron:session): session closed for user root
Mar 27 08:00:01 DietPi CRON[11573]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Mar 27 08:00:01 DietPi CRON[11574]: (root) CMD (   PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker local)
Mar 27 08:00:01 DietPi CRON[11573]: pam_unix(cron:session): session closed for user root
Mar 27 08:09:01 DietPi CRON[11635]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Mar 27 08:09:01 DietPi CRON[11636]: (root) CMD (  [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi)
Mar 27 08:09:01 DietPi CRON[11635]: pam_unix(cron:session): session closed for user root
Mar 27 08:09:01 DietPi systemd[1]: Starting Clean php session files...
░░ Subject: A start job for unit phpsessionclean.service has begun execution
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit phpsessionclean.service has begun execution.
░░ 
░░ The job identifier is 3501.
Mar 27 08:09:01 DietPi systemd[1]: phpsessionclean.service: Succeeded.
░░ Subject: Unit succeeded
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The unit phpsessionclean.service has successfully entered the 'dead' state.
Mar 27 08:09:01 DietPi systemd[1]: Finished Clean php session files.
░░ Subject: A start job for unit phpsessionclean.service has finished successfully
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit phpsessionclean.service has finished successfully.
░░ 
░░ The job identifier is 3501.
Mar 27 08:10:01 DietPi CRON[11689]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Mar 27 08:10:01 DietPi CRON[11690]: (root) CMD (   PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker local)
Mar 27 08:10:01 DietPi CRON[11689]: pam_unix(cron:session): session closed for user root
Mar 27 08:17:01 DietPi CRON[11734]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Mar 27 08:17:01 DietPi CRON[11735]: (root) CMD (cd / && run-parts --report /etc/cron.hourly)
Mar 27 08:17:01 DietPi CRON[11734]: pam_unix(cron:session): session closed for user root
Mar 27 08:20:01 DietPi CRON[11794]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Mar 27 08:20:01 DietPi CRON[11795]: (root) CMD (   PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker local)
Mar 27 08:20:01 DietPi CRON[11794]: pam_unix(cron:session): session closed for user root
Mar 27 08:30:01 DietPi CRON[11853]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Mar 27 08:30:01 DietPi CRON[11854]: (root) CMD (   PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker local)
Mar 27 08:30:01 DietPi CRON[11853]: pam_unix(cron:session): session closed for user root
Mar 27 08:39:01 DietPi CRON[11910]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Mar 27 08:39:01 DietPi CRON[11911]: (root) CMD (  [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi)
Mar 27 08:39:01 DietPi systemd[1]: Starting Clean php session files...
░░ Subject: A start job for unit phpsessionclean.service has begun execution
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit phpsessionclean.service has begun execution.
░░ 
░░ The job identifier is 3569.
Mar 27 08:39:01 DietPi CRON[11910]: pam_unix(cron:session): session closed for user root
Mar 27 08:39:02 DietPi systemd[1]: phpsessionclean.service: Succeeded.
░░ Subject: Unit succeeded
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The unit phpsessionclean.service has successfully entered the 'dead' state.
Mar 27 08:39:02 DietPi systemd[1]: Finished Clean php session files.
░░ Subject: A start job for unit phpsessionclean.service has finished successfully
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit phpsessionclean.service has finished successfully.
░░

What can I do?

Nginx is not able to bind to port 80. It seems there is another web server running already

bind() to 0.0.0.0:80 failed (98: Address already in use)

Can you check for LISTEN ports. Maybe we will see which app using port 80

ss -tulpn | grep LISTEN
 tcp   LISTEN 0      256          127.0.0.1:8953       0.0.0.0:*    users:(("unbound",pid=474,fd=6))      
tcp   LISTEN 0      50             0.0.0.0:445        0.0.0.0:*    users:(("smbd",pid=575,fd=44))        
tcp   LISTEN 0      128            0.0.0.0:5252       0.0.0.0:*    users:(("dietpi-dashboar",pid=437,fd=6))
tcp   LISTEN 0      5            127.0.0.1:4711       0.0.0.0:*    users:(("pihole-FTL",pid=477,fd=10))  
tcp   LISTEN 0      80           127.0.0.1:3306       0.0.0.0:*    users:(("mariadbd",pid=643,fd=19))    
tcp   LISTEN 0      50             0.0.0.0:139        0.0.0.0:*    users:(("smbd",pid=575,fd=45))        
tcp   LISTEN 0      1024           0.0.0.0:80         0.0.0.0:*    users:(("lighttpd",pid=1157,fd=4))    
tcp   LISTEN 0      32             0.0.0.0:53         0.0.0.0:*    users:(("pihole-FTL",pid=477,fd=5))   
tcp   LISTEN 0      128            0.0.0.0:22         0.0.0.0:*    users:(("sshd",pid=473,fd=3))         
tcp   LISTEN 0      256          127.0.0.1:5335       0.0.0.0:*    users:(("unbound",pid=474,fd=4))      
tcp   LISTEN 0      256              [::1]:8953          [::]:*    users:(("unbound",pid=474,fd=5))      
tcp   LISTEN 0      50                [::]:445           [::]:*    users:(("smbd",pid=575,fd=42))        
tcp   LISTEN 0      5                [::1]:4711          [::]:*    users:(("pihole-FTL",pid=477,fd=16))  
tcp   LISTEN 0      50                [::]:139           [::]:*    users:(("smbd",pid=575,fd=43))        
tcp   LISTEN 0      1024              [::]:80            [::]:*    users:(("lighttpd",pid=1157,fd=5))    
tcp   LISTEN 0      128                  *:21               *:*    users:(("proftpd",pid=553,fd=0))      
tcp   LISTEN 0      32                [::]:53            [::]:*    users:(("pihole-FTL",pid=477,fd=7))   
tcp   LISTEN 0      128               [::]:22            [::]:*    users:(("sshd",pid=473,fd=4))

I forgotten to tell you, that I can not see the Pihole Dashboard. The default nginx site is only showing “Access denied”.

There is another web server lighttpd running. This is conflicting with Nginx and preventing Nginx to start. Did have done any repair function on PiHole?

Repair function?

This was just a question. Because if you select the wrong option, PiHole will install a web server, conflicting the current setup. Do you remember why you have 2 web server installed? Any action done in the past days before Nginx stopped working? Can you share your installed software

dietpi-software list | grep " =2 "

Your command is not working.

I have installed Pihole via SC of DietPi. I missed the selection of webserver maybe.
Then I installed NGINX to use locally for a Website and other.

A web server is automatically installed together with PiHole. There is no need to install another web server in addition.

There was a typo on my command. Try again

dietpi-software list | grep " =2 "
    ~# dietpi-software list | grep " =2 "
ID 0 | =2 | OpenSSH Client: Feature-rich SSH, SFTP and SCP client |
ID 1 | =2 | Samba Client: access SMB/CIFS/Samba network shares | |  dietpi-drive_manager > Add network drive
ID 5 | =2 | ALSA: Advanced Linux Sound Architecture |
ID 17 | =2 | Git: Clone and manage Git repositories locally |
ID 57 | =2 | Baïkal: lightweight caldav + carddav server | +MariaDB +PHP +webserver | https://dietpi.com/docs/software/social/#baikal
ID 73 | =2 | Fail2Ban: prevents brute-force attacks with ip ban | | https://dietpi.com/docs/software/system_security/#fail2ban
ID 78 | =2 | LESP: Nginx    | SQLite  | PHP | +Nginx +SQLite +PHP | https://dietpi.com/docs/software/webserver_stack/#lesp-web-stack
ID 79 | =2 | LEMP: Nginx    | MariaDB | PHP | +Nginx +MariaDB +PHP | https://dietpi.com/docs/software/webserver_stack/#lemp-web-stack
ID 84 | =2 | Lighttpd: Extremely lightweight webserver | +PHP | https://dietpi.com/docs/software/webserver_stack/#lighttpd
ID 85 | =2 | Nginx: Lightweight webserver | +PHP | https://dietpi.com/docs/software/webserver_stack/#nginx
ID 87 | =2 | SQLite: Persistent single-file database system | | https://dietpi.com/docs/software/databases/#sqlite
ID 88 | =2 | MariaDB: Persistent cached file-per-table database server | | https://dietpi.com/docs/software/databases/#mariadb
ID 89 | =2 | PHP: Hypertext Preprocessor for dynamic web content | | https://dietpi.com/docs/software/webserver_stack/#php
ID 90 | =2 | phpMyAdmin: Optional MariaDB web interface admin tools | +MariaDB +PHP +webserver | https://dietpi.com/docs/software/databases/#phpmyadmin
ID 93 | =2 | Pi-hole: block adverts for any device on your network | +Git +PHP +webserver | https://dietpi.com/docs/software/dns_servers/#pi-hole
ID 94 | =2 | ProFTPD: Efficient, lightweight FTP server | | https://dietpi.com/docs/software/file_servers/#proftpd
ID 96 | =2 | Samba Server: Feature-rich SMB/CIFS server | | https://dietpi.com/docs/software/file_servers/#samba
ID 103 | =2 | DietPi-RAMlog: Makes /var/log a RAM disk, preserves file structure on reboot | | https://dietpi.com/docs/software/log_system/#dietpi-ramlog
ID 105 | =2 | OpenSSH Server: Feature-rich SSH server with SFTP and SCP support | +OpenSSH Client | https://dietpi.com/docs/software/ssh/#openssh
ID 152 | =2 | Avahi-Daemon: hostname broadcast (mac, pc bonjour) |
ID 182 | =2 | Unbound: validating, recursive, caching DNS resolver | | https://dietpi.com/docs/software/dns_servers/#unbound
ID 200 | =2 | DietPi-Dashboard (beta): Official lightweight DietPi web interface (Rust) | | https://dietpi.com/docs/software/system_stats/#dietpi-dashboard

I never installed Lemp or Lesp. I do not why they are in the list.

LESP or LEMP are not the issue. It’s basically a web server stack installed to provide a database + PHP for Baïkal and Pi-hole.

Your issue, as already sated above, is the fact that you have 2 web server installed. Nginx and Lighttpd. Honestly I’m not sure how you did that, because our install scripts should prevent exactly this. Btw, what is your DietPi version?

For testing you could stop Lighttpd and restart Nginx

systemctl stop lighttpd
systemctl restart nginx

I stopped lighttpd und restarted nginx. Now, Pihole Dashboard is back and the rest nginx services too.

My DietP Version is: v8.2.2 : 05:43 - Tue 03/29/22

Do I have to uninstall lighttpd now?

yes, basically lighttpd should be removed. But still the question how did you managed to have 2 web server installed. Mysterious :sunglasses:

I have really no idea how I could use two different webservers on the system. First I installed PiHole with lighttpd and much later I changed it for using NGINX. I stopped lighttpd after changing the server.

I stopped lighttpd after changing the server.

Maybe that’s the issue? You just stopped lighttpd and did not removed it?

It could be. :thinking: