我需要根据查询字符串参数限制对某些文件的访问。我有一个NGINX代理服务器,它位于其他几个nginx Web服务器的前面,用于负载平衡。我已决定在代理服务器级别强制执行此查询字符串参数以合并配置更改。这给我的设置增加了一些复杂性,因为请求不能被困在if中,因为它需要向上游发送。如何在多个位置重新使用NGINX代理设置
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个代理行存储在一个位置或变量,然后内部重定向到一行?我也可以在不同的虚拟主机中使用相同的设置。
OP,那你最终会做什么?我也很好奇这个。 – Mahn 2013-10-26 18:36:53