Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx reverse proxy for tomcat

I am having issues getting my nginx + tomcat 7 reverse proxy setup working.

Basically I want https://192.168.10.101 to serve content from the upstream cluster/webapp/; However I am getting a 404 page from my applicaton.

Any hints on whats going wrong would be greatly appreciated.

My configuration is given below.

server {

            server_name 192.168.10.101;
            access_log /var/log/nginx/mysite-access.log;
            listen   443;
            ssl on;
            ssl_certificate    /etc/nginx/ssl/mysite.crt;
            ssl_certificate_key    /etc/nginx/ssl/private/mysite_pvt.key;

                location  / {
                        proxy_redirect off;
                        proxy_pass      https://tccluster/webapp/;
                        rewrite_log     on;

                        proxy_set_header   Host             $host;
                        proxy_set_header   X-Real-IP        $remote_addr;
                        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                        proxy_max_temp_file_size 0;

                }
}

upstream  tccluster  {
                server   192.168.56.103:8443;
                server   192.168.56.104:8443;
}
like image 897
JVXR Avatar asked Jan 12 '23 08:01

JVXR


1 Answers

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 !

like image 135
JVXR Avatar answered Jan 17 '23 12:01

JVXR