如何防止nginx从反向代理特定的子目录

在Apache上,您可以使用ProxyPass除了一个或多个子目录(使用“!”)。

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

什么是Nginx的等价物?

我的第一个猜测显然不起作用:

  location /subdir { root /var/www/site/subdir; } location / { proxy_pass http://localhost:9999/ ; } 

您可以将proxy_pass绑定到您喜欢的path,就像这样

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

这确保了没有其他path会通过,但/

要么

你可以使用这个语法只是要匹配的子目录

 location ^~ /subdir { alias /var/www/site/subdir; } location / { proxy_pass http://localhost:9999/ ; } 

^~匹配子目录,然后停止search,所以/不会被执行。 这里描述。