【问题标题】:How do I serve the same static content from any subdomain of my main domain?如何从我的主域的任何子域提供相同的静态内容?
【发布时间】:2020-10-12 23:12:51
【问题描述】:

我有通过我的域提供的静态内容example.com

但是,我也想为访问这些子域的用户提供相同的静态内容。

sub1.example.com sub2.example.com ...

我知道我可以设置通配符并将传入请求重定向到主站点。 但我不想重定向,而是从该子域本身提供内容。用户应该仍然能够在地址栏中看到 sub1.example.com,就好像该站点已在该子域中配置。

但是这些子域(sub1、sub2 等)是动态的,不是在任何地方预先定义的,用户可以随意输入。

这可能吗?如果是,那我该如何实现。 (可能在 nginx/apache 中。)

【问题讨论】:

    标签: html nginx server subdomain wildcard-subdomain


    【解决方案1】:

    来自nginxdocumentation

    .example.org 形式的特殊通配符名称可用于匹配确切名称 example.org 和通配符名称 *.example.org

    所以你只需要使用

    server_name .example.com;
    

    不是

    server_name example.com;
    

    当然,您的域需要通配符 DNS 记录才能正常工作。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-24
    • 1970-01-01
    • 1970-01-01
    • 2012-07-23
    • 2015-11-16
    • 2018-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多