You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nginx配置WordPress访问/blog路径出现File not found错误如何解决

问题解决方法

你遇到的File not found错误由Nginx配置的三个逻辑错误导致,按以下步骤修改即可修复:

错误原因

  • 路径拼接规则错误:location匹配规则和alias路径末尾均未加斜杠,会导致实际请求的文件路径拼接错误
  • PHP路径解析错误:fastcgi_param中用$document_root拼接路径时,取的是全局server块配置的根目录,而非alias指定的WordPress存放目录,PHP拿到的路径完全错误
  • try_files规则不匹配:末尾的重写规则会跳出当前location块,导致路径二次解析错误

修复后的完整配置

location ^~ /blog/ {
    alias /var/www/html/example-blog/;
    index index.php index.html index.htm;
    try_files $uri $uri/ @blog_rewrite;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        include fastcgi_params;
    }
}

location @blog_rewrite {
    rewrite ^/blog/(.*)$ /blog/index.php?$args last;
}

生效步骤

  1. 执行nginx -t检查配置语法是否合法,确认返回success后再执行下一步
  2. 执行systemctl reload nginx重载Nginx配置
  3. 清空浏览器缓存后访问https://example.com/blog 测试即可

内容的提问来源于stack exchange,提问作者Rahul Dagli

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 19:57:00