分类 默认分类 下的文章

背景减少MySQL的IO,实现访问加速
第一步安装Redis及其相关驱动
sudo apt-get install redis
sudo apt-get install php-redis
第二步,安装插件
将文件夹重命名为TpCache。再拷贝至usr/plugins/下
https://github.com/phpgao/TpCache
第三步,重启
sudo service apache2 restart
设置插件
需要缓存的页面:全选除Feed
是否对已登录用户失效:开启
是否支持SSL:根据实际情况选择
缓存驱动:Redis
缓存过期时间:86400
主机地址:127.0.0.1
端口号:6379
是否开启debug:关闭
清除所有数据:关闭

目前以下操作会触发缓存更新

来自原生评论系统的评论
后台文章或页面更新
重启memcached
缓存到期

需求原因原版的Typecho不支持在线视频预览,只有一个图片预览功能,
所以为了实现可以在线预览视频功能,
2024-04-27T17:28:05.png

修改 typecho/admin/media.php
在大概19行的时候,追加如下内容

                <?php if ($attachment->attachment->isImage): ?>
                <p><img src="<?php $attachment->attachment->url(); ?>"
                        alt="<?php $attachment->attachment->name(); ?>" class="typecho-attachment-photo"/></p>
            <?php endif; ?>
            
           <?php if ($attachment->attachment->mime == "video/mp4"): ?>
             <video src="<?php $attachment->attachment->url(); ?>" controls="true" height="320" ></video>
            <?php endif; ?>

           <?php if ($attachment->attachment->mime == "text/plain"): ?>
             <iframe src="<?php $attachment->attachment->url(); ?>" controls="true" width="100%" ></iframe>
            <?php endif; ?>
            
            <?php if ($attachment->attachment->mime == "application/pdf"): ?>
             <iframe src="<?php $attachment->attachment->url(); ?>" controls="true" width="100%" ></iframe>
            <?php endif; ?>

保存即可

PHP+MYSQL+APACHE2,作为网站搭建,具体细节不细讲,

但是在我的/var/www/html下面

linaro@Hinlink:/var/www/html$ tree -L 1
.
├── 404.html
├── 笔记.txt
├── ask
├── base64
├── bg.png
├── chat
├── DownLoad
├── favicon.ico
├── H68K
├── index.html
├── on_publish.php
├── pac
├── probe.php
├── README.md
├── speedtest-x
├── tools
├── typecho
├── typecho_2023_5_1.sql
├── videos
├── WebShell.php
├── websocket.html
├── wordpress
├── www
└── xss

可以看到,有很多目录,我想实现 typecho.domain.com,这样的三级域名的方式,访问,

在FRPC.ini的配置里面

linaro@Hinlink:/var/www/html$ cat /etc/frp/frpc.ini
[common]
server_addr = FRPS服务器
server_port = 7000
token = 第三方token

[HT2_PHP]
type = http
local_ip = 127.0.0.1
local_port = 80
remote_port = 80
#subdomain = www
custom_domains = *.domain.com

custom_domains 其中的值,带上了*,通配符匹配
请输入图片描述

然后,任意访问 www.domain.com或者222.domain.com,会发现得到的页面都是一样的

这个时候,需要配置apache

第一步开启地址重写

sudo a2enmod rewrite

第二步,修改配置文件

nano /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
    DocumentRoot /var/www/html
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(([-_a-zA-Z0-9])+)\.\w+\.\w+$ [NC]
    RewriteRule ^(.*)$ /%1/$1 [L]
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    ErrorDocument 404 "404 Not Found"
</VirtualHost>

第三步重启Apache2

sudo systemctl restart apache2

自此,完成

修改

html/typecho/usr/plugins/DPlayer/assets/editor.js

$(function () {
if ($('#wmd-button-row').length > 0) {
    $('#wmd-button-row').append('<li class="wmd-button" id="wmd-dplayer-button" style="" title="插入视频"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABGUlEQVQ4T6XTvyuFURgH8M9lkTKYlMGiRDKIxSQDkcFgYVAmi8WPwY+Uxa8FhWQmWdgMiAxmf4BYpFAGSRkY6K1z6tJ1vTdnfc/zOU/P830z/nkyoX4GIyjHHKrQjyXUoh3raEQT9nGDjQQowjk6cYcBnOIJHbjCY4DecYtK7KIrAUqwiNHweh16sRa+DWEbD5jAIS5QgekIJB0cB3kwgNXowTLq0YpNNKMB92iLwALGCpznSnYHP4EyvP4B5gX6wlaGcfkL9Cewh0/sYDIMMdtKBcSCN4xjK0tIDXyE6c/ipVAg2Xmynescc/jWQQxSvNeCUpzl2cQqpmKUj0JsC4nCSRL/+DMl66rBcwqhGN04wHwEUtTlvvIFs5ZDZeiythMAAAAASUVORK5CYII="/></li>');
}

$(document).on('click', '#wmd-dplayer-button', function () {
    $('body').append(
        '<div id="DPlayer-Panel">' +
        '<div class="wmd-prompt-background" style="position: absolute; top: 0; z-index: 1000; opacity: 0.5; height: 875px; left: 0; width: 100%;"></div>' +
        '<div class="wmd-prompt-dialog">' +
        '<div>' +
        '<p><b>插入视频</b></p>' +
        '<p>在下方输入参数</p>' +
        '<p><input type="text" id="DP-url" value="" placeholder="链接"/></p>' +
        '<p><input type="text" id="DP-pic" value="" placeholder="封面图"/></p>' +
        '<p><input type="text" id="width" value="" placeholder="视频宽度"/></p>' +
        '<p><input type="checkbox" id="controls" checked>开启控件</input></p>' +
        '<p><input type="checkbox" id="DP-autoplay">自动播放</input></p>' +
        '</div>' +
        '<form>' +
        '<button type="button" class="btn btn-s primary" id="ok">确定</button>' +
        '<button type="button" class="btn btn-s" id="cancel">取消</button>' +
        '</form>' +
        '</div>' +
        '</div>');
});
//cancel
$(document).on('click', '#cancel', function () {
    $('#DPlayer-Panel').remove();
    $('textarea').focus();
});
//ok
$(document).on('click', '#ok', function () {
    var url = document.getElementById('DP-url').value,
        pic = document.getElementById('DP-pic').value,
        width = document.getElementById('width').value,
        controls = !!document.getElementById('controls').checked,
        autoplay = !!document.getElementById('DP-autoplay').checked;
    var tag = '<video src="' + url+ '" ';
    if(pic) tag +=  'pic="' + pic + '" ';
    if (controls) tag += 'controls="' + controls + '" ';
    if(width) tag += 'width="' + width + '" ';
    if (autoplay) tag += 'autoplay="' + autoplay + '" ';
    tag += '> </video>\n';
    
    var editor = document.getElementById('text');

    if (document.selection) {
        editor.focus();
        sel = document.selection.createRange();
        sel.text = tag;
        editor.focus();
    }
    else if (editor.selectionStart || editor.selectionStart === '0') {
        var startPos = editor.selectionStart;
        var endPos = editor.selectionEnd;
        var cursorPos = startPos;
        editor.value = editor.value.substring(0, startPos)
            + tag
            + editor.value.substring(endPos, editor.textLength);
        cursorPos += tag.length;
        editor.focus();
        editor.selectionStart = cursorPos;
        editor.selectionEnd = cursorPos;
    }
    else {
        editor.value += tag;
        editor.focus();
    }

    $('#DPlayer-Panel').remove();
})
});