【问题标题】:nginx wildcard domain mapping to another domain without changing URLnginx通配符域映射到另一个域而不更改URL
【发布时间】:2022-01-20 23:20:40
【问题描述】:

我已经设置了一个服务器,用于将通配符域映射到所需的 url,如下所示。

server {
    listen                  443 ssl;
    listen                  [::]:443 ssl;
    server_name             *.example.com;

    # SSL
    ssl_certificate         /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key     /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    return                  301 https://example.com$request_uri;
}

上面的代码工作正常,但子域网址正在更改为 example.com。例如,

**s1.example.com** is changing to **example.com**
**s2.example.com** is changing to **example.com**
***.example.com** is changing to **example.com**

我的要求是,*.example.com 应该被重定向到 example.com 但 url 应该保持与 *.example.com 相同强>.喜欢,

**s1.example.com** url should be **s1.example.com**
**s2.example.com** url should be **s2.example.com**
***.example.com** url should be ***.example.com**

但页面应该从 example.com

加载

请有人给出解决方案。

谢谢

【问题讨论】:

  • return 改变浏览器的地址栏,这就是它的作用。 example.com 是托管在外部还是在同一台机器上?
  • example.com 托管在同一台机器上。
  • 而不是添加一个新的server 块。您可以将*.example.com 添加到server_nameexample.com
  • example.com的服务器名旁边加上*.example.com后,地址栏的URL还是变成了 example.com.

标签: nginx reverse-proxy nginx-reverse-proxy nginx-config


【解决方案1】:

将主服务器块中的 server_name 从 example.com 更改为 .example.com 并将子域 ssl 证书添加到主服务器块解决了该问题。

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-18
  • 1970-01-01
  • 2022-08-15
  • 2013-01-20
  • 1970-01-01
  • 2010-10-10
  • 2017-05-10
相关资源
最近更新 更多