1

I'm getting 502 bad gateway on an nginx with the following errors:

[error] 1679#1679: *13 connect() failed (111: Connection refused) while connecting to upstream, client: 46.176.252.229, server: dodeka-designers.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "dodeka-designers.com"

This is my /etc/nginx/sites-available/default content. Does anyone have any idea what the issue could be?

server {
    listen 80;
        server_name dodeka-designers.com www.dodeka-designers.com;
    location ~ /.well-known {
                allow all;
        }

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        client_max_body_size 50M;
    }

    location /back {
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 200;
        }
        if ($request_method = 'POST') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
        }
        if ($request_method = 'GET') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
        }
        rewrite ^/back(.*)$ $1 break;
        root /var/www/html;

        client_max_body_size 50M;
            proxy_http_version 1.1;
        proxy_connect_timeout       3600;
        proxy_send_timeout          3600;
        proxy_read_timeout          3600;
        send_timeout                3600;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;

        index index.php index.html index.htm;
    }

    location ~ \.php$ {

        rewrite ^/back(.*)$ $1 break;
        root /var/www/html;

        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        client_max_body_size 50M;
            proxy_http_version 1.1;
        proxy_connect_timeout       3600;
        proxy_send_timeout          3600;
        proxy_read_timeout          3600;
        send_timeout                3600;
        fastcgi_read_timeout        3600;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }



    listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/dodeka-designers.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/dodeka-designers.com/privkey.pem; # managed by Certbot
  include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
 }
  • 1
    Do you really want to post your actual IP and server configuration like this? – terdon Jan 29 at 18:40
  • That error is portmap and is not even related to nginx. You also should not have the portmap port open to the word at large. – Rui F Ribeiro Jan 29 at 18:55
  • 1
    Are you sure you want to be looking at sites-available rather than sites-enabled? – roaima Jan 29 at 19:19
0

You are running a reverse proxy that is trying to connect to another service on 'http://localhost:3000', so this error is not on nginx since this other service on localhost:3000 is not answering nginx requests or it is not answering it properly to be handle by the reverse proxy (for example, it is producing a redirection).

If you are able to connect to port 3000 via telnet for example (command to execute this test: telnet localhost 3000), check if it is speaking in plain text or if it is encripted (https...) - because you configured nginx to connect to this other service as http only, if you are not able to connect to port 3000, then you must determine what service you have in this port that should be fixed, nginx has nothing to do with that.

You did not expect nginx to be a **reverse proxy?** Them you need to edit its configuration to remove the "proxy" lines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.