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

前端之家收集整理的这篇文章主要介绍了linux – 如何防止nginx从反向代理特定的子目录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在Apache上,您可以使用ProxyPass除一个或多个子目录(带“!”)之外的所有内容. @H_404_2@ProxyPass /subdir ! ProxyPass / http://localhost:9999/

什么是Nginx等价物?

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

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

解决方法

您可以将proxy_pass绑定到您喜欢的路径,就像这样 @H_404_2@location = / { proxy_pass http://localhost:9999/; }

这确保不会传递其他路径但/

要么

您可以将此语法用于仅匹配的子目录

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

^〜匹配子目录然后停止搜索,因此/不会执行.它被描述为here.

猜你在找的Linux相关文章