镖师 发表于 2023-8-20 11:01:46

社区发完贴返回404 Not Found nginx

DZ社区新手,电脑、手机都试过了,社区发完贴返回提示404 Not Found nginx请教如何解决

IT618发布 发表于 2023-8-20 11:02:32

伪静态

Discuz智能体 发表于 2025-3-13 14:44:10

关于Discuz发帖后出现404 Not Found nginx错误的问题,建议从以下五个技术维度进行排查和解决:

1. **伪静态配置核查**
- 在Discuz后台进入「全局→SEO设置→URL静态化」,确认已勾选需要的伪静态规则
- 检查Nginx配置文件(通常位于/etc/nginx/sites-enabled/)是否包含以下标准规则:

location / {
    rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
    rewrite ^([^\.]*)/article-(+)-(+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
    rewrite ^([^\.]*)/forum-(\w+)-(+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
    rewrite ^([^\.]*)/thread-(+)-(+)-(+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
    rewrite ^([^\.]*)/group-(+)-(+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
    rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
    rewrite ^([^\.]*)/blog-(+)-(+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
    rewrite ^([^\.]*)/(fid|tid)-(+)\.html$ $1/index.php?action=$2&value=$3 last;
    rewrite ^([^\.]*)/(+*)-(+)\.html$ $1/plugin.php?id=$2:$3 last;
    if (!-e $request_filename) {
      return 404;
    }
}

2. **PATHINFO模式验证**
- 修改Nginx配置增加PATHINFO支持:
location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    include fastcgi_params;
    fastcgi_pass unix:/run/php/php7.4-fpm.sock; # 根据实际PHP版本修改
    fastcgi_index index.php;
}

3. **目录权限深度检查**
- 执行命令修正权限:
find /网站路径/data -type d -exec chmod 755 {} \;
find /网站路径/data -type f -exec chmod 644 {} \;
chown -R www-data:www-data /网站路径/uc_server/data
chmod -R 755 /网站路径/uc_server/data

4. **多维度缓存清理**
- 删除以下目录中的缓存文件:
- /data/cache/
- /data/template/
- /data/threadcache/
- /data/plugin/
- 在SSH执行:
rm -rf /网站路径/data/cache/*.php
service php7.4-fpm reload # 根据实际PHP版本调整

5. **日志联合分析**
- 同时查看Nginx错误日志和PHP错误日志:
tail -f /var/log/nginx/error.log /var/log/php7.4-fpm.log # 路径可能因环境而异
- 在config/config_global.php中开启调试模式:
$_config['debug'] = 1;
$_config['admincp']['runquery'] = 1;

**特殊场景处理方案:**
- 当使用子目录安装时,需在伪静态规则前增加目录标识:
rewrite ^/subdir/(.*)/topic-(.+)\.html$ /subdir/$1/portal.php?mod=topic&topic=$2 last;
- 使用云存储插件时,需在插件配置中设置正确的回调URL白名单
- 若使用Redis缓存,检查maxmemory-policy配置是否为volatile-lru

建议按照上述顺序逐步排查,每完成一个步骤后立即进行发帖测试。若问题仍未解决,可通过查看Nginx日志中的具体404请求路径,分析是伪静态规则缺失还是实际文件不存在导致。多数情况下修正伪静态配置即可解决,但需注意不同Discuz版本间的规则差异。
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。

Discuz智能体 发表于 2025-3-13 15:08:30

出现发帖后返回404 Not Found(Nginx环境)的问题,通常与伪静态配置有关。以下是排查和解决方案:

1. **检查伪静态配置**
- 在DZ后台进入【全局】-【SEO设置】-【URL静态化】
- 确认已勾选"启用伪静态"
- 在"查看当前的Rewrite规则"处选择"Nginx Web Server"

2. **核对nginx配置文件**
确保包含以下核心规则(注意替换域名):
location / {
    try_files $uri $uri/ /index.php?$args;
    rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
    rewrite ^([^\.]*)/article-(+)-(+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
    rewrite ^([^\.]*)/forum-(\w+)-(+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
    rewrite ^([^\.]*)/thread-(+)-(+)-(+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
    rewrite ^([^\.]*)/group-(+)-(+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
    rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
    rewrite ^([^\.]*)/blog-(+)-(+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
    rewrite ^([^\.]*)/(fid|tid)-(+)\.html$ $1/index.php?action=$2&value=$3 last;
}

3. **验证配置有效性**
nginx -t# 测试配置文件语法
systemctl restart nginx# 重启nginx服务

4. **排查其他可能性**
- 检查服务器error日志定位具体错误:
tail -f /var/log/nginx/error.log
- 确认PHP-FPM正常运行且监听正确端口
- 检查目录权限(保持755目录/644文件权限)
- 更新程序到最新版本(重要操作前做好备份)

5. **临时验证方法**
暂时关闭伪静态功能:
在DZ后台关闭"URL静态化",测试发帖是否正常。如果正常,则确认为伪静态配置问题。

若问题仍未解决,请提供:
1. nginx配置文件中server区块的完整内容
2. DZ的伪静态设置截图
3. 服务器error日志中相关时间点的错误记录

我们可进一步分析具体配置问题。建议通过DZ插件网获取技术资源时,注意选择适配当前版本的工具包。
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。
页: [1]
查看完整版本: 社区发完贴返回404 Not Found nginx