Tomcat 8 URL rewrite is not working when requests are proxy passed from nginx server. But the same url-rewrite is working when requests are directly served from tomcat server.
I am having nginx server listening to 80 port and tomcat server listening to 9080 port.
nginx proxy-pass configuration
http
{
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server
{
listen 80;
location /app/
{
proxy_pass http://localhost:9080/;
proxy_set_header Host $host:$server_port;
}
}
}
tomcat rewrite.config file
RewriteRule ^app/xyz /app/abc [L]
When I try to access the url http://server-name/app/xyz, the URL rewriting is not working. But when accessed directly via tomcat listening port(server-name:9080/app/xyz) it is working.
EDIT
Previously I had the URL rewriting configured in nginx.
nginx url rewrite configuration
location /app/
{
proxy_pass http://localhost:9080/;
proxy_set_header Host $host:$server_port;
include /dev_resource/nginx/rewrite.conf;
}
nginx rewrite.conf
rewrite ^/app/xyz /app/abc break;
When I try to access the url http://server-name/app/xyz
, the url rewriting is working. The request is not being forwarded to http://server-name/xyz
.
But when url rewriting is configured with tomcat 8, the url http://server-name/app/xyz
is being forwarded to http://server-name/xyz
.