Hello friends want a help from you! Because then I’m having a problem Error 502 Bad gateway always nginx. Everything was normal, but until now I still don’t see a tutorial in 2016, which corresponds to it, but I think it’s bug. Can someone help me

4 comments
  • Hi! Are there any errors in nginx’s error log? What’s the output of the following command?

    sudo tail -30 /var/log/nginx/error.log
    
  • Hello friend I have that! This command is not going “sudo tail -30 /var/log/nginx/error.log”

    2016/08/31 15:46:55 [emerg] 11039#11039: “fastcgireadtimeout” directive is duplicate in /etc/nginx/nginx.conf:45
    2016/08/31 17:01:32 [info] 12089#12089: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:113
    2016/08/31 17:01:32 [info] 12102#12102: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:113
    2016/08/31 17:03:07 [info] 27788#27788: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:113
    2016/08/31 17:03:07 [info] 27800#27800: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:113
    2016/08/31 17:12:06 [info] 28408#28408: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:113
    2016/08/31 17:12:06 [notice] 28416#28416: signal process started
    2016/08/31 17:15:14 [info] 28542#28542: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:109
    2016/08/31 17:26:35 [info] 29309#29309: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:109
    2016/08/31 17:26:35 [info] 29311#29311: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:109
    2016/08/31 17:26:35 [notice] 29331#29331: signal process started
    2016/08/31 17:27:43 [info] 29402#29402: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:109
    2016/08/31 17:27:44 [info] 29414#29414: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:109
    2016/08/31 20:36:18 [emerg] 31599#31599: “fastcgipass” directive is not allowed here in /etc/nginx/sites-enabled/default:52
    2016/08/31 21:00:24 [info] 31896#31896: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:109
    2016/08/31 21:03:34 [emerg] 32052#32052: unknown directive “…” in /etc/nginx/nginx.conf:13
    2016/08/31 21:14:28 [emerg] 32480#32480: “fastcgi
    buffers” directive is duplicate in /etc/nginx/conf.d/fastcgi.conf:6
    2016/08/31 21:15:47 [info] 464#464: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:110
    2016/08/31 21:15:47 [info] 495#495: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:110
    2016/08/31 21:34:35 [emerg] 700#700: “fastcgipass” directive is not allowed here in /etc/nginx/sites-enabled/default:52
    2016/08/31 21:43:07 [info] 902#902: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:110
    2016/08/31 21:52:30 [info] 1107#1107: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:110
    2016/08/31 21:58:42 [emerg] 1286#1286: “fastcgi
    readtimeout” directive is duplicate in /etc/nginx/conf.d/fastcgi.conf:10
    2016/08/31 21:59:54 [info] 1441#1441: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:110
    2016/08/31 23:11:12 [info] 2311#2311: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:109
    2016/08/31 23:20:58 [emerg] 2499#2499: “location” directive is not allowed here in /etc/nginx/nginx.conf:11
    2016/08/31 23:27:14 [info] 2636#2636: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:110
    2016/08/31 23:28:47 [info] 2770#2770: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:110
    2016/08/31 23:35:49 [emerg] 2830#2830: “location” directive is not allowed here in /etc/nginx/conf.d/xyz.conf:1
    2016/08/31 23:37:14 [info] 2951#2951: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:110
    2016/08/31 23:42:09 [emerg] 3201#3201: “location” directive is not allowed here in /etc/nginx/nginx.conf:31
    2016/09/01 00:00:46 [info] 3707#3707: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:111
    2016/09/01 00:03:42 [info] 3892#3892: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:15
    2016/09/01 00:03:42 [emerg] 3892#3892: “location” directive is not allowed here in /etc/nginx/nginx.conf:18
    2016/09/01 00:09:21 [emerg] 4120#4120: the shared memory zone “one” is already declared for a different use in /etc/nginx/nginx.conf:30
    2016/09/01 00:18:03 [emerg] 4388#4388: “access
    log” directive is not allowed here in /etc/nginx/nginx.conf:4
    2016/09/01 00:18:27 [emerg] 4514#4514: “accesslog” directive is not allowed here in /etc/nginx/nginx.conf:4
    2016/09/01 00:18:47 [info] 4639#4639: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:112
    2016/09/01 00:19:29 [emerg] 4802#4802: “access
    log” directive is not allowed here in /etc/nginx/nginx.conf:10
    2016/09/01 00:21:17 [info] 5054#5054: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:112
    2016/09/01 00:21:17 [emerg] 5054#5054: “accesslog” directive is not allowed here in /etc/nginx/nginx.conf:135
    2016/09/01 00:21:46 [info] 5209#5209: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:112
    2016/09/01 00:27:06 [info] 5423#5423: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:112
    2016/09/01 00:29:13 [info] 5597#5597: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:113
    2016/09/01 00:31:02 [emerg] 5765#5765: invalid number of arguments in “client
    bodybuffersize” directive in /etc/nginx/nginx.conf:25
    2016/09/01 00:35:33 [info] 5943#5943: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:114
    2016/09/01 00:43:42 [info] 6234#6234: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:114
    2016/09/01 01:35:29 [info] 7356#7356: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:114
    2016/09/01 01:39:10 [info] 7615#7615: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:111
    2016/09/01 01:44:52 [info] 7835#7835: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:111
    2016/09/01 02:00:09 [info] 2378#2378: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:111
    2016/09/01 02:12:18 [info] 2376#2376: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:111
    2016/09/01 02:37:35 [alert] 2472#2472: *59 open socket #18 left in connection 5
    2016/09/01 02:37:35 [alert] 2472#2472: aborting
    2016/09/01 02:38:53 [info] 2380#2380: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:111
    2016/09/01 02:44:46 [info] 4418#4418: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:111
    2016/09/01 02:44:49 [info] 4461#4461: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:111
    2016/09/01 02:44:49 [info] 4473#4473: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:111
    2016/09/01 02:49:46 [info] 4596#4596: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:111
    2016/09/01 02:49:46 [notice] 4604#4604: signal process started

  • Did you tried to test your nignx configuration, there could be some errors in it?
    It is done by executing

    • sudo nginx -t

    This command is used to run syntax check and tests on your nginx.conf.

    Correct output should be something like:

    Output of nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    
  • Hello friend a nginx is with normal setting, but I think that’s a bug, because so far I haven’t found anything that solves

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.

