Answer the question
In order to leave comments, you need to log in
How to use URI in proxy_pass for @location?
Seems like the simplest config, but
server {
listen 80;
server_name "test";
location @remote {
proxy_pass https://someremoteserver/api/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For f$proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_next_upstream error timeout http_404 http_502 http_504;
}
location / {
root /home/www/test/;
index index.html;
try_files $uri $uri/ @remote;
}
}
Answer the question
In order to leave comments, you need to log in
You can just change $uri :
location @remote {
rewrite (.*) /api$1 break;
proxy_pass https://someremoteserver;
...
}
If the URI is changed inside the proxied location using the rewrite directive, and the request will be processed with this configuration (break):location /name/ { rewrite /name/([^/]+) /users?name=$1 break; proxy_pass http://127.0.0.1; }
In this case, the URI specified in the directive is ignored, and the entire modified request URI is sent to the server.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question