Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On Apache you can ProxyPass everything except one or more subdirectories (with "!").

    ProxyPass /subdir !
    ProxyPass / http://localhost:9999/

What is the Nginx equivalent ?

My first guess is obviously not working :

 location /subdir {
      root /var/www/site/subdir;

 location / {
      proxy_pass http://localhost:9999/ ;
share|improve this question

You can bind the proxy_pass to EXACTLY the path you like, like this

location = / {
    proxy_pass http://localhost:9999/;

This makes sure that no other path will be passed but /


you can use this syntax for just the subdirectories to be matched

location ^~ /subdir {
     alias /var/www/site/subdir;

location / {
    proxy_pass http://localhost:9999/ ;

The ^~ matches the subdir and then stops searching so the / will not be executed. It is described here.

share|improve this answer
root /var/www/site/subdir should be root /var/www/site in my case, otherwise nginx will try to access /var/www/site/subdir/subdir . – Tinus Nov 26 '14 at 15:13
You are right. Either that, or you can use alias instead of root – Christopher Perrin Nov 26 '14 at 15:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.