【发布时间】:2020-06-02 08:54:23
【问题描述】:
我有 NGINX 服务器,它的目标是两个域 https://a.com 和 https://b.com 。我希望如果 url 来自 only https://a.com 然后应该重定向到 https://b.com 。简而言之,我的服务器应该作为 https://b.com 提供给所有即将到来的 https 链接
【问题讨论】:
标签: nginx
我有 NGINX 服务器,它的目标是两个域 https://a.com 和 https://b.com 。我希望如果 url 来自 only https://a.com 然后应该重定向到 https://b.com 。简而言之,我的服务器应该作为 https://b.com 提供给所有即将到来的 https 链接
【问题讨论】:
标签: nginx
试试这个
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;
}
}
【讨论】: