𝕷𝖎𝖑𝖏𝖆𝖈𝖐 发表于 2024-4-2 21:04:20

docker容器部署的DiscuzX3.5的伪静态如何配置 New

环境:Discuz! X 3.5,OpenResty(Nginx) 1.21,MySQL 8.2
我使用1Panel部署环境,这些都是在docker容器中部署的,
现在伪静态设置中出现了问题,我的处理过程如下:
在“全局 » SEO设置”中勾选开启了所有URL静态化选项,提交。
再到1Panel的伪静态界面中选择discuz3,保存重载,提示异常:
服务内部错误: stderr: 2024/04/02 21:10:03 272#272: duplicate location "/" in /www/sites/www.******.com/rewrite/www.******.com.conf:1 nginx: duplicate location "/" in /www/sites/www.******.com/rewrite/www.******.com.conf:1 nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test failed


查询了些资料,由于nginx已经有“/”的映射在conf中映射到容器内部了,所以无法进行设置,
很多贴子都是介绍如何配置,但是好像没有说明我这种场景该如何配置。
求教大佬指点,谢谢!

我知道答案 回答被采纳将会获得1 贡献 已有0人回答

Discuz智能体 发表于 2025-3-20 01:47:37

在Docker容器中部署的Discuz! X 3.5,使用OpenResty(Nginx)作为Web服务器时,配置伪静态可能会遇到一些问题,特别是当Nginx配置文件中已经存在`location /`的映射时。你遇到的错误提示是`duplicate location "/"`,这意味着在Nginx配置文件中存在重复的`location /`定义。

### 解决方案

1. **检查Nginx配置文件**:
   首先,你需要检查Nginx的配置文件,确保没有重复的`location /`定义。你可以通过以下步骤来检查和修改配置文件:

   - 进入Docker容器:
   docker exec -it <container_id> /bin/bash
   其中`<container_id>`是你的Docker容器ID。

   - 找到Nginx配置文件:
   通常Nginx的配置文件位于`/etc/nginx/nginx.conf`或`/usr/local/nginx/conf/nginx.conf`。你可以使用`cat`或`vi`命令查看和编辑配置文件。

   - 检查`location /`定义:
   确保只有一个`location /`定义。如果有多个,删除多余的`location /`定义。

2. **修改伪静态规则**:
   如果你使用的是1Panel的伪静态界面,并且选择了`discuz3`的伪静态规则,那么你需要确保这些规则不会与现有的`location /`定义冲突。

   - 打开1Panel的伪静态配置界面,找到`discuz3`的伪静态规则。
   - 将这些规则添加到Nginx配置文件的`location /`块中,而不是创建一个新的`location /`块。

   例如:
   location / {
       try_files $uri $uri/ /index.php?$args;
       rewrite ^/forum-(+)-(+)\.html$ /forum.php?mod=forumdisplay&fid=$1&page=$2 last;
       rewrite ^/thread-(+)-(+)-(+)\.html$ /forum.php?mod=viewthread&tid=$1&extra=page%3D$3&page=$2 last;
       rewrite ^/group-(+)-(+)\.html$ /forum.php?mod=group&fid=$1&page=$2 last;
       rewrite ^/space-(username|uid)-(.+)\.html$ /home.php?mod=space&$1=$2 last;
       rewrite ^/blog-(+)-(+)\.html$ /home.php?mod=space&uid=$1&do=blog&id=$2 last;
       rewrite ^/archiver/(fid|tid)-(+)\.html$ /archiver/index.php?action=$1&value=$2 last;
       rewrite ^/forum-(+)-(+)\.html$ /forum.php?mod=forumdisplay&fid=$1&page=$2 last;
       rewrite ^/thread-(+)-(+)-(+)\.html$ /forum.php?mod=viewthread&tid=$1&extra=page%3D$3&page=$2 last;
       rewrite ^/group-(+)-(+)\.html$ /forum.php?mod=group&fid=$1&page=$2 last;
       rewrite ^/space-(username|uid)-(.+)\.html$ /home.php?mod=space&$1=$2 last;
       rewrite ^/blog-(+)-(+)\.html$ /home.php?mod=space&uid=$1&do=blog&id=$2 last;
       rewrite ^/archiver/(fid|tid)-(+)\.html$ /archiver/index.php?action=$1&value=$2 last;
   }

3. **重载Nginx配置**:
   修改完配置文件后,保存并退出编辑器,然后重载Nginx配置:
   nginx -s reload

4. **测试伪静态**:
   完成上述步骤后,访问你的Discuz!站点,检查伪静态是否生效。如果一切正常,URL应该已经变成了静态化的形式。

### 总结

在Docker容器中部署Discuz! X 3.5并配置伪静态时,确保Nginx配置文件中没有重复的`location /`定义,并将伪静态规则正确地添加到现有的`location /`块中。这样可以避免`duplicate location "/"`的错误,并成功实现伪静态化。

如果你在配置过程中遇到其他问题,欢迎继续提问!
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。
页: [1]
查看完整版本: docker容器部署的DiscuzX3.5的伪静态如何配置 New