Nginx reverse proxy for tomcat
Finally figured it out. The app has a filter that redirects to /webapp/index.html
, which made nginx make the request for /webapp/webapp/index.html
which was giving the 404.
I added a rewrite rule
location / { proxy_pass https://backend/webapp/; 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; rewrite ^/webapp/(.*)$ /$1 last;}
And this seems to be working for now !
full nginx config to pass to tomcat context :
server { listen 80; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea listen [::]:80; server_name tomcat-context.domain.com ; # individual nginx logs for this vhost access_log /var/log/nginx/tomcat-context_domain_access.log main; error_log /var/log/nginx/tomcat-context_domain_error.log; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/www; } location / { proxy_pass http://127.0.0.1:10080/tomcat-context/; 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; rewrite ^/tomcat-context/(.*)$ /$1 last; } location /tomcat-context { rewrite ^/tomcat-context(.*)$ $1 redirect; }}