Nginx逃离&符号

时间:2016-01-15 18:58:29

标签: nginx query-string ampersand proxypass

所以我有这个编码的网址http://localhost:3050/pdfx/http%3A%2F%2Flocalhost%2Fpdf.html%3FlipperId%3D61%26lang%3Dfr-ca

转换为http://localhost:3050/pdfx/http:/localhost/pdf.html?lipperId=61&lang=fr-ca

我的nginx.conf是以下

http{
server {
    listen 3050 default_server;
    listen [::]:3050 default_server ipv6only=on;

    root C:\Workspaces\wmsi_workspace\pdf-renderer;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;


   location ~ ^/pdfx/(.*)$ {
      proxy_pass http://node_phantomjs_server_standard?site=$1;
   }

   location ~ ^/pdfxi/ {
      proxy_pass http://node_phantomjs_server_inject;
   }

   location ~ ^/api/rps {
      proxy_pass http://node_phantomjs_server_inject;
   }


    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 500 502 503 504 /index.html;

}

upstream node_phantomjs_server_standard {
  server 127.0.0.1:3000;
}

upstream node_phantomjs_server_inject {
  server 127.0.0.1:3050;
}

}

当我点击上面的URL时,它会被转换为http://localhost/pdf.html?lipperId=61并完全忽略查询字符串的过滤器部分(不是合法的查询字符串)。

我不确定为什么会这样,因为它总是跳过&符号以及它后面的内容。

任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:1)

如果您是从命令行测试网址,则问题是“'&'是bash shell的特殊字符。这可以通过将URL包装在单引号中来解决。

如果您没有从命令行进行测试,则翻译可能与浏览器有关。尝试从命令行进行测试以获得备用视角:

curl 'http://localhost:3050/pdfx/http%3A%2F%2Flocalhost%2Fpdf.html%3FlipperId%3D61%26lang%3Dfr-ca'