×
7 answers

Hello,

In addition to what has already been mentioned, I would recommend following these steps in case that you are having any problems with your nginx server and you are unsure on what the problem is:

  • Check if nginx is running:
systemctl status nginx

If nginx is running you should see something like this:

● nginx.service - The nginx HTTP Server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-11-19 09:37:46 UTC; 2 days ago
     Docs: https://httpd.nginx.org/docs/2.4/

If nginx is not running then the output would look like this:

● nginx.service - The nginx HTTP Server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Fri 2019-11-22 08:41:01 UTC; 39s ago
     Docs: https://httpd.nginx.org/docs/2.4/
  • If nginx is not running you could start it with:
systemctl start nginx

Then check the status agian and make sure that nginx remains running.

  • If nginx did not start after a reboot, you could enable it so that it starts after the next reboot:
systemctl enable nginx
  • Check your nginx config syntax:
nginx -t

If you get an error, you would need to fix that problem and then you could restart nginx:

systemctl restart nginx
  • If you get Syntax OK when running nginx -t then your confiruation is correct, so I would recommend checking your error logs:
tail -f /var/log/nginx/error.log
  • Check the permissions of the files and folders in your document root:

Find the user that your nginx service is running as:

ps auxf | grep nginx

If you are using Ubuntu, the user should be www-data, so you would need to make sure that your files and folders are owned by that user, so nginx could read and write to those files:

chown -R www-data:www-data /var/www/yourdomain.com
  • Check if nginx is binding to the default ports:
netstat -plant | grep '80\|443'
  • Check if ufw allows TCP connections on port 80 and 443:
ufw status

If this is the case, you can follow the steps from this article here on how to configure your ufw:

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-18-04

That is pretty much it, with all of the above information you should be able to narrow down the problem.

For more information I would suggest checking out this article here:

https://www.digitalocean.com/community/tutorials/how-to-troubleshoot-common-site-issues-on-a-linux-server

Hope that this helps!
Regards,
Bobby
Source: How to Troubleshoot Common Nginx Issues on Linux Server?

by Justin Ellingwood
Everybody runs into issues with their website at one point or another. This guide will help you troubleshoot some common issues and get your site running again.
 sudo chown user:group -R /run/php

.... that fixed my issue for me .. Ubuntu 18.04

Lots of possibilities but if you opted to use FPM most probably you are pointing to the wrong version.

fastcgi_pass unix:/var/run/php/php<YourPHPVersionHere>-fpm.sock;

Try run this command
systemctl start php-fpm
systemctl enable php-fpm

The log file shared does not appear to include the 502 error result.

This could just be because the error occurred outside the timeframe of the log snippet.

It could also happen if a service like CloudFlare is in front of your droplet and is the source of the 502.

You can view the output of your logs in real-time while testing to help identify exactly the cause and effect around an error.

tail -f /var/log/nginx/error.log
will let you watch for errors

tail -f /var/log/nginx/access.log
will let you watch normal non-error requests in real time.

