DokuWiki 搭建使用记录 作者: Hogwarts 发布于: 2025-11-27 更新于: 2026-02-19 分类: 默认分类 #一、搭建的前提 需安装WEB和PHP环境,推荐LCMP。 #二、下载安装 ##2.1 下载到WEB根目录并解压 wget https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz tar -zxvf dokuwiki-stable.tgz mv dokuwiki-stable dokuwiki ##2.2 安装 在浏览器端输入您的域名加install.php,格式为 `https://yourdomain.com/install.php` 填写Wiki名称、管理员和密码等信息。 安装成功后在VPS根目录下删除install.php文件。 #三、使用记录 ##3.1 中文文件名乱码 在网站根目录/conf/local.php最后一行加上: $conf['fnencode']='utf-8'; **特别提醒**:必须第一步做这件事,否则乱码问题可能不能彻底解决。 ##3.2 Web 访问安全问题 管理员登陆后,会有安全提示。能够访问`http://yourserver.com/data/pages/wiki/dokuwiki.txt`页面。对根目录下的 /data/、/conf/、/bin/、/inc/ 和 /vendor/ 目录进行限制。以caddy2为例,在`caddy.conf`文件中加入以下代码。 @forbidden path /data/* /conf/* /bin/* /inc/* /install.php handle @forbidden { respond * 403 } 特别提示:安装时请记住注释掉上面的禁止代码块,安装完成后再取消注释。 参见:`https://www.dokuwiki.org/security#deny_directory_access_in_caddy` `https://www.dokuwiki.org/install:caddy` ##3.3 重写功能 默认情况下,DokuWiki 不会进行URL重写,因此生成的 URL 类似于这样: `http://example.com/doku.php?id=wiki:syntax` ###3.3.1 修改local.php 修改根目录下的 `conf/local.php` 在最后加入 $conf['userewrite'] = '1'; ###3.3.2 修改caddy.conf try_files {path} {path}/index.html route { handle_path /_media/* { rewrite * /lib/exe/fetch.php?media={path}&{query} } handle_path /_detail/* { rewrite * /lib/exe/detail.php?media={path}&{query} } handle /_export/* { @export path_regexp export ^/_export/([^/]+)/(.*) rewrite @export /doku.php?do=export_{re.export.1}&{query}&id={re.export.2} } handle / { rewrite * /doku.php?{query} } try_files {path} /doku.php?id={path}&{query} } 参考:`https://www.dokuwiki.org/rewrite` ###3.3.3 路径重写 打开的网址:`https://Yourdomain.com/wiki/` wiki为dokuwiki文件存放在网站根目录的文件夹名称。 修改根目录下`conf/dokuwiki.php`文件,在文件中加入 $conf ['basedir' ] = '/wiki/'; caddy 文件配置 https://Yourdomain.com { tls /etc/ssl/fullchain.cer /etc/ssl/private.key # 1. 安全过滤:放在最前面 @badbots { header_regexp User-Agent "(?i)censys|shodan|zoomeye|ahrefs|mj12|semrush|dotbot|libwww-perl|nmap|masscan|dirbuster|sqlmap|nikto|wpscan|whatweb|wget|fetch|httpclient|crawler|scrapy|httpx|netcraft|zgrab|nessus|openvas" } handle @badbots { respond "Access for bad crawlers denied" 403 { close } } # 全局头部和日志 header { Strict-Transport-Security "max-age=31536000; preload" X-Content-Type-Options nosniff X-Frame-Options SAMEORIGIN } encode gzip log { output file /var/log/caddy/ssl_access.log { roll_size 100mb roll_keep 3 roll_keep_for 7d } } encode gzip zstd handle_path /wiki* { #在这分流了 root * /data/www/html/wiki #dokuwiki路径 #安装时请记住注释掉下面的禁止访问代码块 @forbidden path /data/* /conf/* /bin/* /inc/* /install.php handle @forbidden { respond * 403 } #禁止访问代码块结束 try_files {path} {path}/index.html route { handle_path /_media/* { rewrite * /lib/exe/fetch.php?media={path}&{query} } handle_path /_detail/* { rewrite * /lib/exe/detail.php?media={path}&{query} } handle /_export/* { @export path_regexp export ^/_export/([^/]+)/(.*) rewrite @export /doku.php?do=export_{re.export.1}&{query}&id={re.export.2} } handle / { rewrite * /doku.php?{query} } try_files {path} /doku.php?id={path}&{query} } php_fastcgi unix//run/php/php-fpm.sock file_server } # 3. 默认主站处理 (排除掉上面已处理的路径) handle { root * /data/www/bi3aax php_fastcgi unix//run/php/php-fpm.sock file_server } } ##3.4 插件 所有的插件在管理后台-扩展管理器中搜索安装。 ###3.4.1 Markdown插件Markdown Page Plugin 让Wiki支持Markdown语法 ###3.4.2 新增页面 Add New Page 插件 ###3.4.3 侧边栏 Indexmenu Plugin 插件 在根目录/data/pages/中新建sidebar.txt,内容如下 {{indexmenu>..|navbar}} #导航目录,树状结构会自动在当前页面命名空间中展开。 {{NEWPAGE}} #添加新页面 这个目录里保存的所有主页面的txt文件,不想要哪个直接删除即可。比如wiki文件夹。 Indexmenu Plugin 具体使用方法见:`https://www.dokuwiki.org/plugin:indexmenu` 其它侧边栏插件:simplenavi plugin,同样需新建sidebar.txt,并写入内容如下 {{simplenavi>}} {{NEWPAGE}} ###3.4.4 PDF.js 插件 基本用法 {{pdfjs>:ns:document.pdf}} 定义高度: {{pdfjs 200px > :ns:document.pdf}} 定义宽度和高度: {{pdfjs 200em,400px> :ns:document.pdf}} 定义默认缩放级别: {{pdfjs> :ns:document.pdf?125}} 配置中 hide_download_button 选项会隐藏 pdf 查看器中的下载按钮,但仍然可以通过CTRL+S保存 参考:`https://www.dokuwiki.org/plugin:pdfjs` ###3.4.5 Move Plugin 插件 让Wiki支持重命名页面和迁移命名空间。 ###3.4.6 ImgPaste Plugin 插件 让Wiki支持在Chrome浏览器下,支持通过编辑器内Ctrl+V,实现图片资源上传 ###3.4.7 copy2clipboard Plugin 插件 一键复制代码插件 `https://www.dokuwiki.org/plugin:copy2clipboard` ###3.4.8 tplmod Plugin 可以隐藏“媒体管理”和“搜索”选项的插件 ###3.4.9 color Plugin 文字前景色背景色插件。 text text text text text text  参考:`https://www.dokuwiki.org/plugin:color` ###3.4.10 SMTP Plugin 插件 配置 SMTP 邮件服务器 ##3.5 Bootstrap3 主题 `https://www.dokuwiki.org/template:bootstrap3` ##3.6 更换Logo 默认主题的Logo存放地址为:`网站根目录/lib/tpl/dokuwiki/images/` Bootstrap3 主题的Logo存放地址为:`网站根目录/lib/tpl/Bootstrap3/images/` 首先将images文件夹做备份。 替换apple-touch-icon.png、logo.png、favicon.ico、dokuwiki.svg这四个文件。文件大小参照原文件。 ##3.7 DokuWiki 格式语法 参考:`https://www.dokuwiki.org/zh:wiki:syntax` #四、未解决的问题 ## 侧边栏目录顺序 侧边栏目录顺序自动排列,先写入的在最下面,只能用“序号+目录内容”命名自定义排序。Move Plugin插件只能解决移动和重命名问题,此问题无法解决。还未找到解决方案。 标签: DokuWiki