不懂先生

typecho全站添加ssl
1、申请SSL证书2、Typecho设置登录Typecho后台 -> 设置 -> 基本设置 ->...
扫描右侧二维码阅读全文
06
2022/04

typecho全站添加ssl

1、申请SSL证书

2、Typecho设置

登录Typecho后台 -> 设置 -> 基本设置 -> 站点地址改成https的域名是必须的。编辑Typecho站点根目录下的文件config.inc.php加入下面一行配置,否则网站后台还是会调用HTTP资源。

/** 开启HTTPS */
define('__TYPECHO_SECURE__',true);

由于Chrome浏览器对HTTPS要求较高,Firefox已经显示小绿锁,可是Chrome还是有警告提示,F12查看,评论表单的action地址还是HTTP,找到站点主题目录下的comments.php文件,并搜索$this->commentUrl(),将其替换为:echo str_replace("http","https",$this->commentUrl()); 最后保存。

3、HTTP重定向到HTTPS(配置nginx,若有面板可以面板中直接配置)

这样HTTP的方式还是可以访问的,我们可以通过WEB服务器(Ningx)将80端口(HTTPS)重定向到443端口(HTTPS),强制全站HTTPS,
/usr/local/nginx/conf/vhost/youdomain.com.conf添加以下代码

server
{
        listen 80;
        server_name bossdong.cn www.bossdong.cn;
        rewrite ^(.*) https://www.bossdong.cn$1 permanent;
}

作用是当以HTTP请求bossdong.cn或www.bossdong.cn的时候全部301重定向到https://www.bossdong.cn

参考文章:

  1. https://www.xiaoz.me/archives/7057
  2. https://www.xiaoz.me/note/64.html
  3. https://www.cnblogs.com/sunmmi/articles/10682575.html
Last modification:April 6th, 2022 at 08:37 pm

Leave a Comment