Nginx 删除子字符串并添加为 url 参数
Nginx remove substring and add as url param
这与 有关,但答案对我不起作用。
我需要转这个:/api/batch.json?param=1
进入/batch?param=1&format=json
Nginx 位置:
location /api/batch {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:8000/batch;
}
我该怎么做?
使用 rewrite...break
更改 location
中的 URI,然后使用 proxy_pass
.
向上游传递 URI
例如:
location /api/batch {
...
rewrite ^/api(/batch)\.(json)$ ?format= break;
proxy_pass ...;
}
rewrite
指令将自动附加原始参数(如果有),除非替换字符串以 ?
结尾。有关详细信息,请参阅 this document。
这与
我需要转这个:/api/batch.json?param=1
进入/batch?param=1&format=json
Nginx 位置:
location /api/batch {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:8000/batch;
}
我该怎么做?
使用 rewrite...break
更改 location
中的 URI,然后使用 proxy_pass
.
例如:
location /api/batch {
...
rewrite ^/api(/batch)\.(json)$ ?format= break;
proxy_pass ...;
}
rewrite
指令将自动附加原始参数(如果有),除非替换字符串以 ?
结尾。有关详细信息,请参阅 this document。