I'm attempting to set up a reverse proxy with NGINX on my VPS to direct traffic to an application running inside a Kubernetes pod through a NodePort service at port 32080. Although accessing my app directly via app.example.com:32080 works perfectly, I'm encountering a 404 error when trying to reach it through app.example.com. Here's the NGINX configuration I'm currently using:
server {
listen 80;
server_name app.example.com;
location / {
proxy_pass http://localhost:32080;
proxy_http_version 1.1;
proxy_set_header Host "localhost";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Any suggestions on what might be going wrong?
3 Answers
Have you checked NGINX's error logs? They might give you insight into what's going wrong. Also, make sure you're really connecting through the right host header since your app could be configured to expect a specific value.
If you're trying to serve the page at port 80, you might want to consider using a more generic configuration for the `Host` header. Like `proxy_set_header Host $host;`. This way, it dynamically sets the host based on the incoming request, which might solve your issue.
It looks like you're not using the proper `Host` header in your NGINX configuration. Try changing `proxy_set_header Host "localhost";` to `proxy_set_header Host "app.example.com";` so that NGINX knows to serve requests for that host instead of localhost. That's likely why you're facing the 404 issue. Don't forget to restart NGINX after making that change!

Related Questions
Keep Your Screen Awake Tool
Favicon Generator
JWT Token Decoder and Viewer
Ethernet Signal Loss Calculator
Glassmorphism CSS Generator with Live Preview
Remove Duplicate Items From List