1

I have a website that is hosted on google cloud platform using NGINX server. Some hour before it was working well but suddenly an error of 502 bad gateway occured.

NGINX server is hosted on another instance and main project is another instance and following is the configuration of my server :

server {
      listen 443 ssl;  
      server_name www.domain.com;
       ssl_certificate /path-to/fullchain.pem;
      ssl_certificate_key /path-to/privkey.pem;
     
      # REST API Redirect
      location /api {
              proxy_set_header X-Real-IP  $remote_addr;
              proxy_set_header X-Forwarded-For $remote_addr;
              proxy_set_header Host $host;
              proxy_pass http:/internal-ip:3000;
      }
     
       # Server-side CMS Redirect
      location / {
              proxy_set_header X-Real-IP  $remote_addr;   
              proxy_set_header X-Forwarded-For $remote_addr;
              proxy_set_header Host $host;
              proxy_pass http://internal-ip:4400;
       }
  }

when restarted the instance of nginx server then website loaded successfully but after three or four refresh it started giving Bad Gateway and after that anytime I open it is giving bad gateway error. Sometimes, automatically it reloads well but again down.

Tried to know the error log of nginx server and following is the output of error log:

Sometimes this popular issue is logged: enter image description here

and sometimes this:enter image description here

Regarding first issue I tried some recommendations such that increase the proxy send and read time to some higher value as suggested here in server configuration and also shown in the image as follows :

enter image description here

Also backend code is working fine because I can access the deployed backend services in local during development but hosted website can not access any backend service.

But nothing worked and sadly my website is down. Please suggest any solution.

Jose Luis Delgadillo
  • 2,348
  • 1
  • 6
  • 16
Nandan Pandey
  • 148
  • 1
  • 11
  • What is the traffic to your site? Are you running nginx on Compute Engine VM? Where is your backend code vs nginx - you are referring to it as internal-ip - is it another Compute Engine? – Maciej Perliński Feb 09 '21 at 18:48
  • Yes I am running nginx on Compute Engine VM on other instance and Backend is on another compute engine vm instance whose internal ip is mentioned in nginx server configuration file. – Nandan Pandey Feb 10 '21 at 07:11

1 Answers1

1

By default nginx is having 1024 worker connections you can change it with

events {
  worker_connections  4096; 
}

Also you can try to increase amount of workers as workers*worker_connections is giving you amount of connections you can handle. All that is in the context your site is receiving a traffic and you simply running out of connections.