【问题标题】:nginx sub domain proxy pass don't worknginx子域代理通行不通
【发布时间】:2017-07-25 04:53:40
【问题描述】:

我有这样的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

【问题讨论】:

    标签: nginx url-rewriting reverse-proxy


    【解决方案1】:

    您的sub1 配置正在执行重定向,因为您在rewrite 语句中指定了完整的URL。详情请见this document。

    使用内部重写,例如:

    rewrite ^ /index.php last;
    

    或者更简单地说,用:

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

    请参阅this document 了解更多信息。

    【讨论】:

      猜你喜欢
      • 2021-02-08
      • 2016-03-16
      • 1970-01-01
      • 2012-10-08
      • 2018-03-27
      • 1970-01-01
      • 2018-06-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多