Skip to content

LNMP 环境下 Typecho 后台 404 的一般解决方案

Published: at 11:45

手动配置 LNMP 并部署 Typecho 时,后台会出现 404。最终测试可用解决方案记录如下,便于日后查阅。

  1. 打开虚拟主机配置文件
    文件位于 /etc/nginx/sites-available/,并在 /etc/nginx/sites-enabled/ 建立了同名符号链接。

  2. 用以下内容覆盖原文件(修改域名、路径等参数):

server {
    listen 80;
    server_name example.com;   # 替换为网站域名
    root /var/www;                   # 替换为你的Typecho安装路径

    index index.php index.html;

    location / {
        try_files $uri $uri/ @rewrite;    # 关键:路由重定向
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php/$1;  # 将请求重写到index.php
    }

    location ~ [^/]\.php(/|$) {
        include fastcgi_params;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;  # 或127.0.0.1:9000
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;         # 解析PathInfo
    }
}
  1. 重启 Nginx :
systemctl restart nginx

Next Post
mdBook:使用 Pandoc 快速创建高质量 PDF 电子书