Hi DO community!
I know this question has been asked before many times but do believe I have followed everystep mentioned in answers but nothing works.
My website was running very well except when I found out that Multiple image uploads gives 413 request entity too large error and for the sake of solving it I just did the mistake of putting “clientmaxbody_size 100M;” in nginx.conf. From that time till now my website is not getting open and I am getting:

This site can’t be reached
[mydomain] refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERRCONNECTIONREFUSED

I removed the line and restart nginx multiple times but same thing is continuing.
I followed this: https://www.digitalocean.com/community/questions/help-me-to-fix-err_connection_refused
and many others to solve the error but nothing happens.
I have checked out error logs , there is nothing exceptional in them and even now they are not updating to show some new error. I have checked nginx syntax , gunicorn status. Everything is up and fine.
Only one thing that I found weird after running this command sudo journalctl -u nginx:
failed to read pid from file /run/nginx.pid
So I decided to remove this error and followed https://www.digitalocean.com/community/questions/unable-to-start-nginx-failed-to-read-pid-from-file-run-nginx-pid
But still nothing is working out. Do help me out as my running website has just stopped that is causing alot of issue to me.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi there @mahawaqar9875,

Do you have a firewall like UFW enabled on the Droplet? If so I would recommend checking the status and making sure that ports 80 and 443 are open.

Also what I could suggest here is trying the things mentioned in this answer here on how to troubleshoot common Nginx problems and then sharing the output of each command here so that I could try to advise you further:

https://www.digitalocean.com/community/questions/how-to-troubleshoot-common-nginx-issues-on-linux-server

Let me know how it goes!
Regards,
Bobby

  • Hi @bobbyiliev,

    I did sudo ufw status. I get Status: inactive. Nginx status is active and nginx.conf syntax is correct.
    Remaining commands are also good to go.
    Output of netstat -plant | grep '80\|443'

    
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      874/nginx: master p
    tcp        0   1080 159.89.173.221:22       222.186.15.558:49232    ESTABLISHED 1516/sshd: [accepte
    tcp6       0      0 :::80                   :::*                    LISTEN      874/nginx: master p
    
    
    edited by bobbyiliev
    • Hi there @mahawaqar9875,

      This is quite interesting, according to the output everything seems to be working as expected.

      Do you see any entries in your access log as well?

      Regarding the PID error, I can see that a few people reported that the following fixed the error for them:

      First create the following directory:

      • sudo mkdir /etc/systemd/system/nginx.service.d

      After that create a config file to override the Nginx unit file:

      • sudo printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf

      Finally, reload the daemons:

      • sudo systemctl daemon-reload

      Then try restarting Nginx as usual.

      Let me know how it goes!
      Regards,
      Bobby

      • Hi @bobbyiliev ,
        Neither there are entries in access log nor in error log.
        Thing you mentioned regarding PID, I have already done them and they didn’t affect.
        One more thing interesting thing I wanna report is when I do “sudo allow 8000” and run app -
        Simple ip address in browser says “Welcome to Nginx” but ip:8000 again says “ErrorConnectionRefused”

        • Hi there @mahawaqar9875,

          It sounds like Nginx is working all good but there might be a problem with gunicorn.

          Have you looked into your gunicorn logs for some more information?

          • sudo journalctl -u gunicorn

          Feel free to share the output here as well.

          Regards,
          Bobby

          • @bobbyiliev Have a look at the gunicorn logs output. These are the last few entries in gunicorn logs since Jun 03 when website was running. Nothing has been outputted after that:

            Jun 03 06:46:53 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[9291]:  - - [03/Jun/2020:11:46:53 +0500] "GET / HTTP/1.0" 200 16351 "-" "Mozilla/
            Jun 03 06:47:34 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[9291]:  - - [03/Jun/2020:11:47:34 +0500] "GET / HTTP/1.0" 200 16351 "-" "Mozilla/
            Jun 03 06:53:14 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[9291]: [2020-06-03 06:53:14 +0000] [9291] [INFO] Handling signal: term
            Jun 03 06:53:14 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[9291]: [2020-06-03 11:53:14 +0500] [9310] [INFO] Worker exiting (pid: 9310)
            Jun 03 06:53:14 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Stopping gunicorn daemon...
            Jun 03 06:53:14 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[9291]: [2020-06-03 11:53:14 +0500] [9312] [INFO] Worker exiting (pid: 9312)
            Jun 03 06:53:14 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[9291]: [2020-06-03 11:53:14 +0500] [9313] [INFO] Worker exiting (pid: 9313)
            Jun 03 06:53:15 ubuntu-s-1vcpu-1gb-blr1-01 gunicorn[9291]: [2020-06-03 06:53:15 +0000] [9291] [INFO] Shutting down: Master
            
            

            Do suggest me some way out. Anxiously waiting for feedback.

          • Hi there @mahawaqar9875,

            I’m unable to see anything suspicious from all of the commands that you’ve shared already.

            Can you share the content of your Nginx configuration file here as well?

            Also, have you tried setting up a new Droplet and installing Nginx + Gunicorn and deploying your application as a test?

            Regards,
            Bobby

  • @bobbyiliev This is already my new droplet. Through my previous droplet I was unable to send mail on port 465. I never knew DO will irritate me so much. BTW here is my 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;
    #   }
    #}
    
    
    • Hi there,

      The configuration file looks good.

      Can you also share the contents of your Nginx server block?

      This issue is not really DigitalOcean specific, it looks like either server configuration problem or application problem.

      Regards,
      Bobby

      • I suppose you are demanding this block to review. Correct me with file path if I am wrong:

        server {
            listen 80;
            server_name www.domain.com domain.com;
        
            location = /favicon.ico { access_log off; log_not_found off; }
            location /static/ {
                root /root/django/;
            }
        
            location /media/ {
                root /root/django; 
            }
        
            location / {
                include proxy_params;
                proxy_pass http://unix:/run/gunicorn.sock;
            }
        }
        
Submit an Answer