我需要将像* .lang.domain.com这样的网址重写为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;
}
}