[SOLVED]Cant close nginx correctly

Discussion in 'Linux Beginners' started by Taxick, Aug 25, 2021.

  1. Taxick

    Taxick Member

    Hi
    I'm a big noob, and I need some help :)

    First some info:
    • OS: Ubuntu 20.04.3 LTS
    • Webserver: nginx/1.18.0 (Ubuntu)
    I'm running a website (A ghost blog) and some other services. (I can list them if needed)

    But I have problems with Nginx! It will not stop/start correctly!

    I use this command to stop Nginx: systemctl stop nginx.service (as root)

    But it not seems to stop correctly!

    If I run lsof -i:80 as root after I have run systemctl stop nginx.service i get this list:

    root@s1:/home/# lsof -i:80 - So it must still be running :/
    Code:
    root@s1:/home# lsof -i:80
    COMMAND  PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    nginx   2254     root    8u  IPv4  33446      0t0  TCP *:http (LISTEN)
    nginx   2254     root    9u  IPv6  33447      0t0  TCP *:http (LISTEN)
    nginx   2262 www-data    8u  IPv4  33446      0t0  TCP *:http (LISTEN)
    nginx   2262 www-data    9u  IPv6  33447      0t0  TCP *:http (LISTEN)
    nginx   2263 www-data    8u  IPv4  33446      0t0  TCP *:http (LISTEN)
    nginx   2263 www-data    9u  IPv6  33447      0t0  TCP *:http (LISTEN)
    nginx   2264 www-data    8u  IPv4  33446      0t0  TCP *:http (LISTEN)
    nginx   2264 www-data    9u  IPv6  33447      0t0  TCP *:http (LISTEN)
    nginx   2265 www-data    8u  IPv4  33446      0t0  TCP *:http (LISTEN)
    nginx   2265 www-data    9u  IPv6  33447      0t0  TCP *:http (LISTEN)
    

    If I try to start Nginx again with this command: systemctl stop nginx.service (as root) I get this error:

    root@s1:/home/# systemctl stop nginx.service
    Job for nginx.service failed because the control process exited with error code.
    See "systemctl status nginx.service" and "journalctl -xe" for details. root@s1:/home/#

    systemctl status nginx.service:


    Code:
    root@s1:/home# 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 2021-08-25 17:41:39 CEST; 12s ago
           Docs: man:nginx(8)
        Process: 4183 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
        Process: 4195 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
    
    Aug 25 17:41:38 futurenode.dk nginx[4195]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
    Aug 25 17:41:38 futurenode.dk nginx[4195]: nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
    Aug 25 17:41:38 futurenode.dk nginx[4195]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    Aug 25 17:41:38 futurenode.dk nginx[4195]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
    Aug 25 17:41:38 futurenode.dk nginx[4195]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
    Aug 25 17:41:38 futurenode.dk nginx[4195]: nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
    Aug 25 17:41:39 futurenode.dk nginx[4195]: nginx: [emerg] still could not bind()
    Aug 25 17:41:39 futurenode.dk systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
    Aug 25 17:41:39 futurenode.dk systemd[1]: nginx.service: Failed with result 'exit-code'.
    Aug 25 17:41:39 futurenode.dk systemd[1]: Failed to start A high performance web server and a reverse proxy server.
    
    From /var/log/nginx/error.log

    Code:
    2021/08/25 17:43:59 [emerg] 4232#4232: still could not bind()
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to [::]:80 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to [::]:443 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to [::]:80 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to [::]:443 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to [::]:80 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to [::]:443 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to [::]:80 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to [::]:443 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to [::]:80 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: bind() to [::]:443 failed (98: Address already in use)
    2021/08/25 17:44:10 [emerg] 4259#4259: still could not bind()
    
    Anyone that can help me out here
    So it's close / start correctly?

    EDIT: It seems if I close the process with kill -9 PID, It stops the server but starts again after 1-2 minutes.

    Regards

    Thomas
     
    Last edited: Aug 25, 2021
  2. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    @Taxick, your images are not showing for me, can you post plain text instead? (put it in code blocks for better formatting)
     
  3. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    You can always kill the service.
     
  4. Taxick

    Taxick Member

    @Jesse Norell
    Hi, thanks for your reply... I have edited my post, so it's without images :) Hope you can see it now?
    @ahrasis
    I know :) But it will be nice if the "systemctl stop nginx.service" works
     
  5. Taxick

    Taxick Member

    EDIT: It seems if I close the process with kill -9 PID, It stops the server but starts again after 1-2 minutes.
     
  6. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    Perhaps that host has monitor software running to restart services that have stopped?
     
    Last edited: Aug 25, 2021
  7. Taxick

    Taxick Member

    Hi @Taleman
    I use Linode, and I have looked at the settings.. Can't find anything!
    EDIT: If it is not on the Linode CP I have to look, maybe you can point me the right way?
     
  8. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    This is normally due to duplicate vhost files or their contents. By the way are you using php-fpm? I also noticed you posted in non ISPConfig category, any reason you are not using it to manage your nginx web server?
     
  9. Taxick

    Taxick Member

    This normally due to duplicate vhost files or their contents. <-- Can you explain?

    What will i need to do?
     
  10. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    Unless the status or error shows which vhost when tested with nginx -t command, you may need to simply disable the site one by one and test nginx again and again; or disable all and enable one by one on each test.
     
  11. Taxick

    Taxick Member

    Hi
    I have disabled all conf in nginx!
    Then I have enabled one by one, and then run nginx -t after all of them
    No - Errors.
    Code:
    root@s1:/home/# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    
    The problem is still not fixed :(
    BTW.. Thanks for you time and help

    EDIT:
    I don't know if it helps, but if I kill all PID that use ports 80 and 443, I can start til nginx without any errors
     
    Last edited: Aug 25, 2021
  12. Taxick

    Taxick Member

    Did someone have an idea how to fix this?
     
  13. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    What does your /lib/systemd/system/nginx.service look like? Do you have a /etc/init/nginx? What's in it? Does 'nginx -s quit' stop nginx?
     
  14. Taxick

    Taxick Member

    Hi @Jesse Norell
    Thanks for your reply. I'm really apricated it.
    Here is my /lib/systemd/system/nginx.service
    Code:
    # Stop dance for nginx
    # =======================
    #
    # ExecStop sends SIGSTOP (graceful stop) to the nginx process.
    # If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control
    # and sends SIGTERM (fast shutdown) to the main process.
    # After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
    # SIGKILL to all the remaining processes in the process group (KillMode=mixed).
    #
    # nginx signals reference doc:
    # http://nginx.org/en/docs/control.html
    #
    [Unit]
    Description=A high performance web server and a reverse proxy server
    Documentation=man:nginx(8)
    After=network.target
    
    [Service]
    Type=forking
    PIDFile=/run/nginx.pid
    ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
    ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
    ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
    ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
    TimeoutStopSec=5
    KillMode=mixed
    
    [Install]
    WantedBy=multi-user.target
    
    
    - I did not have a file or folder with that name -> /etc/init/nginx

    - "nginx -s quit" seems to kill the process. So if I use this command its works.. How to start nginx again?

    Regards

    Thomas
     
  15. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    If nginx test is ok, I don't think you have problems with your vhost files but you claimed starting, stoping or restarting nginx is a problem which seems odd, but revisiting I think there is a mistake in your command line which should just be just nginx not nginx.service.
     
  16. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    I saw on a webpage where nginx was being restarted by upstart, maybe the is something similar going on?
     
  17. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    Or may be your nginx was updated but failed to update properly since mine is currently nginx 1.20 on Ubuntu 20.04.3. Just another guess.
     
  18. Taxick

    Taxick Member

    Hi :)
    Thanks for all your help and replays. I found the error! Maybe a user error!;)
    When I close nginx it shut down OK and there was no problem! I cut stop and start it :)
    But anytime I have tested nginx I also tested certbot renew --dry-run -v to test let's encrypt (certbot).
    Certbot makes a lot of HTTP and HTTPS connections, and then nginx cant not close them probably.
    So if I did not run "certbot renew --dry-run -v" its works fine..
    BTW.. When I run the certbot command, nginx starts automatically again!
    I hope it makes sense!
     
    Last edited: Aug 27, 2021
    ahrasis likes this.
  19. Chris_UK

    Chris_UK Active Member HowtoForge Supporter

    That makes sense, certbot will be checking if nginx is up and if not starting it so that it can perform run the configuration test. It's can't perform the test without the web server being up.
     
  20. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    I think only if your certbot use nginx parameter and not webroot, will it start nginx.

    ISPConfig in its web server setup uses webroot so nginx won't need to be started thereafter.
     

Share This Page