Apache + NginX reverse proxy: serving static and proxy files within nested URLs <p>I have Apache running on my server on port 8080 with NginX running as a reserve proxy on port 80. I am attempting to get NginX to serve static HTML files for specific URLs. I am struggling to write the NginX configuration that does this. I have conflicting directives as my URLs are nested within each other.</p> <p>Here's what I want to have:</p> <ul> <li><p>One URL is at <code>/example/</code> and I want NginX to serve a static HTML file located on my server at <code>/path/to/www/example-content.html</code> instead of letting Apache serve the page to NginX.</p></li> <li><p>Another URL is at <code>/example/images/</code> and I want Apache to serve that page to NginX, just as it does for the rest of the site.</p></li> </ul> <p>I have set up my nginx.conf file like this:</p> <pre><code>server { listen 80; server_name localhost; # etc... location / { proxy_pass http://127.0.0.1:8080/; } # etc... </code></pre> <p>My attempt to serve the static file at <code>/example/</code> from NginX went like this:</p> <pre><code> location /example/ { alias /path/to/www/; index example-content.html; } </code></pre> <p>This works, but it means everything after the <code>/example/</code> URL (such as <code>/example/images/</code>) is aliased to that local path also.</p> <p>I would like to use regex instead but I've not found a way to serve up the file specifically, only the folder. What I want to be able to say is something like this:</p> <pre><code> location ~ ^/example/$ { alias /path/to/www/example-content.html; } </code></pre> <p>This specifically matches the <code>/example/</code> folder, but using a filename like that is invalid syntax. Using the explicit <code>location = /example/</code> in any case doesn't work either.</p> <p>If I write this:</p> <pre><code> location ~ ^/example/$ { alias /path/to/www/; index example-content.html; } location ~ /example/(.+) { alias /path/to/www/$1; } </code></pre> <p>The second directive attempts to undo the damage of the first directive, but it ends up overriding the first directive and it fails to serve up the static file.</p> <p>So I'm at a bit of a loss. Any advice at all extremely welcome! Many thanks.</p>