【问题标题】:Nginx differentiate between domain and sub-domainNginx 区分域和子域
【发布时间】:2016-06-17 20:22:54
【问题描述】:

我有 mydomain.com (192.168.1.10) 我还有另外两台服务器 192.168.1.11 和 192.168.1.12

现在我希望 *.mydomain.com 指向 192.168.1.11,mydomain.com 指向 192.168.1.12

我试过很多例子都没有运气。

有人知道如何实现吗??

有没有类似的东西:

location *.mydomain {
}

【问题讨论】:

    标签: nginx rewrite reverse-proxy


    【解决方案1】:

    您不需要子域的位置指令,只需使用正则表达式设置单独的服务器:

    server {
      server_name example.com;
      ...
    }
    
    server {
      server_name ~^(?<subdomain>.+)\.example\.com$;
      #you can use $subdomain in configuration
      #root /var/www/example.com/$subdomain;
      ...
    }
    

    然后您可以为这些服务器设置任何后端(上游)或代理设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-31
      • 2011-09-21
      • 2017-11-02
      • 2014-01-24
      • 2020-11-28
      • 2018-05-08
      相关资源
      最近更新 更多