Nginx位置块中的URI解码

时间:2018-06-20 05:54:31

标签: nginx decoding nginx-reverse-proxy

我在配置中具有反向代理nginx设置。

     upstream cluster {
        least_conn;
        server 192.168.4.137:8001;
        server 192.168.4.137:8002;
    }

    server {
        listen       8000;
        server_name  192.168.4.137;

        charset utf-8;
        log_not_found on;

        access_log  logs/host.access.log  main;
        error_log   logs/host.error.log;


        gzip            on;
        gzip_min_length 1000;
        gzip_proxied    expired no-cache no-store private auth;
        gzip_types      text/plain text/xml 
                        text/css 
                        text/comma-separated-values 
                        text/javascript 
                        application/javascript 
                        application/x-javascript 
                        application/atom+xml 
                        application/json 
                        application/x-json;


        location ~ \.(jpg|jpeg)$ {
            internal;
            root D:\\;
        }


        location / {
            proxy_pass http://192.168.4.137:8001;
            proxy_set_header        Host             $host:$server_port;
            proxy_set_header        X-Real-IP        $remote_addr;
            proxy_set_header        X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_read_timeout 1800;
            proxy_connect_timeout 60;
        }

jpg / jpeg的位置匹配器是内部重定向,并且文件名中可以​​包含“%”。

location ~ \.(jpg|jpeg)$ {
    internal;
    root D:\\;
 }

'%'正在被解码,因此会为错误的名称抛出404。

我已经尝试过:

  1. 在代理通过中使用 $ request_uri
  2. 在位置块中使用重写(。+)%20(。+)“ $ 1%20 $ 2”

更新1: 作为对其余调用的响应,响应是带有重定向头的文件路径:

url = "\\Negative\\alcohol%20negative (10).jpeg"
response['X-Accel-Redirect'] = url

nginx中生成的错误日志是:

2018/06/16 18:28:45 [error] 15328#2636: *10 CreateFile() "D:\\Negative\alcohol negative (10).jpeg" failed (2: The system cannot find the file specified), client: 192.168.4.137, server: 192.168.4.137, request: "GET /rest/image/imagedata?id=3341869 HTTP/1.1", upstream: "http://192.168.4.137:8001/rest/image/imagedata?id=3341869", host: "192.168.4.137:8000", referrer: "http://192.168.4.137:4200/detail/3341869"



到目前为止,以上两种方法均无效。 请提出同样的建议。

0 个答案:

没有答案