【发布时间】:2017-11-06 08:31:19
【问题描述】:
我需要将 *.lang.domain.com 之类的 URL 重写为 lang.domain.com,我使用 nginx 重写模块成功地做到了。我有通配符证书 *.domain.com,它不能保护像 test.lang.domain.com 这样的 4 级域
主要问题是当用户在浏览器中输入https://bla-bla.lang.domain.com 时,他们首先会收到有关连接不安全的通知。然后他们需要点击高级并继续https://bla-bla.lang.domain.com(不安全)。之后,他们将被重定向到https://lang.domain.com。
所以我的问题是是否可以在 nginx 中建立 https-connection 之前进行重定向?还是可以在一些上层实现?
server {
listen 80 default;
server_name www.domain.com domain.com *.domain.com;
if ($host ~* "^.+\.(.+\.domain\.com)$") {
set "$domain" "$1";
rewrite ^(.*)$ https://$domain$uri permanent;
}
return 301 https://$host$request_uri;
}
server {
listen 443 default;
server_name www.domain.com domain.com *.domain.com;
if ($host ~* "^.+\.(.+\.domain\.com)$") {
set "$domain" "$1";
rewrite ^(.*)$ https://$domain$uri permanent;
}
ssl on;
ssl_certificate /etc/ssl/domain.com/domain.com.ca-bundle;
ssl_certificate_key /etc/ssl/domain.com/domain.com.key;
include "conf.d/ssl_settings.default";
include "conf.d/redirect.ssl.default";
include "conf.d/logger_front.default";
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HTTPS on;
proxy_pass https://somestream;
}
}
【问题讨论】:
标签: mod-rewrite nginx https subdomain