Ctrl+c will allow you to exit from either of these tail commands.

@joilson,

You might be missing the correct path to PHP FPM Sock.

  • For anyone reading this answer it probably is the case if you have a “No such file or directory” due to the wrong path in the nginx serverblock file (like vhost file for apache) for fastcgi_pass unix: path.

    Just replying in case it helps someone in that particular case because I spent awhile trying to figure it out

Hello to everyone,
I have this really boring issue …

If I try to remotely reach my Apache Guacamole server (Zero Client) … I get this error even though, the NGINX server is working … Here are some command outputs:

sudo nano /etc/nginx/sites-available/zc

server {
        server_name zc.samacappalti.it www.zc.samacappalti.it;

        root /var/www/htm;
        index index.html index.htm;

        location / {
        proxy_pass http://CENSORED:8080/guacamole/;
        proxy_buffering off;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $http_connection;
        access_log off;
        }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot

    ssl_certificate /etc/letsencrypt/live/zc.samacappalti.it/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/zc.samacappalti.it/privkey.pem; # managed by Certbot

}

server {
    if ($host = www.zc.samacappalti.it) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = zc.samacappalti.it) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

        listen 80;
        listen [::]:80;

        server_name zc.samacappalti.it www.zc.samacappalti.it;
    return 404; # managed by Certbot

}
sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo tail -f /var/log/nginx/error.log
2020/10/19 21:45:42 [error] 1234#1234: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 93.41.132.61, server: zc.samacappalti.it, request: "GET / HTTP/1.1", upstream: "http://192.168.100.233:8080/guacamole/", host: "zc.samacappalti.it"
2020/10/19 21:45:42 [error] 1234#1234: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 93.41.132.61, server: zc.samacappalti.it, request: "GET /favicon.ico HTTP/1.1", upstream: "http://192.168.100.233:8080/guacamole/favicon.ico", host: "zc.samacappalti.it", referrer: "https://zc.samacappalti.it/"
2020/10/19 21:45:42 [error] 1234#1234: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 93.41.132.61, server: zc.samacappalti.it, request: "GET / HTTP/1.1", upstream: "http://192.168.100.233:8080/guacamole/", host: "zc.samacappalti.it"
2020/10/19 21:45:42 [error] 1234#1234: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 93.41.132.61, server: zc.samacappalti.it, request: "GET /favicon.ico HTTP/1.1", upstream: "http://192.168.100.233:8080/guacamole/favicon.ico", host: "zc.samacappalti.it", referrer: "https://zc.samacappalti.it/"
2020/10/19 21:45:42 [error] 1234#1234: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 93.41.132.61, server: zc.samacappalti.it, request: "GET / HTTP/1.1", upstream: "http://192.168.100.233:8080/guacamole/", host: "zc.samacappalti.it"
2020/10/19 21:45:42 [error] 1234#1234: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 93.41.132.61, server: zc.samacappalti.it, request: "GET /favicon.ico HTTP/1.1", upstream: "http://192.168.100.233:8080/guacamole/favicon.ico", host: "zc.samacappalti.it", referrer: "https://zc.samacappalti.it/"
2020/10/19 21:51:48 [error] 1235#1235: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 93.41.132.61, server: zc.samacappalti.it, request: "GET / HTTP/1.1", upstream: "http://192.168.100.233:8080/guacamole/", host: "zc.samacappalti.it"
2020/10/19 21:51:49 [error] 1235#1235: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 93.41.132.61, server: zc.samacappalti.it, request: "GET /favicon.ico HTTP/1.1", upstream: "http://192.168.100.233:8080/guacamole/favicon.ico", host: "zc.samacappalti.it", referrer: "https://zc.samacappalti.it/"
2020/10/19 22:12:34 [error] 1406#1406: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 93.41.132.61, server: zc.samacappalti.it, request: "GET / HTTP/1.1", upstream: "http://192.168.100.233:8080/guacamole/", host: "zc.samacappalti.it"
2020/10/19 22:17:56 [error] 1406#1406: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 205.169.39.38, server: zc.samacappalti.it, request: "GET / HTTP/1.1", upstream: "http://192.168.100.233:8080/guacamole/", host: "zc.samacappalti.it"
sudo ufw status
Stato: attivo

A                          Azione      Da
-                          ------      --
Nginx Full                 ALLOW       Anywhere
80                         ALLOW       Anywhere
443                        ALLOW       Anywhere
Nginx Full (v6)            ALLOW       Anywhere (v6)
80 (v6)                    ALLOW       Anywhere (v6)
443 (v6)                   ALLOW       Anywhere (v6)

I seriously need help… PLEASE!

Greetings.
M.

Submit an Answer