Question

nginx with nodejs : 502 bad gateway error

Hi, so I am getting the error as mentioned in the title only for one particular GET request. That GET requests processes data and renders a PDF file.

So, I started my research on this, tried a lot of configuration changes in my nginx config file like

  1. adding increased read timeouts, etc
  2. adding increased proxy buffering
  3. disabling gzip
  4. adding an upstream block and such

This is my first time using nginx. I followed a youtube tutorial to deploy my app on a domain and then add a SSL certificate as well (though have to admit I do understand now the basic concepts of how reverse proxy works and configuring, so I wonder what is it that is causing this issue).

Before this I had deployed the app on the free tier of heroku and I faced no issue with this GET request on this particular URL.

Following is my current configuration file

upstream localhost:3000 { zone upstreams 64K; server 127.0.0.1:3000 max_fails=0 fail_timeout=2s; keepalive 8; }

server { root /var/www/html; index index.html index.htm index.nginx-debian.html;

server_name digitalawb.in www.digitalawb.in;

location / {
	proxy_set_header Host $host;
	proxy_set_header X-Real-Ip $remote_addr;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_set_header X-Forwarded-Proto $scheme;

	proxy_pass http://localhost:3000/;
	proxy_read_timeout 90;
	proxy_buffering on;
	proxy_buffer_size 4k;
	proxy_buffers 24 4k;
	proxy_busy_buffers_size 8k;
	proxy_max_temp_file_size 2048m;
	proxy_temp_file_write_size 32k;
	proxy_redirect http://localhost:3000/ https://digitalawb.in/;
}

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/digitalawb.in/fullchain.pem; 
ssl_certificate_key /etc/letsencrypt/live/digitalawb.in/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

}

server { if ($host = www.digitalawb.in){ return 301 https://$host$request_uri; }

if ($host = digitalawb.in){
	return 301 https://$host$request_uri;
}

listen 80 default_server;
listen [::]:80 default_server;

server_name digitalawb.in www.digitalawb.in;
return 404;

}


Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer