【问题标题】:How to redirect specific name only domain with https to another domain如何使用 https 将特定名称的域重定向到另一个域
【发布时间】:2020-06-02 08:54:23
【问题描述】:

我有 NGINX 服务器,它的目标是两个域 https://a.comhttps://b.com 。我希望如果 url 来自 only https://a.com 然后应该重定向到 https://b.com 。简而言之,我的服务器应该作为 https://b.com 提供给所有即将到来的 https 链接

【问题讨论】:

    标签: nginx


    【解决方案1】:

    试试这个

    server {    # traffic from http://a.com will redirect to https://b.com
        listen      80;
        server_name *.a.com;
    
        return 301 https://b.com$request_uri;
    }
    
    server {    # traffic from https://a.com will redirect to https://b.com
        listen      443 ssl;
        server_name *.a.com;
    
        ssl_certificate     /path/to/your/certs/a.com.crt;
        ssl_certificate_key /path/to/your/certs/a.com.key;
    
        ...
    
        return 301 https://b.com$request_uri;
    }
    
    server {    # will serve your app
        listen  443 ssl default_server;
    
        server_name *.b.com;
    
        ssl_certificate     /path/to/your/certs/b.com.crt;
        ssl_certificate_key /path/to/your/certs/b.com.key;
    
        ...
    
        location / {
            root        /path/to/your/app;
            index       index.html;
            try_files   $uri $uri/ /index.html;
        }
    }
    

    【讨论】:

    • 感谢它的工作
    猜你喜欢
    • 2018-03-06
    • 1970-01-01
    • 2014-08-28
    • 2011-12-21
    • 2013-04-01
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多