避免 nginx 在 proxy_pass 上解码查询参数(相当于 AllowEncodedSlashes NoDecode) [英] Avoid nginx decoding query parameters on proxy_pass (equivalent to AllowEncodedSlashes NoDecode)

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

问题描述

我在几个tomcat面前使用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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