加密前重写https-URL
Rewrite https-URL before encryption
我需要将类似 *.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 (unsafe). After that they will be redirected to https://lang.domain.com。
所以我的问题是在 nginx 中建立 https 连接之前是否可以进行重定向?还是可以在一些上层实现?
server {
listen 80 default;
server_name www.domain.com domain.com *.domain.com;
if ($host ~* "^.+\.(.+\.domain\.com)$") {
set "$domain" "";
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" "";
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;
}
}
发生重定向 after 建立了安全连接。所以不,你不能有一个重定向来处理你的特殊情况。
我需要将类似 *.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 (unsafe). After that they will be redirected to https://lang.domain.com。
所以我的问题是在 nginx 中建立 https 连接之前是否可以进行重定向?还是可以在一些上层实现?
server {
listen 80 default;
server_name www.domain.com domain.com *.domain.com;
if ($host ~* "^.+\.(.+\.domain\.com)$") {
set "$domain" "";
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" "";
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;
}
}
发生重定向 after 建立了安全连接。所以不,你不能有一个重定向来处理你的特殊情况。