Score:0

Nginx forward to proxy_pass location without rewriting the port

cn flag

I have the following topology

PfSense -> Nginx -> Webserver where my app is listening under port 8080

My NGINX configuration file looks like:

log_format  webapp_log_format  '$remote_addr - $remote_user [$time_local] "$request" '
                                '$status $body_bytes_sent "$http_referer" '
                                '"$http_user_agent" "$http_x_forwarded_for" '
                                '"$http_connection" "$http_upgrade"' ;

server {
    listen        80;
    server_name    www.example.com example.com;

    ## Redirect http to https

    return 301 https://example.com/;
}

server {
    listen           443 ssl;
    server_name      www.example.com example.com;

    ssl_certificate /etc/certs/live/fullchain.pem;
    ssl_certificate_key /etc/certs/live/privkey.key;

    location / {
    return 301 /webapp;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    deny all;
    }

    location /webapp/ {
        proxy_pass http://example.com:8080/webapplication/;
        access_log /var/log/nginx/rap.log app_log_format;
    }

}

These are my scenarios:

browsing externally to https://example.com/webapp -> shows the webapp without an issue

browsing externally to https://example.com -> rewrites the URL in my browser to https://example.com:8080/webapp (which doesn't work because of the 8080)

what is wrong in my config file?

pt flag
If `example.com` points to your Pfsense device, then you would need to arrange to forward connections on port 8080 to port 80 on your nginx server (or update your nginx configuration to listen on port 8080 and then forward the connections from Pfsense to port 8080).
cn flag
i don't want to visitors to see :8080 in their browser when visiting this site
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.