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?
CodePudding user response:
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.