本文介绍了避免Nginx解码proxy_pass上的查询参数(等效于AllowEncodedSlashes NoDecode)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在几个雄猫前面使用nginx作为负载平衡器.在我的传入请求中,我已经对查询参数进行了编码.但是,当请求到达tomcat时,对参数进行解码:

I use nginx as a load balencer in front of several tomcats. In my incoming requests, I have encoded query parameters. But when the request arrives to tomcat, parameters are decoded :

向nginx的传入请求:

incoming request to nginx:

curl -i "http://server/1.1/json/T;cID=1234;pID=1200;rF=http%3A%2F%2Fwww.google.com%2F"

向tomcat的传入请求:

incoming request to tomcat:

curl -i "http://server/1.1/json/T;cID=1234;pID=1200;rF=http:/www.google.com/"

我不希望转换我的请求参数,因为在这种情况下,我的tomcat会抛出405错误.

I don't want my request parameters to be transformed, because in that case my tomcat throws a 405 error.

我的nginx配置如下:

My nginx configuration is the following :

upstream tracking  {
    server front-01.server.com:8080;
    server front-02.server.com:8080;
    server front-03.server.com:8080;
    server front-04.server.com:8080;
}

server {
    listen 80;
    server_name tracking.server.com;
    access_log /var/log/nginx/tracking-access.log;
    error_log  /var/log/nginx/tracking-error.log;

    location / {
        proxy_pass  http://tracking/webapp;
    }
}

在当前的apache负载均衡器配置中,我有 AllowEncodedSlashes 保留我编码参数的指令:

In my current apache load balancer configuration, I have the AllowEncodedSlashes directive that preserves my encoded parameters:

AllowEncodedSlashes NoDecode

我需要从apache转到nginx.

I need to move from apache to nginx.

我的问题与这个问题完全相反:避免nginx逃逸在proxy_pass上查询参数

My question is quite the opposite from this question : Avoid nginx escaping query parameters on proxy_pass

推荐答案

我终于找到了解决方案:我需要通过 $request_uri参数:

I finally found the solution: I need to pass $request_uri parameter :

location / {
    proxy_pass  http://tracking/webapp$request_uri;
}

这样,原始请求中编码的字符将不会被解码,即被原样传递到代理服务器.

That way, characters that were encoded in the original request will not be decoded, i.e. will be passed as-is to the proxied server.

这篇关于避免Nginx解码proxy_pass上的查询参数(等效于AllowEncodedSlashes NoDecode)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 06:09