【发布时间】:2015-11-20 09:03:09
【问题描述】:
我有一个*.example.com 的 SSL 通配符证书,它对根域无效。我希望 Ubuntu 14.04 上的 Nginx 到
- 只接受对已定义主机的请求
- 将根域和www子域的所有http请求重定向到https www子域
- 仅在端口 443 上为根域返回 404,例如如果请求是 https://example.com
通过复制下面的配置,我设法实现了 1 和 2。
server {
#listen 80;
#isten 443;
return 404;
}
server {
listen 80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl;
#certificate and key referenced in common.conf
server_name www.example.com;
root /usr/share/nginx/html/example.com;
index index.php index.html index.htm;
include common/common.conf;
}
当我从上面的第二行和第三行中删除注释标记时,希望仅为 https://example.com 返回 404 - 没有任何效果。例如,我在 Chrome 中得到了 https://www.example.com/ 和 http://ww.example.com/ 的 ERR_CONNECTION_CLOSED。
我应该怎么做才能同时实现 1)、2) 和 3)?
非常感谢。
【问题讨论】: