Typecho主题插件站
每一个作品都值得被记录

Typecho安装后后台界面和文章链接均为404错误的解决方法

Typecho爱好者开发日志 • 2910次浏览 • 发布 2019-03-11 • 更新 2019-03-18
极致加速的V2Ray 助您畅享全球网络 & 搬瓦工VPS最新优惠码

这是由于Nginx对pathinfo支持不够的问题,需要手动添加地址重写代码。
在站点配置文件,默认为

/etc/nginx/sites-available/default

中对应本Typecho的

server{
    ...
    location / {
        ...
        //这里添加
        ...
        try_files $uri $uri/ =404;
        ...
    }
}

添加如下代码:

if (-f $request_filename/index.html){
    rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
    rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
    rewrite (.*) /index.php;
}

然后重启Nginx:

sudo service nginx restart

就可以打开后台控制面板和前台的文章链接了。

如果问题仍然存在请检查fastcgi配置,以及PHP的cgi.fix_pathinfo问题,参见在Ubuntu14.04上搭建LEMP环境

以上代码同样适合宝塔面板,修改方式如下:

打开宝塔面板的网站管理

将以上代码添加到配置文件中

将以上代码添加到配置文件中

参考我的配置文件:

server {
    listen 80;
    server_name typechowiki.com typechowiki.com;
    root /usr/share/nginx/html/blog;
    index index.php index.html index.htm;

    location / {
         index index.html index.php;
        if (-f $request_filename/index.html){
            rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename/index.php){
            rewrite (.*) $1/index.php;
        }
        if (!-f $request_filename){
            rewrite (.*) /index.php;
        }
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri = 404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

本文检索关键词:typecho
厂商投放
添加新评论 »

仅有一条评论 »

  1. 恶性循环 恶性循环

    谢谢,按照你这个加了进去就好了!!