Problems with NGINX reverse proxy to NodePort service

0
15
Asked By TechWiz123 On

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

Answered By LinuxGuru007 On

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.

Answered By ProxyMaster99 On

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.

Answered By CodeNinja42 On

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

Remove Duplicate Items From List

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.