手机版

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);
}

版权声明:Typecho Nginx 开启https(解决其他页面404问题)是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。

相关文章推荐