nginx条件代理基于请求正文内容传递

前端之家收集整理的这篇文章主要介绍了nginx条件代理基于请求正文内容传递前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我试图配置Nginx代理将请求传递给另一个服务器,只有当$request_body变量匹配特定的正则表达式.但它不适合我.

 server{
        listen 80 default;
        server_name www.applozic.com;

        location / {
                 proxy_set_header X-Real-IP $remote_addr;
                 proxy_set_header X-Forwarded-For $remote_addr;
                 proxy_set_header Host $http_host;

                if ($request_body ~* (.*)appId(.*)) {
                   proxy_pass http://apps.applozic.com;
                }
        }

}

请求正文是::

              {
               "applicationId": "appId","authenticationTypeId": 1,"enableEncryption": false,"notificationMode": 0,"deviceType": 4,}
最佳答案
最好的我可以告诉你的问题是,在你的if语句执行时,变量$request_body可能没有被读入内存.

建议的替代方案是使用lua支持compile nginx with the echo modules and run echo_request_body.

原文链接:https://www.f2er.com/nginx/434973.html

猜你在找的Nginx相关文章