Nginx reverse proxy – requests still return port 80

nginxreverse-proxyweblogic

I'm trying to use nginx as a proxy server for two weblogic servers. The ports on the weblogic are 23823 and 23824 and i want them both to be accessible from port 8888 and distinguished by context path. I've tried this configuration:

    listen 8888;
    server_name vead03;

    location /app1 {
            proxy_pass  http://127.0.0.1:23823;
            proxy_redirect  off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    location /app2 {
            proxy_pass  http://127.0.0.1:23824;
            proxy_redirect  off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

I can access both servers through ports 8888 without problems, but when a request lands on the server and I call request.getServerPort(), I receive 80 for some reason.
I have no idea where can this message come from. Port 80 is nowhere in the nginx configuration and I definitely haven't used it anywhere on the Weblogic. This is quite a problem, because the application expects to receive 8888, not 80.

Best Answer

The solution was quite easy: instead of

proxy_set_header Host $host;

I had to use

proxy_set_header Host $host:$server_port;