【问题标题】:NginX - From Non-SSL Domain to New SSL Domain - Proper redirect neededNginX - 从非 SSL 域到新的 SSL 域 - 需要正确的重定向
【发布时间】:2018-02-15 16:55:43
【问题描述】:

情况如下:

  1. 旧域 (none-SSL) 我们称之为“no-ssldomain.com”
  2. 新域(使用 SSL)我们称之为“ssldomain.com”

两个域都指向同一个服务器。所以使用这两个域都可以。

No-ssldomain.com 已经运行了 7 年,但由于我所追求的域名现在可用,我使用 SSL 注册了它并试图永久迁移到它。

它在 Wordpress 上运行,所有永久链接都有效,所有重定向都有效。旧的 no-ssldomain.com 嵌套链接完美地重定向到新的 ssldomain.com。所以没有谷歌处罚。不错。

我当前的配置做了什么(使用分号,因为我不能发布超过 2 个链接):

  1. 如果您输入:http;//no-ssldomain.com > 重定向到 > https;//ssldomain.com
  2. 如果您输入:https;//no-ssldomain.com > 重定向到 > https;//ssldomain.com 李>
  3. 如果您输入:http;//no-ssldomain.com/xx/xx/xx > 重定向到 > https;//ssldomain.com /xx/xx/xx

但发现 1 个烦人的问题。

如果您输入:https;//no-ssldomain.com/xx/,它将使用 no-ssldomain.com 打开网页并显示不安全警告。它不会重定向到新的 ssldomain.com。那么我怎样才能正确地重定向它呢?

这是我的服务器配置:

server {
        listen 80;
        server_name no-ssldomain.com;
        location / {
                rewrite "/([0-9]{4})/([0-9]{2})/(.*)" http://$host/$3 permanent;
        }
        if ($host = "no-ssldomain.com") {
                return 301 https://ssldomain.com$request_uri;
        }
}

server {
        listen 80;
        listen 443;
        ssl on;
        ssl_certificate /xxx/xxx/ssldomain_com.chained.crt;
        ssl_certificate_key /xxx/xxx/server.key;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php;

        server_name ssldomain.com;
        location /wp-admin {
                index index.php;
        }
        location / {
                index index.php;
                rewrite "/([0-9]{4})/([0-9]{2})/(.*)" https://ssldomain.com/$3 permanent;
                try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
}

【问题讨论】:

    标签: ssl redirect nginx https


    【解决方案1】:

    经过一个小时的尝试,我找到了答案。

    我所做的是为 no-ssldomain.com 安装 Let's Encrypt 的免费证书,现在我可以监听所述域的端口 443。

    然后将我的配置的第一个“服务器”部分更改为:

    server {
            listen 80;
            listen 443;
            #ssl on;
            ssl_certificate /etc/letsencrypt/live/xxxx.com/fullchain.pem;
            ssl_certificate_key /etc/letsencrypt/keys/0000_key-certbot.pem;
    
            server_name no-ssldomain.com www.no-ssldomain.com;
    
            return 301 https://ssldomain.com$request_uri;
    }
    

    然后一切都按预期进行!谢谢!

    【讨论】:

      猜你喜欢
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 2017-01-09
      • 2014-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多