腾讯云CDN开启SSL返回302

站点建设1 24.1K3字数 1445阅读4分49秒阅读模式

腾讯云CDN开启SSL返回302

今天这个标题真的是难倒我了。下面解释下要说的内容吧!文章源自亦枫博客-https://yflad.cn/749.html

使用腾讯云的CDN,配置好SSL后,开启强制HTTPS,默认是返回302的。但是不开启强制HTTPS,源站配置的HTTPS跳转貌似是无效的(首页)文章源自亦枫博客-https://yflad.cn/749.html

比如:文章源自亦枫博客-https://yflad.cn/749.html

访问的是http://www,yflad.cn,在不开启强制HTTPS时,返回的是301,但是跳转的还是http://yflad.cn文章源自亦枫博客-https://yflad.cn/749.html

PS:只是首页这样,再次点击时就变成HTTPS文章源自亦枫博客-https://yflad.cn/749.html

询问了工程师关于腾讯云的CDN默认跳转后,说是   301重定向到https上文章源自亦枫博客-https://yflad.cn/749.html

腾讯云CDN开启SSL返回302文章源自亦枫博客-https://yflad.cn/749.html

 文章源自亦枫博客-https://yflad.cn/749.html

说下为什么非得要301?文章源自亦枫博客-https://yflad.cn/749.html

302(临时重定向,request_uri):搜索引擎会抓取新的内容而保留旧的网址。因为服务器返回302代码,搜索引擎认为新的网址只是暂时的。文章源自亦枫博客-https://yflad.cn/749.html

301(永久重定向,permanent):搜索引擎在抓取新内容的同时也将旧的网址替换为重定向之后的网址。301也是百度等搜索引擎所倾爱的,这让我想到之前的HTTPS认证是不是也是这个原因(只能等审核下来再看看吧)。文章源自亦枫博客-https://yflad.cn/749.html

 文章源自亦枫博客-https://yflad.cn/749.html

贴上permanent是为了说下nginx 的配置文章源自亦枫博客-https://yflad.cn/749.html

  1. server
  2. {
  3.     listen 80 default_server;
  4.     listen 443 ssl;
  5.     server_name yflad.cn;
  6.     index index.php index.html index.htm default.php default.htm default.html;
  7.     root /www/wwwroot/wpblog;
  8.     #error_page 404/404.html;
  9.     ssl_certificate    /etc/xx/xxx/xxxx/xxxx.pem;
  10.     ssl_certificate_key    /etc/xx/xxx/xxxx/xxxx.pem;
  11.     if ($server_port !~ 443){
  12.         rewrite ^(.*)$ https://$host$1 permanent;
  13.     }
  14.     error_page 497  https://$host$request_uri;

 文章源自亦枫博客-https://yflad.cn/749.html


 文章源自亦枫博客-https://yflad.cn/749.html

下面说下自己的解决方法吧!文章源自亦枫博客-https://yflad.cn/749.html

方法一:在关闭 强制HTTPS 的情况下,在header头部加入以下代码文章源自亦枫博客-https://yflad.cn/749.html

  1. <script type="text/javascript">
  2. if (document.location.protocol != "https:") {
  3.         locationlocation.href = location.href.replace(/^http:/,"https:");
  4. }
  5. </script>

PS:意思是说,当检测到打开的是http页面的话,则自动跳转到对应的https页面文章源自亦枫博客-https://yflad.cn/749.html

 文章源自亦枫博客-https://yflad.cn/749.html

17-06-12文章源自亦枫博客-https://yflad.cn/749.html

方法二:在nginx站点配置文件,看到下面这样的代码

  1. rewrite ^/.*$ https://$host$request_uri;
  2. ##或者
  3. rewrite ^/.*$ https://$host$uri;

替换成

  1. rewrite ^/.*$ https://$host$request_uri permanent;

 


 

当再次检测的时候返回的就是301永久跳转了
腾讯云CDN开启SSL返回302

 

 

重定向还有很多方法,就不一一列举了!毕竟自己墨水有限,谈不上更好的方法!本文只是记录下小站的HTTPS认证。如果有好的建议或者方法,请下方留言或者私信我,不胜感激

 

6月12日

百度搜索了下“亦枫”,终于看见HTTPS认证通过了腾讯云CDN开启SSL返回302

腾讯云CDN开启SSL返回302

 

继续阅读
历史上的今天
6月
12
扫扫关注公众号
weinxin
我的微信
扫扫体验小程序
weinxin
我的公众号
亦枫
  • 本文由 发表于 2017年6月12日 12:04:06
评论  1  访客  0  作者  1
    • 亦枫
      亦枫

      如果你申请了ssl,请部署到CDN

    匿名

    发表评论

    匿名网友 填写信息

    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

    确定