本 Wiki 开启了 HTTPS。但由于同 IP 的 Blog 也开启了 HTTPS,因此本站必须要支持 SNI 的浏览器才能浏览。为了兼容一部分浏览器,本站保留了 HTTP 作为兼容。如果您的浏览器支持 SNI,请尽量通过 HTTPS 访问本站,谢谢!
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录前一修订版后一修订版 | 前一修订版 | ||
other:website:misc [2022/06/24 11:46] – 移除 codinghare | other:website:misc [2024/02/04 16:17] (当前版本) – [Disqus loading on scroll] codinghare | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ======常见运维问题===== | ||
+ | 一些个人网站环境配置及常见问题记录。 | ||
+ | ---- | ||
+ | |||
+ | ====AMH==== | ||
+ | References: | ||
+ | * [[https:// | ||
+ | ===AMH 查看默认密码=== | ||
+ | 使用以下命令则可以查看: | ||
+ | <code bash> | ||
+ | cat / | ||
+ | </ | ||
+ | |||
+ | ===MySQL无法自动启动=== | ||
+ | |||
+ | MYSQL 在重启服务器时不能启动,尝试以下方法: | ||
+ | \\ | ||
+ | \\ | ||
+ | 删除 '' | ||
+ | |||
+ | <code bash> | ||
+ | cd /etc/ | ||
+ | rm my.inf | ||
+ | </ | ||
+ | ==PID file not found== | ||
+ | <code bash> | ||
+ | #error msg | ||
+ | ERROR! MySQL server PID file could not be found! | ||
+ | </ | ||
+ | 这种情况多半是硬盘空间满了导致系统强制结束了 mysql 的进程。用下面的命令之后再重启一下 mysql 进系统看看。 | ||
+ | <code bash> | ||
+ | rm -f / | ||
+ | </ | ||
+ | |||
+ | ===SSL 配置=== | ||
+ | ==SSL多虚拟主机== | ||
+ | 单IP的多个虚拟主机只需要一个 SSL证书即可。配置步骤: | ||
+ | - 在 '' | ||
+ | - 将得到的证书在 '' | ||
+ | - 制定自动更新的策略。 | ||
+ | ====Dokuwiki==== | ||
+ | Rreferences: | ||
+ | * [[https:// | ||
+ | |||
+ | ===Dokuwiki Nginx Rewrite 规则=== | ||
+ | |||
+ | 将下列规则添加到 AMH 的 '' | ||
+ | |||
+ | <code nginx> | ||
+ | location / { | ||
+ | index doku.php; | ||
+ | try_files $uri $uri/ @dokuwiki; | ||
+ | } | ||
+ | |||
+ | #caching: warning: will cause picture 404 problem if your wiki is running in rewrite mode 1. | ||
+ | location ~ ^/ | ||
+ | expires 30d; | ||
+ | } | ||
+ | |||
+ | #dir safety | ||
+ | location ^~ /conf/ { return 403; } | ||
+ | location ^~ /data/ { return 403; } | ||
+ | |||
+ | #rewrite | ||
+ | Location @dokuwiki { | ||
+ | # rewrites " | ||
+ | rewrite ^/ | ||
+ | rewrite ^/ | ||
+ | rewrite ^/ | ||
+ | rewrite ^/(.*) / | ||
+ | } | ||
+ | </ | ||
+ | ==Dokuwiki 重写后图片显示不正常(Nginx& | ||
+ | Dokuwiki URL Rewrite 与以下代码冲突: | ||
+ | <code nginx> | ||
+ | location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$ { | ||
+ | expires | ||
+ | } | ||
+ | </ | ||
+ | 而 AMH 的 '' | ||
+ | |||
+ | ===Dokuwiki Nginx 安全规则=== | ||
+ | |||
+ | 该段代码用于防止除 '' | ||
+ | \\ | ||
+ | 使用:添加以下代码到 '' | ||
+ | <code nginx> | ||
+ | # Block access to data folders | ||
+ | location ~ / | ||
+ | deny all; | ||
+ | } | ||
+ | # Block access to .htaccess files | ||
+ | location ~ /\.ht { | ||
+ | deny all; | ||
+ | } | ||
+ | </ | ||
+ | ===所有 MIMe 类型=== | ||
+ | [[https:// | ||
+ | ===Dokuwiki 使用=== | ||
+ | |||
+ | * 插件的安装:直接到后台的插件管理器中寻找指定的插件下载安装即可。 | ||
+ | |||
+ | ==常用插件== | ||
+ | |||
+ | * Add New Page:可以直接在没有创建页面的位置直接创建页面,非常方便。 | ||
+ | * Code Prettifier:非常好用的代码高亮。 | ||
+ | * Edittable :图形化界面的表格创建,比较方便,但有自适应问题。 | ||
+ | * Fastwiki :优化 Dokuwiki 的访问速度(预加载)。 | ||
+ | * Google Document Viewer :可以直接在 Dokuwiki 中查看 Google 文档。 | ||
+ | * MathJax :数学公式插件。 | ||
+ | * Pure SVG Insert:使 Dokuwiki 支持 SVG 的显示。 | ||
+ | * DokuWiki Upgrade:一键升级 Dokuwiki,必备插件。 | ||
+ | * Wrap:很好用的内容排版插件。 | ||
+ | ===Dokuwiki 相关问题=== | ||
+ | ==Dokuwiki 上传附件显示 " | ||
+ | 解决方法:进入服务器的 '' | ||
+ | <code php> | ||
+ | always_populate_raw_post_data = -1 | ||
+ | </ | ||
+ | ==Igor 版本 svg 缩放不正确== | ||
+ | <WRAP center round important 100%> | ||
+ | 官方 issue 中解释该设置是一个 guard,不应修改。推荐对指定插件进行修改。 | ||
+ | </ | ||
+ | 将 ''/ | ||
+ | <code css> | ||
+ | width: 1.2em; | ||
+ | </ | ||
+ | 替换为 | ||
+ | <code css> | ||
+ | width: auto; | ||
+ | </ | ||
+ | |||
+ | ====服务器通用前端优化==== | ||
+ | |||
+ | ===Leverage browser caching=== | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | 解决方法:使用新版本的重写规则,请参见前面。 | ||
+ | </ | ||
+ | |||
+ | |||
+ | \\ | ||
+ | \\ | ||
+ | **Nginx** 版本的通用优化代码如下: | ||
+ | <code nginx> | ||
+ | location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { | ||
+ | expires 365d; | ||
+ | } | ||
+ | |||
+ | location ~* \.(pdf)$ { | ||
+ | expires 30d; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ====Typecho==== | ||
+ | |||
+ | 一些 Typecho 的改造 / 使用 问题收集。 | ||
+ | ===后台 Access Denied=== | ||
+ | |||
+ | 在 AMH 中开启 '' | ||
+ | |||
+ | ===Typecho 改造指南=== | ||
+ | |||
+ | ==评论:添加额外样式给管理员== | ||
+ | Typecho 可以针对当前用户是否是管理员来添加额外的样式。一个简单的应用例子如下: | ||
+ | \\ | ||
+ | \\ | ||
+ | 首先我们需要官方帮助文档中的自定义函数。该函数用于判断当前评论用户是否为管理员,通过 '' | ||
+ | <code php> | ||
+ | <?php function threadedComments($comments, | ||
+ | $commentClass = ''; | ||
+ | if ($comments-> | ||
+ | if ($comments-> | ||
+ | $commentClass .= ' comment-by-author'; | ||
+ | } else { | ||
+ | $commentClass .= ' comment-by-user'; | ||
+ | } | ||
+ | } | ||
+ | $commentLevelClass = $comments-> | ||
+ | ?> | ||
+ | /* 自定义评论的代码结构 */ | ||
+ | <?php } ?> | ||
+ | </ | ||
+ | \\ | ||
+ | 接下来会通过一段函数将增加的样式表打印出来,结果是 '' | ||
+ | <code php> | ||
+ | <li id=" | ||
+ | if ($comments-> | ||
+ | echo ' comment-child'; | ||
+ | $comments-> | ||
+ | } else { | ||
+ | echo ' comment-parent'; | ||
+ | } | ||
+ | $comments-> | ||
+ | echo $commentClass; | ||
+ | ?>"> | ||
+ | </ | ||
+ | \\ | ||
+ | 有了这两段函数以后,剩下的工作就很简单了。以我要替换管理员在评论中名字的背景为例。首先将打印出来的字段应用到 HTML 的调用中: | ||
+ | <code php> | ||
+ | <span class=" | ||
+ | </ | ||
+ | |||
+ | 上面的代码直接把 '' | ||
+ | \\ | ||
+ | \\ | ||
+ | 最后去 CSS 里添加样式表即可: | ||
+ | |||
+ | <code css> | ||
+ | .comment-author.comment-by-author {background: | ||
+ | </ | ||
+ | ==评论:重写发表评论时间== | ||
+ | Typecho 默认的时间输出格式是 PHP 的格式。如果我们希望将其转换为“发表于多久多久之前” 的格式,可以通过以下的手段来实现: | ||
+ | \\ | ||
+ | \\ | ||
+ | 首先我们需要往 '' | ||
+ | <code php> | ||
+ | // | ||
+ | function timesince($older_date, | ||
+ | $chunks = array( | ||
+ | array(86400 , ' | ||
+ | array(3600 , ' | ||
+ | array(60 , ' | ||
+ | array(1 , ' | ||
+ | ); | ||
+ | $newer_date = time(); | ||
+ | $since = abs($newer_date - $older_date); | ||
+ | |||
+ | for ($i = 0, $j = count($chunks); | ||
+ | $seconds = $chunks[$i][0]; | ||
+ | $name = $chunks[$i][1]; | ||
+ | if (($count = floor($since / $seconds)) != 0) break; | ||
+ | } | ||
+ | / | ||
+ | if ($count == 1) { | ||
+ | $output = $count.' | ||
+ | } | ||
+ | else {$output = $count.' | ||
+ | return $output; | ||
+ | } | ||
+ | </ | ||
+ | 这个函数会获取以前的时间作为参数,并转换成相应的字段,我们只需要拿到 '' | ||
+ | <code php> | ||
+ | <?php echo timesince($comments-> | ||
+ | </ | ||
+ | ==评论:回复评论自带@跳转== | ||
+ | 首先到 '' | ||
+ | <code php> | ||
+ | // | ||
+ | function get_comment_at($coid) | ||
+ | { | ||
+ | $db = Typecho_Db:: | ||
+ | $prow = $db-> | ||
+ | | ||
+ | $parent = $prow[' | ||
+ | if ($parent != " | ||
+ | $arow = $db-> | ||
+ | | ||
+ | $author = $arow[' | ||
+ | $href = '<a href="# | ||
+ | echo $href; | ||
+ | } else { | ||
+ | echo ''; | ||
+ | } | ||
+ | } | ||
+ | // | ||
+ | function get_filtered_comment($coid){ | ||
+ | $db = Typecho_Db:: | ||
+ | $rs=$db-> | ||
+ | | ||
+ | $content=$rs[' | ||
+ | echo $content; | ||
+ | } | ||
+ | ?> | ||
+ | </ | ||
+ | \\ | ||
+ | 再到 '' | ||
+ | <code linenums: | ||
+ | <?php get_comment_at($comments-> | ||
+ | </ | ||
+ | ==添加自定义html标签到文章内容== | ||
+ | 找到文件夹 ''/ | ||
+ | ===Typecho 升级指南=== | ||
+ | |||
+ | //Typecho// 可以通过以下方式来进行升级: | ||
+ | |||
+ | - 下载最新的版本:[[https:// | ||
+ | - 删除服务器上三个目录的文件,如果修改了源代码可以使用 //Github// 的对比工具来进行合并。三个目录分别是:''/ | ||
+ | - 上传最新的对应文件即可。 | ||
+ | |||
+ | ===Typecho URL重写=== | ||
+ | |||
+ | ==Apache 重写规则== | ||
+ | 添加如下代码到 '' | ||
+ | <code apache> | ||
+ | < | ||
+ | RewriteEngine On | ||
+ | RewriteBase / | ||
+ | RewriteCond %{REQUEST_FILENAME} !-f | ||
+ | RewriteCond %{REQUEST_FILENAME} !-d | ||
+ | RewriteRule ^(.*)$ index.php [L, | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===InstantClick=== | ||
+ | |||
+ | '' | ||
+ | |||
+ | ==安装InstantClick== | ||
+ | |||
+ | 下载 [[http:// | ||
+ | \\ | ||
+ | \\ | ||
+ | 在 '' | ||
+ | <code js> | ||
+ | ... | ||
+ | <script src=" | ||
+ | <script data-no-instant> | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==点击时候的预加载== | ||
+ | |||
+ | 默认情况下是在鼠标悬停到链接上方即开始加载,有时候这样会带来服务器的额外开销问题。将 '' | ||
+ | < | ||
+ | InstantClick.init(' | ||
+ | </ | ||
+ | |||
+ | ==修改预加载条的颜色== | ||
+ | |||
+ | 在样式表中加入如下代码即可: | ||
+ | <code css> | ||
+ | # | ||
+ | </ | ||
+ | |||
+ | ==与 PrismJS兼容== | ||
+ | |||
+ | 先对 '' | ||
+ | \\ | ||
+ | \\ | ||
+ | 打开 '' | ||
+ | <code html js> | ||
+ | < | ||
+ | </ | ||
+ | 改为: | ||
+ | <code html> | ||
+ | <script data-no-instant> | ||
+ | </ | ||
+ | 找到 '' | ||
+ | <code html> | ||
+ | <script src="' | ||
+ | </ | ||
+ | 改为: | ||
+ | <code html> | ||
+ | <script src="' | ||
+ | </ | ||
+ | 找到 '' | ||
+ | <code html> | ||
+ | <script defer=" | ||
+ | </ | ||
+ | 改为: | ||
+ | <code html js> | ||
+ | <script defer=" | ||
+ | </ | ||
+ | \\ | ||
+ | 再修改位于 '' | ||
+ | <code js> | ||
+ | if (typeof Prism !== ' | ||
+ | var pres = document.getElementsByTagName(' | ||
+ | for (var i = 0; i < pres.length; | ||
+ | if (pres[i].getElementsByTagName(' | ||
+ | pres[i].className | ||
+ | Prism.highlightAll(true, | ||
+ | </ | ||
+ | PHP 部分: | ||
+ | <code php> | ||
+ | {<? | ||
+ | </ | ||
+ | 对判断插件是否使用了行号。如果没启用插件,会导致网站 **505** 错误。 | ||
+ | \\ | ||
+ | \\ | ||
+ | 如果不使用行号,直接使用以下代码: | ||
+ | <code php> | ||
+ | if (typeof Prism !== ' | ||
+ | </ | ||
+ | |||
+ | ===Mathjax=== | ||
+ | ==mathjax 3 简单配置== | ||
+ | <code js> | ||
+ | MathJax = { | ||
+ | showProcessingMessages: | ||
+ | messageStyle: | ||
+ | tex: { | ||
+ | inlineMath: [ [" | ||
+ | displayMath: | ||
+ | processEscapes: | ||
+ | }, | ||
+ | svg: { | ||
+ | fontCache: " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | ==igor 版本的缩放问题== | ||
+ | 添加以下代码到 ''/ | ||
+ | <code cpp> | ||
+ | mjx-container[jax=" | ||
+ | height: auto; | ||
+ | width: auto; | ||
+ | } | ||
+ | </ | ||
+ | ==Mathjax与InstantClick不兼容== | ||
+ | |||
+ | 在 '' | ||
+ | < | ||
+ | if (typeof MathJax !== ' | ||
+ | </ | ||
+ | ==Mathjax的直接添加== | ||
+ | |||
+ | 在 '' | ||
+ | <code html> | ||
+ | <script type=" | ||
+ | MathJax.Hub.Config({ | ||
+ | extensions: [" | ||
+ | jax: [" | ||
+ | tex2jax: { | ||
+ | inlineMath: [ [' | ||
+ | displayMath: | ||
+ | processEscapes: | ||
+ | }, | ||
+ | | ||
+ | " | ||
+ | }); | ||
+ | </ | ||
+ | <script type=" | ||
+ | | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP center round info 100%> | ||
+ | 近日 //MathJax// 自营 CDN 已经停止服务,需自行寻找相关 CDN。 | ||
+ | </ | ||
+ | \\ | ||
+ | ==Mathjax按需加载== | ||
+ | 首先在 '' | ||
+ | <code php> | ||
+ | <?php $GLOBALS[' | ||
+ | </ | ||
+ | 接着到 Mathjax.js 调用的地方设置条件(我的是'' | ||
+ | <code php> | ||
+ | <?php if($GLOBALS[' | ||
+ | < | ||
+ | <script type=" | ||
+ | <?php endif;?> | ||
+ | </ | ||
+ | |||
+ | ==Mathjax不显示加载信息== | ||
+ | 在 '' | ||
+ | <code js> | ||
+ | showProcessingMessages: | ||
+ | messageStyle: | ||
+ | </ | ||
+ | |||
+ | ===Disqus=== | ||
+ | |||
+ | ==Disqus loading on scroll== | ||
+ | |||
+ | < | ||
+ | \\ | ||
+ | <WRAP round tip 60%> | ||
+ | 新版本不再使用 jquery。 | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | \\ | ||
+ | 在 '' | ||
+ | <code js> | ||
+ | < | ||
+ | var disqus_loaded = false; | ||
+ | |||
+ | function load_disqus() | ||
+ | { | ||
+ | disqus_loaded = true; | ||
+ | var dsq = document.createElement(' | ||
+ | dsq.src = " | ||
+ | (document.getElementsByTagName(' | ||
+ | } | ||
+ | |||
+ | window.onscroll = function(e) { | ||
+ | if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) { | ||
+ | //hit bottom of page | ||
+ | if (disqus_loaded==false){ load_disqus() }; | ||
+ | } | ||
+ | }; | ||
+ | </ | ||
+ | </ | ||
+ | \\ | ||
+ | 注意替换 '' | ||
+ | \\ | ||
+ | \\ | ||
+ | html 调用: | ||
+ | <code html> | ||
+ | <div id=" | ||
+ | </ | ||
+ | |||
+ | ====Flarum==== | ||
+ | ===解决 nginx 重写的问题=== | ||
+ | Flarum 自己带一个子目录 '' | ||
+ | - 绑定 '' | ||
+ | - 绑定 domain.com 到子域主机 | ||
+ | - 绑定子目录中填写 ''/ | ||
+ | - 在子主机中包含 '' | ||
+ | |||
+ | ===Flarum 目录权限=== | ||
+ | <code bash> | ||
+ | $chown www:www -R / | ||
+ | </ | ||
+ | ===InnodB=== | ||
+ | 如果遇到以下的错误: | ||
+ | >flarum Something went wrong: SQLSTATE[42000]: | ||
+ | 需要到 '' | ||
+ | ===https 403=== | ||
+ | 如果出现 http 访问正常 而 https 访问 403 的情况,需要到 '' | ||
+ | <code cpp> | ||
+ | //default | ||
+ | http:// | ||
+ | //change to | ||
+ | https:// | ||
+ | </ | ||