nginx子域代理通行证不起作用



我具有像这样的nginx配置

example.com配置

location /sample.php {
    #return 505; 
    proxy_pass http://sub1.example.com
}
location / {
    return 404;
}

sub1.example.com配置

location / {
    try_uri $uri @missing
}
location ~ .php {
    ...
}
location @missing {
    rewrite ^ http://sub1.example.com/index.php
}

当我在example.com/index.php中请求sample.php重定向并返回404时,我预测必须返回sub1.example.com/index.php,这是有效的URL

我的错误是什么?注意:当我毫无用处return 505时,这是工作的,然后返回505在浏览器中

您对sub1的配置正在执行重定向,因为您已经在rewrite语句上指定了完整的URL。有关详细信息,请参见此文档。

使用内部重写,例如:

rewrite ^ /index.php last;

或更简单,

location / {
    try_files $uri /index.php;
}

请参阅此文档以获取更多信息。

最新更新