HTTPS 到 HTTPS 重定向 Nginx [英] HTTPS to HTTPS redirect Nginx

查看:64
本文介绍了HTTPS 到 HTTPS 重定向 Nginx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一个 HTTPS 重定向到另一个 HTTPS(我只有一个域的 SSL 证书)?

How can I redirect an HTTPS to another HTTPS (I only got one SSL certificate for a single domain)?

例如,如何从 https://example.org 重定向到 https://example.com?

For example, how to redirect from https://example.org to https://example.com?

我已经尝试过在 Google 和其他论坛上进行搜索,但都没有找到有效的方法.

I already tried to search Google and other forums, but nothing I found worked.

推荐答案

做起来超级简单:

server {
    listen       443 ssl;
    server_name  example.org;
    return       301 http://www.example.com$request_uri;
}

参见文档,它描述了重写和 301 重定向之间的区别(从 Nginx 0.9.1 开始推荐)

See the docs, it describes a difference between rewrite and 301 redirect (recommended since Nginx 0.9.1)

更新:

http {
    ssl_certificate /etc/nginx/ssl/example.com/10599/server.crt;
    ssl_certificate_key /etc/nginx/ssl/example.com/10599/server.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/ssl/dhparams.pem;


    server {
        listen       80;
        listen       443 ssl;
        server_name  example.eu www.example.eu example.org www.example.org www.example.com;
        return       301 https://example.com$request_uri;
    }


    server {
        listen 443 ssl;
        server_name example.com;
        root /home/forge/example.com;

        index index.html index.htm index.php;

        client_max_body_size 20m;

        charset utf-8;

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }

        access_log off;
        error_log  /var/log/nginx/example.com-error.log error;

        error_page 404 /index.php;

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }

        location ~ /\.ht {
            deny all;
        }
    }

}

这篇关于HTTPS 到 HTTPS 重定向 Nginx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