redirect - 如何在 ssl 中重定向两个域?

标签 redirect ssl nginx

我有域名 englishname.ca,我想重定向到 englishname.com。我做了一些配置,它适用于 HTTP 但不适用于 https。但是我去 http://englishname.ca , 我被重定向到 http://englishname.com但是当我去 https://englishname.ca ,我没有被重定向。

这是我的 session :

server {                                                                                                               
        server_name 162.243.216.109 staging.frenchname.com staging.englishname.ca staging.singularenglishname.com;
        add_header X-Frame-Options "SAMEORIGIN";

        rewrite  ^/(.*)$  $scheme://staging.englishname.com/$1 permanent;                                  
} 

server {
        listen 80 default deferred;
        server_name www.englishname.com staging.englishname.com;                               
        root /home/deployer/apps/site/current/public;   

        location ^~ /assets/ {                                                                                         
                gzip_static on;
                expires max;
                add_header Cache-Control public;
        }

        try_files $uri/index.html $uri @unicorn;
        location @unicorn {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_pass http://unicorn;
        }

        error_page 500 502 503 504 /500.html;
        client_max_body_size 4G;
        keepalive_timeout 10;
}

server {
        listen 443 default ssl;
        server_name www.englishname.com staging.englishname.com;
        root /home/deployer/apps/site/current/public;

        ssl on;
        ssl_certificate /etc/ssl/certs/www.englishname.crt;
        ssl_certificate_key /etc/ssl/private/www.englishname.key;

        ssl_session_timeout 5m;
        ssl_protocols sslv3 tlsv1 tlsv1.1 tlsv1.2;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        location ^~ /assets/ {
                gzip_static on;
                expires max;
                add_header Cache-Control public;
        }

        try_files $uri/index.html $uri @unicorn;
        location @unicorn {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_redirect off;
                proxy_pass http://unicorn;
        }

        error_page 500 502 503 504 /500.html;
        client_max_body_size 4G;
        keepalive_timeout 10;
}

我能做什么?

最佳答案

我找到了答案,我只是添加了这些行:

server {
        listen 443;
        server_name 162.243.216.109 staging.lescollectionneursassocies.com staging.associatedartcollectors.ca staging.associatedartcollector.com;
        add_header X-Frame-Options "SAMEORIGIN";

        rewrite  ^/(.*)$  $scheme://staging.associatedartcollectors.com/$1 permanent;
}

它与开头相同,但带有 listen 443

关于redirect - 如何在 ssl 中重定向两个域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27687099/

相关文章:

php - NGINX + PHP-FPM-是否应该将它们放在单独的容器中?

java - 使用 Spotify API - 如何在 Java 中跟踪多个重定向链接?

spring - 使用 post 参数从 spring Controller 重定向

ios - 我可以使用根 ca 证书签署 iOS 移动配置文件吗

angular - 如何在 Nginx 容器内路由 Angular 应用程序?

http - 使用 nginx 重定向所有不是来 self 的 IP 的请求

performance - 301 重定向 Apache : It is better to do it in httpd. conf 或 .htaccess?

根据用户的位置将用户重定向到最近的服务器,而无需更改 url

ssl - 2 路 SSL - 发送客户端证书时 IIS 7 返回 403.16

ssl - 在数据库中使用 SSL 证书