PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 1, 2022

[FIXED] how to resolve nginx 502 bad-gateway error

 September 01, 2022     amazon-ec2, devops, nginx, nginx-config, nginx-reverse-proxy     No comments   

Issue

I've containerized the next.js web application and hosted in aws ec-2. using nginx as proxy server

this is the only working page

/

not working for any other pages (paths),it throws 502 bad-gate-way

EX:

/etc

/slug/page

this is the nginx cofiguration

server {
listen 80 default_server;


location  / {
  proxy_pass http://localhost:300;
}

}

how can I Forward all paths to a specific port?


Solution

server {
        listen 80 default_server;
        listen [::]:80 default_server;

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

        server_name _;

        location / {
                # reverse proxy for next server
                proxy_pass http://localhost:300;
                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;

            # we need to remove this 404 handling
                # because next's _next folder and own handling
                # try_files $uri $uri/ =404;
        } 

        location ~ /.well-known {
                allow all
        }
} 

I've add this nginx configuration, now it's working fine.



Answered By - Shaheel_Azhar
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing