小编VBa*_*art的帖子

如何在多个位置重用NGINX代理设置

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

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;
        }
}
Run Code Online (Sandbox Code Playgroud)

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

security proxy webserver dry nginx

8
推荐指数
1
解决办法
1535
查看次数

标签 统计

dry ×1

nginx ×1

proxy ×1

security ×1

webserver ×1