nginx子域代理传递don';行不通

nginx子域代理传递don';行不通,nginx,url-rewriting,reverse-proxy,Nginx,Url Rewriting,Reverse Proxy,我有这样的nginx配置 example.com配置 location /sample.php { #return 505; proxy_pass http://sub1.example.com } location / { return 404; } location / { try_uri $uri @missing } location ~ \.php { ... } location @missing { rewrite ^ http

我有这样的nginx配置

example.com配置

location /sample.php {
    #return 505; 
    proxy_pass http://sub1.example.com
}
location / {
    return 404;
}
location / {
    try_uri $uri @missing
}
location ~ \.php {
    ...
}

location @missing {
    rewrite ^ http://sub1.example.com/index.php
}
sub1.example.com配置

location /sample.php {
    #return 505; 
    proxy_pass http://sub1.example.com
}
location / {
    return 404;
}
location / {
    try_uri $uri @missing
}
location ~ \.php {
    ...
}

location @missing {
    rewrite ^ http://sub1.example.com/index.php
}
当我请求
sample.php
重定向到
example.com/index.php
并返回404时,我预测必须返回
sub1.example.com/index.php
,这是一个有效的URL

我犯了什么错?
注意:当我取消注释
return 505
时,在浏览器中返回505

您的
sub1
配置正在执行重定向,因为您已在
rewrite
语句中指定了完整的URL。有关详细信息,请参阅

使用内部重写,例如:

rewrite ^ /index.php last;
或者更简单地说,包括:

location / {
    try_files $uri /index.php;
}
更多信息,请参阅