分类: Debug

  • ERR_HTTP2_PROTOCOL_ERROR 等错误Debug

    ERR_HTTP2_PROTOCOL_ERROR 等错误Debug

    ERR_HTTP2_PROTOCOL_ERROR 等错误Debug

    网站配置CDN和COS后,频现ERR_HTTP2_PROTOCOL_ERROR错误,而且网络访问极不稳定且速度慢,丝毫没有体现出服务器挪回国内并且开启CDN和COS的作用。

    网上查了很多文档,最终从以下三个方面入手解决了问题。

    域名证书

    个人博客网站如果配置多域名证书或通配符证书过于奢侈,一年证书的费用甚至相当于服务器和域名3到5年的成本。而在使用免费域名证书的过程中,只能申请到单域名证书,这样在配置CDN和COS过程中往往会遇到一些证书错误的问题。

    今日突发奇想,我网站用的是blog.guohao.asia/这个顶级域名,在申请免费SSL证书的过程中,SSL证书同时包含了blog.guohao.asia/;www.guohao.asia,这样一来,不就相当于这张免费的SSL证书变成了包含主域名和WWW二级域名的“多域名”证书了么?!

    于是在腾讯云CDN控制台,复制原cdn.guohao.asia的配置信息到www.guohao.asia,在wordpress后台的插件中重新配置CDN域名信息。

    自此,网站上的CDN源显示恢复正常。

    CDN-HTTP响应头配置

    image-20220930145017139

    关闭CDN Access-Control-Allow-Origin “HTTP响应头配置”。

    可能的原因是:

    • Access-Control-Allow-Origin 是用来设置接口跨域访问的.设置为*表示接受任何域的请求.
    • 根据W3C标准,如果支持用户凭证,设置Access-Control-Allow-Origin为当前域,并且设置Access-Control-Allow-Credentials为true;
    • 否则当设置Access-Control-Allow-Origin为*时,是不允许设置Access-Control-Allow-Credentials为true的.

    CDN-QUIC

    image-20220930145445481

    在CDN控制台中开启QUIC,并填写网站域名。


    刷新CDN节点缓存及本地缓存后网站访问恢复正常。

  • NextCloud性能优化及维护

    NextCloud性能优化及维护

    NextCloud性能优化

    后台任务

    image-20220915140526069

    crontab -u www -e

    */5 * * * * php -f /PathToNextcloud/cron.php

    设置cron.php每5分钟运行一次,cron.php的具体路径在nextcloud安装的根目录下。

    cron.php应该被www用户执行。

    另外,宝塔面板用户也可以通过面板上的“计划任务”来执行cron.php,如:

    image-20220915164120009

    PHP configuration option output_buffering must be disabled

    注释掉php.ini中的; output_buffering = 4096

    image-20220915143527113

    缓存配置

    /config/config.php中添加如下代码:

      'memcache.local' => 'OC\\Memcache\\APCu',        #Memcached
    
      'memcache.distributed' => 'OC\\Memcache\\Memcached',
    
      'redis' => [        #Redis
    
          'host' => 'localhost', #Redis 服务器
    
          'port' => 6379,     #Redis 端口
    
          'timeout' => 0.0,       #Redis 超时设定
    
          'password' => '########',       #Redis 密码
    
          'dbindex' => 1,     #Redis 数据库选择
    
      ],
    
      'memcached_servers' => array(        #Memcached 服务器
    
          array('localhost', 11211),
    
      ),
    
      'memcached_options' => array(        #Memcached 选项
    
          \Memcached::OPT_CONNECT_TIMEOUT => 50,
    
          \Memcached::OPT_RETRY_TIMEOUT =>   50,
    
          \Memcached::OPT_SEND_TIMEOUT =>    50,
    
          \Memcached::OPT_RECV_TIMEOUT =>    50,
    
          \Memcached::OPT_POLL_TIMEOUT =>    50,
    
          \Memcached::OPT_COMPRESSION =>          true,
    
          \Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
    
          \Memcached::OPT_BINARY_PROTOCOL =>      true,
    
      ),
    
      'cache_path' => '/www/wwwroot/nextcloud/cache',        #缓存目录
    
      'cache_chunk_gc_ttl' => 60*60*24,        #缓存删除时间

    代码中有些内容需要根据具体情况进行修改替换。建议添加在最后,Nextcloud搭配了COS之类的,建议放在COS配置之前。

    PHP 的 OPcache 模块未载入。推荐开启获得更好的性能。 PHP OPcache 模块没有正确配置。

    安装OPcache,在php.ini中加入如下内容:

    opcache.enable=1
    opcache.enable_cli=1
    opcache.interned_strings_buffer=32
    opcache.max_accelerated_files=80000
    opcache.memory_consumption=128
    opcache.save_comments=1
    opcache.revalidate_freq=3

    特别注意的是,如果使用宝塔面板,最好在最后一行结束后用回车换行,否则宝塔还会接着最后一行的最后一个字符添加其他内容。

    “Strict-Transport-Security” HTTP 头未设为至少 “15552000” 秒。为了提高安全性,建议启用 HSTS

    apache的配置文件中加入:

    <IfModule mod_headers.c>
          Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
    </IfModule>

    一些文件未通过完整性检查。有关如何解决这一问题的进一步信息可在 文档中找到。(无效文件列表… / 重新扫描…)

    点开无效文件列表:

    Technical information
    =====================
    The following list covers which files have failed the integrity check. Please read
    the previous linked documentation to learn more about the errors and how to fix
    them.
    
    Results
    =======
    - core
     - FILE_MISSING
      - .user.ini
     - EXTRA_FILE
      - .well-known/acme-challenge/dNIrvBYgSweGs1H0NW2rAMZOp0xKOKJgOdeqzJdJt9g
    
    Raw output
    ==========
    Array
    (
        [core] => Array
            (
                [FILE_MISSING] => Array
                    (
                        [.user.ini] => Array
                            (
                                [expected] => 4843b3217e91f8536cb9b52700efb20300290292cf6286f92794d4cec99df286afeb7dd6c91b1be20bc55eda541eef230a5c5e7dcd46c189edd0ed1e80c6d3f5
                                [current] => 
                            )
    
                    )
    
                [EXTRA_FILE] => Array
                    (
                        [.well-known/acme-challenge/dNIrvBYgSweGs1H0NW2rAMZOp0xKOKJgOdeqzJdJt9g] => Array
                            (
                                [expected] => 
                                [current] => c5ba196825088a37caca22449c2548cf59df02f166fdfc973652b6ce886f84259f2ce6349860a9a8874648207ff37f372ff87a4f08153737dcc5d3deaa61672e
                            )
    
                    )
    
            )
    
    )

    可以看到是.user.ini文件不存在,好在这个文件是用来放跨站的配置文件,在宝塔面板里直接开启放跨站就好,或者创建文件后写入open_basedir=/PathToNextcloud/:/tmp/,其中/PathToNextcloud/是Nextcloud的安装目录;

    而另外一个文件是多余的,直接删掉(这个文件是申请SSL证书时自动生成的)。

    完整config.php设置

    <?php
    $CONFIG = array (
      'instanceid' => 'xxxxxxxxxxx',
      'passwordsalt' => 'xxxxxxxxxxxxxxxxxx',
      'secret' => 'TNFR/+xxxxxxxxxxxxxxxxxxx/',
      'trusted_domains' => 
      array (
        0 => 'nextcloud.guohao.asia',
      ),
      'datadirectory' => '/www/wwwroot/nextcloud/data',
      'dbtype' => 'mysql',
      'version' => '24.0.5.1',
      'overwrite.cli.url' => 'https://nextcloud.guohao.asia',
      'dbname' => 'xxxxxxxxxxxx',
      'dbhost' => 'localhost',
      'dbport' => '',
      'dbtableprefix' => 'oc_',
      'mysql.utf8mb4' => true,
      'dbuser' => 'xxxxxxxxxx',
      'dbpassword' => 'xxxxxxxxx',
      'installed' => true,
      'app_install_overwrite' => 
      array (
        0 => 'tencentcloudcosconfig',
        1 => 'files_external_onedrive',
      ),  
    
    #缓存设置 
      'memcache.local' => 'OC\\Memcache\\Redis',        
      'memcache.distributed' => 'OC\\Memcache\\Memcached',
      'redis' => [        #Redis
          'host' => 'localhost', #Redis 服务器
          'port' => 6379,     #Redis 端口
          'timeout' => 0.0,       #Redis 超时设定
          'password' => 'XXXXXXXXXXX',        #Redis 密码
          'dbindex' => 1,     #Redis 数据库选择
      ],
      'memcached_servers' => array(        #Memcached 服务器
          array('localhost', 11211),
      ),
      'memcached_options' => array(        #Memcached 选项
          \Memcached::OPT_CONNECT_TIMEOUT => 50,
          \Memcached::OPT_RETRY_TIMEOUT =>   50,
          \Memcached::OPT_SEND_TIMEOUT =>    50,
          \Memcached::OPT_RECV_TIMEOUT =>    50,
          \Memcached::OPT_POLL_TIMEOUT =>    50,
          \Memcached::OPT_COMPRESSION =>          true,
          \Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
          \Memcached::OPT_BINARY_PROTOCOL =>      true,
      ),
    
      'cache_path' => '/www/wwwroot/nextcloud/cache',        #缓存目录
      'cache_chunk_gc_ttl' => 60*60*24,        #缓存删除时间
    
    #腾讯云COS  
      'objectstore' => 
      array (
        'class' => '\\OC\\Files\\ObjectStore\\S3',
        'arguments' => 
        array (
          'key' => 'XXXXXXXXXXXXXXXXXXXXXXXX',
          'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXX',
          'bucket' => 'nextcloud-000000000',
          'hostname' => 'cos.ap-beijing.myqcloud.com',
          'use_ssl' => true,
          'autocreate' => false,
        ),
      ),
    
      #电话区号
      'default_phone_region' => 'CN',
    );

    解决nextcloud无法更新应用

    在==config.php==中添加如下内容:

     'appstoreenabled' => true,
     'appstoreurl' => 'https://www.orcy.net/ncapps/v1/',

    更换为国内源(更新进度较官方略慢)

    由“维护模式”改出

    在nextcloud根目录下执行sudo -u www php occ maintenance:mode --off

  • 再次安装Moodle

    再次安装Moodle

    再次安装Moodle

    Deprecated: Return type of moodle_recordset::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/wwwroot/exercise.ink/moodle/lib/dml/moodle_recordset.php on line 61
    Fatal error: Type of xml_format_exception::$line must be int (as in class Exception) in /www/wwwroot/exercise.ink/moodle/lib/xmlize.php on line 42

    在官方社区中找到一个相同错误的内容:Installing and upgrading help.Deprecated error in 3.11 with latest Apache install

    That particular issue is MDL-73424 (part of the ongoing PHP8.1 epic at MDL-73016)

    Solution is to not use those versions of PHP, and stick to supported versions only

    跟帖回复提到Moodle在PHP8.1版本中会遇到问题,只能降到PHP7.4下使用。

    好在用的是宝塔面板,安装和切换PHP版本都很方便。

    切换PHP7.4后问题解决。

    但这应该不是终结,依稀记得Moodle对服务器和数据库有着各种各样的要求。

    果然,还是遇到了每次都会复现的问题——无法建立moodledata文件夹:image-20220908154206332

    不过好在这并不是一个难以解决的问题,程序无法建立这个文件夹,就手动创建一个,并且权限修改为777

    宝塔面板还有在这里把放跨站攻击关掉。

    之后,面临下一个问题安装PHP cURL并手动上传语言包。

    接下来,连接数据库:

    正式安装:image-20220908160629179

    遇到了意料之中的几个问题:

    1. 数据库版本过低;
    2. 缺少fileinfo扩展

    这两个是主要问题,如果不解决掉Moodle是无法顺利安装下去的。

    其他一些小问题也要一起解决,否则也会影响运行效率。

    不过这个主机上升级数据库略繁琐,今天先到这。

  • 信呼OA移动端考勤定位打卡报错

    信呼OA移动端考勤定位打卡报错

    信呼OA移动端考勤定位打卡报错

    在调试移动端考勤定位打卡功能时报错:

    Fatal error: Uncaught Error: Call to undefined method weixinClassAction::xssrepstr() in /www/wwwroot/oa/webmain/task/api/weixinAction.php:48 Stack trace: #0 /www/wwwroot/oa/include/View.php(42): weixinClassAction->addlocationAction() #1 /www/wwwroot/oa/api.php(39): include_once('/www/wwwroot/oa...') #2 {main} thrown in /www/wwwroot/oa/webmain/task/api/weixinAction.php on line 48

    在移动端app、企业微信内置浏览器、第三方浏览器中该问题复现。

    将PHP版本由php7.0降级到php5.6后报错变成:

    Fatal error: Call to undefined method weixinClassAction::xssrepstr() in /www/wwwroot/oa/webmain/task/api/weixinAction.php on line 48

    xssrepstr应该是一个通常被用于特殊字符过滤的自定义函数^1^:

    /* 特殊字符过滤 */
        public function xssrepstr($str)
        {
            $xpd  = explode(',','(,), ,<,&gt;,\\,.,*,&amp;,%,$,^,!,@,#,-,+,:,;\'');
            $xpds = array();
            foreach($xpd as $xpd1)$xpds[]='';
            $str = str_replace(',', '',$str);
            return str_ireplace($xpd, $xpds, $str);
        }

    在一篇发表于2021年8月26日的题为《通读审计之信呼OA》的文章中,也以及了xssrepstr


    以上问题,在v2.3.9版本中修正,现定位打卡功能已可正常使用。

  • 优化日志

    优化日志

    优化日志

    • 优化缓存功能——20220827;
    • 优化评论功能,解决部分手机浏览器无法发布评论的问题——20220827;
    • 优化首页部分背景图片,压缩并改为本地存储——20220827;
    • 启用腾讯云CDN——20220831;
    • 删除部分无用插件——20220831;
    • 通过自定义插件向functions.php添加函数——20220902
      • 实现主题升级或更换主题时functions.php内自定义代码不丢失
      • 实现个人说明部分支持HTML代码
    <?php
    /* 
    Plugin Name: 模版函数扩展插件
    Description: 给主题模版函数库“functions.php”文件里添加功能,避免因主题升级或更换主题造成对functions.php文件的代码修改丢失 
    Author: <a href="https://blog.guohao.asia/" >NULL</a>
    */
    // Disables Kses only for textarea saves
    foreach (array('pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description') as $filter) {
      remove_filter($filter, 'wp_filter_kses');
     }
    
        // Disables Kses only for textarea admin displays
    foreach (array('term_description', 'link_description', 'link_notes', 'user_description') as $filter) {
    remove_filter($filter, 'wp_kses_data');
    }
    ?>
    • 替换前端字体-20220903
    *:not([class*="icon"]):not(i) {
    font-family: Segoe UI, "Microsoft Yahei" !important;
    }
    • 修改首页元素显示条件,提升PC端及移动端显示效果-20220903
    • 通过自定义插件向functions.php添加函数,解除大尺寸图片上传限制——20220905
    //禁用WordPress大图片(2560大小)裁剪功能
    add_filter( 'big_image_size_threshold', '__return_false' );
    • 替换代码高亮为highlight.js-20220912
    <link rel="stylesheet" href="/wp-content/highlight/styles/base16/onedark.min.css">		<!--引入代码深色背景-->
    <script src="/wp-content/highlight/highlight.min.js"></script>							<!--引入代码高亮js-->
    <script src="/wp-content/highlight/highlightjs-line-numbers/dist/highlightjs-line-numbers.min.js"></script>			<!--引入添加行号js-->
    <script>
    	hljs.initHighlightingOnLoad();
    	hljs.initLineNumbersOnLoad();
    </script>
    • 增加首行缩进
    //WordPress 文章首行缩进
    function Bing_paragraph_indentation( $content ){
        return str_replace( '<p', '<p style="text-indent:2em;"', $content );
    }
    add_filter( 'the_content', 'Bing_paragraph_indentation' );
AI 助手