在加密之前重写https-URL

问题描述:

我需要将* .lang.domain.com之类的URL重写为lang.domain.com,并且使用nginx重写模块成功完成了这一操作。我有通配证书* .domain.com,它不能保护4级域名,如test.lang.domain.com 主要问题是当用户在浏览器中键入https://bla-bla.lang.domain.com时,他们首先得到关于连接的通知是不安全的。然后他们需要点击高级并继续https://bla-bla.lang.domain.com(不安全)。之后,他们将被重定向到https://lang.domain.com。 所以我的问题是在nginx中建立https连接之前是否可以做重定向?还是可以在一些高层实现?在加密之前重写https-URL

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; 
    } 
} 

重定向发生after安全连接建立。所以不,你不能有重定向来处理你的特定情况。