Nginx pass_proxy subdirectory without url decoding

后端 未结 2 549
太阳男子
太阳男子 2020-11-29 03:27

I need to write an nginx location directive to proxy requests to subdirectory to another server preserving urlencoding and removing subdirectory pre

2条回答
  •  一个人的身影
    2020-11-29 04:00

    What you have to do is fairly easy as long as we are talking prefix matching with ^~ or no modifier

    location /api/ {
      # if you don't want to pass /api/ add a trailing slash to the proxy_pass
      proxy_pass http://localhost:8080/;
    
      ...
    }
    

    And everything will be passed along without decoding, you don't have to pass $uri

    Also while you use proxy pass you should also set these headers

    # pass headers and body along
    proxy_pass_request_headers on;
    proxy_pass_request_body on;
    
    # set some headers to make sure the reverse proxy is passing along everything necessary
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    

提交回复
热议问题