How can query string parameters be forwarded through a proxy_pass with nginx?

前端 未结 7 1486
Happy的楠姐
Happy的楠姐 2020-11-27 10:26
upstream apache {
   server 127.0.0.1:8080;
}
server{
   location ~* ^/service/(.*)$ {
      proxy_pass http://apache/$1;
      proxy_redirect off;
   }
 }
         


        
7条回答
  •  粉色の甜心
    2020-11-27 10:40

    you have to use rewrite to pass params using proxy_pass here is example I did for angularjs app deployment to s3

    S3 Static Website Hosting Route All Paths to Index.html

    adopted to your needs would be something like

    location /service/ {
        rewrite ^\/service\/(.*) /$1 break;
        proxy_pass http://apache;
    }
    

    if you want to end up in http://127.0.0.1:8080/query/params/

    if you want to end up in http://127.0.0.1:8080/service/query/params/ you'll need something like

    location /service/ {
        rewrite ^\/(.*) /$1 break;
        proxy_pass http://apache;
    }
    

提交回复
热议问题