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

Nginx下子目录安装WordPress启用美化固定链接返回404错误求助

该故障和域名设置无关,核心问题是Nginx路径配置与WordPress站点地址配置不匹配。

你当前的Nginx配置中root指令直接指向了WordPress子目录/var/www/digitext-v1,意味着访问http://192.168.11.8/[路径]时,Nginx会去/var/www/digitext-v1/[路径]下查找资源。但从错误日志的请求记录可以看到,你实际访问的站点地址带了/digitext-v1前缀,也就是http://192.168.11.8/digitext-v1/[路径],此时Nginx会尝试查找/var/www/digitext-v1/digitext-v1/[路径]的资源,找不到自然返回404错误。

日志中出现的preg_match警告是popup-maker插件的代码兼容问题,和本次404故障无关联,可在解决固定链接问题后单独排查。

修复方案

你可以根据自己的访问需求选择以下任意一种方案:

方案1:保留带/digitext-v1前缀的访问路径

如果你希望继续用http://192.168.11.8/digitext-v1的形式访问站点,按如下步骤修改:

  1. 调整Nginx配置:
server {
    listen 80;
    server_name digitextv1 192.168.11.8;

    # 改为站点根目录,不再直接指向子目录
    root   /var/www;
    index  index.php index.html index.htm;

    # Add trailing slash to */wp-admin requests.
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;

    # 新增子目录专属匹配规则
    location /digitext-v1 {
        try_files $uri $uri/ /digitext-v1/index.php?$args;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
  1. 进入WordPress后台,打开「设置」-「常规」,确认WordPress地址(URL)和站点地址(URL)均设置为http://192.168.11.8/digitext-v1
  2. 重启Nginx服务,再进入WordPress后台「设置」-「固定链接」,直接点击保存刷新重写规则即可。

方案2:直接用根路径访问站点

如果你不需要/digitext-v1前缀,希望用http://192.168.11.8直接访问站点:

  1. 进入WordPress后台,打开「设置」-「常规」,将WordPress地址(URL)和站点地址(URL)均修改为http://192.168.11.8
  2. 原有Nginx配置不需要改动,重启Nginx服务后,进入「固定链接」页面点击保存刷新规则即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.05 19:27:01