Use NGINX as reverse-proxy to another Nginx

I have a kubernetes pods with Nginx serving a static node.js website, with a load balancer IP 192.168.0.223. When I browse http://192.168.0.223:80/, the static website is displayed correctly. I have a reverse-proxy NGINX, due to limitations of my local network, at 192.168.0.199, on Raspberry pi Raspbian. Here's the Nginx configuration:

server {
  listen 80;
  listen [::]:80;
  server_name localhost;
  access_log /var/www/logs/node-access.log;
  error_log /var/www/logs/node-error.log;
  location / {
        proxy_pass http://192.168.0.223:80;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Scheme $scheme;
        proxy_redirect http://192.168.0.223/ /;
        client_max_body_size 0;
    }
}

However when I request http://192.168.0.199:80/, it displays the vanilla "Welcome to Nginx!" page. I made sure this is the only conf in sites-enabled, and there is nothing in the logs. Could you help me please ?


Solution 1:

Set servername to the IP you gave, 192.168.0.199. Currently it's only sending inbound localhost to the destination you want.

You should be able to verify this by running curl http://192.168.0.199 from the nginx box and getting the nginx page, where running curl http://localhost should give you the desired result.