![请求重写后,NginX 代理/重定向](https://linux22.com/image/592345/%E8%AF%B7%E6%B1%82%E9%87%8D%E5%86%99%E5%90%8E%EF%BC%8CNginX%20%E4%BB%A3%E7%90%86%2F%E9%87%8D%E5%AE%9A%E5%90%91.png)
我正在尝试让 Nginx 在请求上运行一些正则表达式,并将它们发送到另一个服务器块,然后从第二个服务器块返回响应标头。目前我获得了 302 响应状态,如何从第二个服务器块获取标头?
举个例子,我想要一个这样的请求:http://nginxrouting.local/some/stuff/that/needs/to/be/removed/itemid=1234/more/stuff/topicid=1234 发送至http://nginxrouting_destination.local/itemid=1234topicid=1234从新位置返回标题
服务器块如下所示:
server {
server_name nginxrouting.local;
root /var/nginxrouting/public;
location / {
if ($request_uri ~* ".*(itemid=[0-9]*){1}.*") {
set $itemid $1;
}
if ($request_uri ~* ".*(topicid=[0-9]*){1}.*") {
set $topicid $1;
}
if ($request_uri ~* ".*(&type=RESOURCES){1}.*") {
set $resources $1;
}
rewrite ^ http://nginxrouting_destination.local/$itemid$topicid$resources? redirect;
add_header itemid $itemid;
}
}
server {
server_name nginxrouting_destination.local;
root var/nginxrouting/public_destination;
location / {
add_header working yes;
return 200;
}
}
答案1
您应该使用proxy_pass
配置指令(更多信息这里)rewrite
并不适合这种情况。