【发布时间】:2015-05-21 10:39:54
【问题描述】:
我只有 example.com 的 SSL 证书,并且想使用 nginx 将 http://example.com 和 http://*.example.com 都重定向到 https://example.com。我知道如果没有包含所有子域的证书,就不可能通过 SSL 重定向子域,但至少,我应该能够重定向正在输入 www.example.com 的用户(端口 80 ) 到 SSL 主页。
我当前的 nginx 配置如下:
server {
# This should catch all non-HTTPS requests to example.com and *.example.com
listen 80;
server_name example.com *.example.com;
access_log off;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
# Actual server config starts here...
请求http://example.com 将被正确重定向到https://example.com,而http://www.example.com 导致https://www.example.com(当然,浏览器显示证书错误)。我认为这与 server_name 值的处理顺序有关,但我没有找到有关如何强制执行某个顺序的任何信息。
【问题讨论】: