【发布时间】:2022-01-17 07:33:08
【问题描述】:
我有以下 nginx 配置:
upstream front {
server localhost:4000;
}
upstream back {
server localhost:8000;
}
server {
server_name my_domain.com;
listen 80;
location ~ /api($|/.*) {
rewrite ^/api($|/.*) /VirtualHostBase/http/my_domain.com:80/Intk/VirtualHostRoot/_vh_api$1 break;
proxy_pass http://back;
}
location ~ / {
add_header Cache-Control "public";
expires +1m;
proxy_pass http://front;
}
location ~ /orgs/.+$ {
return 301 http://my_domain.com/orgs;
}
location ~* manage_ {
deny all;
}
location ~ \.php$ {
return 410;
access_log off;
}
location ~ ^/(wp-admin|wp-content) {
return 410;
access_log off;
}
location = /nginx_stub_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
}
server {
server_name www.my_domain.com;
listen 80;
access_log off;
return 301 http://my_domain.com$request_uri;
}
我不明白它有什么问题,特别是第三个位置块。
如果我写my_domain.com/orgs/some-org,它不应该重定向到my_domain.org/orgs吗?
它没有那样做,它就像那个位置块不存在一样。
据我了解,nginx 应该以最具体的匹配来满足请求,它应该是第三个位置块中的那个。
【问题讨论】: