安全性 – 如何在多个位置重用NGINX代理设置

前端之家收集整理的这篇文章主要介绍了安全性 – 如何在多个位置重用NGINX代理设置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我需要根据查询字符串参数限制对某些文件的访问.我有一个Nginx代理服务器,位于其他几个Nginx Web服务器之前,用于负载平衡.我已决定在代理服务器级别强制执行此查询字符串参数,以便合并配置更改.这为我的设置增加了一点复杂性,因为请求不会被困在if中,因为它需要向上游发送.

@H_301_5@server { listen 443; # SSL Settings server_name staging.xxxx.com; location / { proxy_pass http://webdav-cluster; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; } # Unless the correct application token is passed in as a query parameter # then deny access. location ~ \/protected\/.*txt${ if ($arg_secret != abc) { return 403; } proxy_pass http://webdav-cluster; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; } }

有没有办法将这4个代理行存储在一个位置或变量中,然后在内部重定向到一行?我也可以在不同的虚拟主机中使用相同的设置.

最佳答案
在这种情况下,您应该使用include指令:http://nginx.org/r/include
原文链接:https://www.f2er.com/nginx/434810.html

猜你在找的Nginx相关文章