Nginx Redirect via Proxy, Rewrite and Preserve URL

First, you shouldn’t use root directive inside the location block, it is a bad practice. In this case it doesn’t matter though.

Try adding a second location block:

location ~ /some/path/(?<section>.+)/index.html {
    proxy_pass http://192.168.1.24/$section/index.html;
    proxy_set_header Host $host;
}

This captures the part after /some/path/ and before index.html to a $section variable, which is then used to set the proxy_pass destination. You can make the regex more specific if you require.

Leave a Comment