Nginx反向代理&使用参数重写

时间:2017-08-22 23:14:36

标签: nginx parameters proxy reverse

我试图以下列形式部署需要输入参数(" Part")的Bokeh服务器应用程序:

(1) http://127.0.0.1:5100/myapp?Part=1234-567

我想使用重写,以便当用户点击以下网址时

(2) http://<my_hostname>/myappRenamed/Part=1234-567

Nginx反向代理URL(1)

现在,我的配置文件类似于下面的内容。

location /myappRenamed/ {
    proxy_pass http://127.0.0.1:5100;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host:$server_port;
    proxy_buffering off;
}

当我点击

时,这是有效的
http://<my_hostname>/myappRenamed/myapp?Part=1234-567

除了我希望网址

http://<my_hostname>/myappRenamed/Part=1234-567

1 个答案:

答案 0 :(得分:0)

您应该首先重写URL,使用nginx重写功能和代理它使URL友好:

location /myappRenamed/ {
    rewrite ^/myapp(.*) /$1 break;
    proxy_pass http://127.0.0.1:5100;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host:$server_port;
    proxy_buffering off;
}

我没有你的ENV所以我无法真正测试规则,但你有了这个概念。