【发布时间】:2019-09-24 00:08:36
【问题描述】:
我正在尝试创建一个将流量重定向到特定端口的子 url。例如: 如果我的 URL 是 /a/status,它应该重定向到 127.0.0.1:8800/status。
我尝试配置 URL 正则表达式,但它似乎不起作用。以下是目前的调查结果:
location /
{
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header Access-Control-Allow-Origin *;
proxy_pass http://127.0.0.1:8800;
include /etc/nginx/proxy_params;
}
对于上述代码,URL /status 将流量正确重定向到 8800 端口。但是,使用下面的代码,存在问题。
location /a/
{
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header Access-Control-Allow-Origin *;
proxy_pass http://127.0.0.1:8800;
include /etc/nginx/proxy_params;
}
URL /a/status,不会重定向到端口 8800。我也尝试使用下面代码的正则表达式,但没有成功:
location ~* ^/(.+)/$
{
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header Access-Control-Allow-Origin *;
proxy_pass http://127.0.0.1:8787;
include /etc/nginx/proxy_params;
}
【问题讨论】:
标签: nginx nginx-location nginx-reverse-proxy