宝哥软件园

Typecho Nginx 开启https(解决其他页面404问题)

编辑:宝哥软件园 来源:互联网 时间:2020-05-04

本文假设你已经申请好了证书,并已经配置到服务器

1、在项目根目录下的配置文件config.inc.php中添加如下代码,让后台访问https资源,不加的话后台登录仍然访问http;

define('__TYPECHO_SECURE__',true);

2、nginx配置文件中,在你解析443端口的server中,在localhost中添加如下代码,地址带参数跳转,不加会导致其他页面404;

try_files $uri $uri/ /index.php?$query_string;
if (!-e $request_filename){  
    rewrite ^/(.*) /index.php last;  
} 

例如:

location ~ .*.php(/.*)*$ {
    try_files $uri $uri/ /index.php?$query_string;
    if (!-e $request_filename){
        rewrite ^/(.*) /index.php last;
    }
   ...
}

3、在项目代码中header.php中加入如下代码,默认访问https(可选);

if ($_SERVER["HTTPS"] <> "on")
{
    $xredir = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    header("Location: ".$xredir);
}
更多资讯
游戏推荐
更多+