【问题标题】:Rewriting wildcard domain with HTTPS使用 HTTPS 重写通配符域
【发布时间】:2016-12-15 06:45:31
【问题描述】:

是否可以在 nginx 中重写 HTTPS 通配符域,或者我们应该为每个域创建多个结构/文件?

假设我有以下内容:

1. subdomain1.domain.com
2. subdomain2.domain.com

如果我没有 HTTPS,我会使用以下方法,效果很好:

server {
 listen 443;
server_name *.domain.com;
charset utf-8;
}

不,如果我使用 HTTPS,我将不得不编写一个如下所示的新块(使用letsencryt)

以下只是一个测试域(只有1个域)

 server {
    server_name test.me;
    rewrite ^ https://test.me$request_uri? permanent;
}

server {
    listen 443;
    server_name test.me;
    charset utf-8;
    ...
 }

是否可以对多个域执行相同的操作? 服务器 { server_name .domain.com; 重写 ^ https://.domain.com$request_uri?永恒的; }

server {
    listen 443;
    server_name *.domain.com;
    charset utf-8;
    ...
 }

我尝试了上面的配置,但它不起作用,它会将我重定向到

https://%2A.domain.com.domain.com/  (just for test)

有可能做这样的事情吗?或者我应该为每个子域设置不同的块吗?

【问题讨论】:

    标签: nginx https


    【解决方案1】:

    使用nginx 提供的变量之一从请求行中提取主机名。例如$host(详见this document):

    server { 
        server_name .domain.com;
        return 301 https://$host$request_uri;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-11
      • 2017-05-09
      • 1970-01-01
      • 1970-01-01
      • 2018-10-22
      • 2012-08-09
      • 2014-06-09
      • 1970-01-01
      相关资源
      最近更新 更多