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?