分类 Typecho 下的文章

按文章内容装好插件后选择是否修改逻辑

原作者的判断逻辑,在评论插件配置配错,或是出现百度审核有未知错误时,评论会绕过审核直接发布

进入插件的目录,修改 Plugin.php文件

找到 public static function checkComment($comment, $post)函数,修改以下内容:

public static function checkComment($comment, $post)
    {
        $options = Typecho_Widget::widget('Widget_Options');

        $app_id = $options->plugin('BaiduTextCensor')->app_id;
        $api_key = $options->plugin('BaiduTextCensor')->api_key;
        $secret_key = $options->plugin('BaiduTextCensor')->secret_key;

        $is_check_admin = $options->plugin('BaiduTextCensor')->is_check_admin;
        if (!$is_check_admin) {
            $userObj = Typecho_Widget::widget('Widget_User');
            if($userObj->hasLogin() && $userObj->pass('administrator', true)) {
                return $comment;
            }
        }

        if (!class_exists('Luffy\TextCensor\AipBase')) {
            require_once 'AipBase.php';
        }
        $client = new Luffy\TextCensor\AipBase($app_id, $api_key, $secret_key);
        $res = $client->textCensorUserDefined($comment['text']);
    // 从这以下的都是修改内容,可以和原文对比下
        if ($res['conclusionType'] == 1) {
                Typecho_Cookie::delete('__typecho_remember_text');
                return $comment;
        } elseif ($res['conclusionType'] == 2) {
            Typecho_Cookie::set('__typecho_remember_text', $comment['text']);
            throw new Typecho_Widget_Exception("评论内容" . $res['data'][0]['msg'] . ",请重新评论");
        }

        throw new Typecho_Widget_Exception("评论过滤系统有未知错误!");
        return $comment;
    }

以下是转发的内容:


百度文本内容审核

百度文本内容审核能一站式检测文本中夹杂的色情、推广、辱骂、违禁、涉政、灌水等垃圾内容,净化网络环境,为您的应用提供更可靠的内容安全保障,运用业界领先的深度学习技术,判断一段文本内容是否符合网络发文规范,实现自动化、智能化的文本审核,大幅节省内容审核的人力成本,为您的产品体验保驾护航

能力介绍

  • 文本色情:对文本中的色情行为描述、色情资源链接、低俗交友、污秽文爱等内容进行识别
  • 暴恐违禁:对暴力行为、恐怖描述、赌博、毒品、枪支弹药等违禁内容进行识别
  • 政治敏感:对文本中的敏感事件、涉政人物、散布谣言、反动宣传等内容进行识别
  • 恶意推广:对文本中带有售卖意向的软文广告,微信、QQ等个人联系方式等违规内容及变体进行识别
  • 低俗辱骂:对文本中的侮辱谩骂、人身攻击、消极宣泄等内容进行识别
  • 低质灌水:对网络社区常见的乱码、水帖、刷屏等无意义的灌水信息进行识别

Typecho

安装

  1. Github 下载源码,将源码上传到 Typecho 插件目录usr/plugins
  2. 修改插件文件名为BaiduTextCensor
  3. 修改目录权限和用户组
chown -R www:www BaiduTextCensor/
chmod 755 BaiduTextCensor/runtime
  1. 启用~

设置

在百度Ai控制台的 产品服务 / 内容审核 - 应用列表 创建应用 后获取 AppID、API Key、Secret Key

其他

WordPress

在 WordPress 后台安装插件页面搜索 Baidu TextCensor For Comments

项目地址:https://github.com/sy-records/wp-baidu-textcensor

其他博客系统

在其他博客系统中,如 ThinkPHP、Laravel 等,可以直接使用 composer 包,自行调用处理

项目地址:https://github.com/sy-records/baidu-textcensor

License

Apache-2.0

1 效果

2 方法

进入 <typecho目录>编辑主题的 Content.php文件

[root@10-23-159-191 typecho]# vim usr/themes/handsome/libs/Content.php

找到 whenSwitchHeaderImgSrc函数,注释 random变量,替换成随机图源

// 随机图源
$randomImgOrgin = get_headers('https://api.mz-moe.cn/img.php', TRUE)['Location'];
$random = $randomImgOrgin;
// 随机缩略图路径(注释默认的随机图)
// $random = STATIC_PATH . 'img/sj/' . @$randomNum[$index] . '.jpg';//如果有文章置顶,这里可能会导致index not undefined

或者也可以这样:

$randomImgOrgin = "";
$OrginKey = "";
switch(rand(1,2))
{
case 1:
    $randomImgOrgin = "https://api.mtyqx.cn/api/random.php?return=json";
    $OrginKey = "imgurl";
    break;
case 2:
    $randomImgOrgin = "https://api.mtyqx.cn/tapi/random.php?return=json";
    $OrginKey = "imgurl";
    break;
}
$responContent = "";
$requestHandle = fopen($randomImgOrgin,"rb");
while (!feof($requestHandle)) {
    $responContent .= fread($requestHandle, 10000);
}
fclose($requestHandle);
$jsonData = json_decode($responContent, true);
$random = $jsonData[$OrginKey];

需要注意,因为图片都是比较大的,会影响网页的加载速度,这里还将 handsome主题增强功能->增强功能开关->lazyload开了起来,感觉会好一些

3 随机图源

随机动漫图片api

随机博客api

1 效果

image.png

2 方法

handsome设置外观->开发者设置->自定义CSS中添加以下代码:

kaygb_copy();function kaygb_copy(){$(document).ready(function(){$("body").bind('copy',function(e){hellolayer()})});var sitesurl=window.location.href;function hellolayer(){
$.message({
    message: "尊重原创,转载请注明出处!<br> 本文作者:Jiang<br>原文链接:<br>"+sitesurl,
    title: "复制成功",
    type: "warning",
    autoHide: !1,
    time: "1500"
    })
}}

handsome设置外观->PJAX->PJAX回调函数中添加以下代码:

kaygb_copy();

3 参考

如何调用handsome主题自带的弹窗提示实现复制弹窗提醒以及个性化提示

用Layer和jQuery写了一个复制之后版权提醒的弹窗

注:原作者不止有复制,还有其它功能

1 效果

image.png

2 方法

handsome设置外观->开发者设置->自定义CSS中添加以下代码:

/*主页标题居中*/
header.bg-light.lter.wrapper-md {
text-align: center;
}

1 效果

2 方法

2.1 修改post.php

进入 <typecho目录>编辑主题的 post.php文件

[root@10-23-159-191 typecho]# vim usr/themes/handsome/post.php

找到文件中以下内容位置

<?php Content::postContentHtml($this, $this->user->uid); ?>

在后面新增代码:

<!--版权信息&正文结束分割线-->
<div class="cutline">
    <span><a style="color:#F17B8F; border-bottom: 0px solid #999!important;"> 正文到此结束 </a></span>
</div>
<ul class="post-copyright">
    <li class="post-copyright-author"><strong>本文作者:</strong><?php $this->author(); ?></li>
    <li class="post-copyright-link"><strong>本文链接:</strong><a href="<?php $this->permalink() ?>" title="<?php $this->title() ?>"><?php $this->permalink() ?></a></li>
    <li class="post-copyright-license"><strong>版权声明:</strong>本博客所有文章除特别声明外,均默认采用<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank" rel="noopener" title="CC BY-NC-SA 4.0 "><strong> CC BY-NC-SA 4.0 </strong></a> 许可协议。</li>
</ul>

2.2 新增样式

handsome 主题后台提供 CSS 代码的编辑服务,在 设置外观 -> 开发者设置 -> 自定义CSS 对话框中加入以下代码

/*版权信息&正文结束分割线 CSS*/
.cutline {
    border-top: 1px dotted #ccc;
    height: 1px;
    margin: 20px 0;
    text-align: center;
    width: 100%;
}
.cutline span {
    background-color: rgb(236, 237, 238);
    border: 1px solid #d6d6d6;
    font: 12px Arial,Microsoft JhengHei;
    padding: 2px 4px;
    position: relative;
    top: -10px;
}
.post-copyright {
    font-size: 13px;
    margin: 8px 0;
    padding: 10px;
    border-left: 4px solid #ff5252;
    background-color: rgba(220, 220, 220, 0.1);
    list-style: none;
    word-break: break-all;
    position: relative;
    overflow: hidden;
}
.post-copyright li {
    display: list-item;
    text-align: -webkit-match-parent;
}
.post-copyright a {
    color: rgba(0, 120, 231, 1);
    text-decoration: none;
    transition: color .1s;
}

3 参考

Typecho 在文章底部添加版权说明

1 效果

2 方法

进入 <typecho目录>编辑主题的 post.php文件

[root@10-23-159-191 typecho]# vim usr/themes/handsome/post.php

找到文件中以下内容位置

     <!--文章内容-->
     <div id="post-content" class="wrapper-lg">

在后面新增代码:

<!--复制代码自带版权说明-->
<script>
document.body.addEventListener('copy', function (e) {
    if (window.getSelection().toString() && window.getSelection().toString().length > 42) {
        setClipboardText(e);
    }
});
function setClipboardText(event) {
    var clipboardData = event.clipboardData || window.clipboardData;
    if (clipboardData) {
        event.preventDefault();
        var htmlData = ''
            + window.getSelection().toString()
            + '<br>-------------------------------------------------<br>'
            + '著作权归作者所有。<br>'
            + '商业转载请联系作者获得授权,非商业转载请注明出处。<br>'
            + '作者:<?php $this->author() ?><br>'
            + '链接:<?php $this->permalink() ?><br>'
            + '-------------------------------------------------<br>';
        var textData = ''
            + window.getSelection().toString()
            + '\n-------------------------------------------------\n'
            + '著作权归作者所有。\n'
            + '商业转载请联系作者获得授权,非商业转载请注明出处。\n'
            + '作者:<?php $this->author() ?>\n'
            + '链接:<?php $this->permalink() ?>\n'
            + '-------------------------------------------------\n';

        clipboardData.setData('text/html', htmlData);
        clipboardData.setData('text/plain',textData);
    }
}
</script>
<!--复制代码自带版权说明-->

3 参考

handsome主题美化记录

一般编辑主题下的 footer.php

[root@10-23-159-191 typecho]# vim usr/themes/default/footer.php

在标签内新增:

<font size="2">   <span class="mod_copyright_split">|</span>   </font>
<font size="1"> <a target="_blank" href="https://beian.miit.gov.cn">闽ICP备2021007947号-1</a></font>
<font size="2">   <span class="mod_copyright_split">|</span>   </font>
<font size="1"> <img src="https://www.vkxx.com/usr/uploads/other/gongan.png"/> <a target="_blank" href="https://www.beian.gov.cn/portal/registerSystemInfo?recordcode=35010402351226">闽公网安备 35010402351226号</p></a></font>

handsome主题可在 设置外观->开发者设置->博客底部左侧信息中添加以上代码

也可以用美化效果:

<div class="github-badge">
    <a href="https://beian.miit.gov.cn" target="_blank">
    <span class="badge-subject">闽ICP备</span><span class="badge-value bg-red">2021007947号</span>
    </a>
</div>
<div class="github-badge">
    <a href="https://www.beian.gov.cn/portal/registerSystemInfo?recordcode=35010402351226" target="_blank">
    <span class="badge-subject"><img src="https://www.vkxx.com/usr/uploads/other/gongan.png" style="height:12px;"/>闽公网安备</span><span class="badge-value bg-red">35010402351226号</span>
    </a>
</div>

Typecho增加log调试功能

参考:Typecho控制台日志打印

<typecho目录>/var/下新建 Logger.php文件

Logger.php

<?php

/*
 * Logger 日志类
 * @date 2016/12/21
 * @author 300js
 * 简单快捷debug类
 * 优点:少配置或零配置,支持任何格式数据记录,支持数G数据存储.支持在浏览或linux环境查看
 * 配置:
 * 可以在外部更改的常量:
 *  支持html便捷浏览模式或纯txt查看,值html|txt
    defined('MINI_DEBUG_TYPE') or define('MINI_DEBUG_TYPE', 'html');
    调试模式,1可写,0不可写
    defined('MINI_DEBUG_FLAG') or define('MINI_DEBUG_FLAG', 1);
    jquery 地址
    defined('MINI_DEBUG_JSPAHT') or define('MINI_DEBUG_JSPAHT', 'http://cdn.bootcss.com/jquery/1.8.3/jquery.js');
    debug 可写的目录设置,结尾一定要加 保证有可写权限
    defined('MINI_DEBUG_PATH') or define('MINI_DEBUG_PATH', __DIR__ . DIRECTORY_SEPARATOR);
 *
 * 更改存储目录:
    define('MINI_DEBUG_PATH', __DIR__ . '/');//必须后面加斜杆 /
    Logger::log('err', 'myFlag');
 * 存储不同的文件名:
    define('MINI_DEBUG_PATH', __DIR__ . '/');
    Logger::setCacheFile(date('Y-m-di'));//无需设置文件后缀
    Logger::log('err', 'myFlag');
 *  更改存储格式:
    define('MINI_DEBUG_PATH', __DIR__ . '/');
    define('MINI_DEBUG_TYPE', 'txt');//默认为html
    Logger::log('err', 'myFlag');
 * 覆盖文件,相当将之前的数据删除,写入新的数据,可做清空数据用
    define('MINI_DEBUG_PATH', __DIR__ . '/');
    Logger::log(1, 'myFlag', false);
 */
class Logger {
    private static $config = array(
        'isSetFixx' => false,//是否已追加后缀标识
        'cacheFile' => 'debug',//缓存的文件名,无需设置后缀
    );
    private static $_cacheFile = '';

    /**
     * 设置日志文件,可文件名,可加相对路径,无需设置后缀名称
     * @param string $cacheFile
     */
    final public static function setCacheFile($cacheFile) {
        self::$config['cacheFile'] = $cacheFile;
    }
    /**
     * 记录日志
     * @param mix $data 数据
     * @param string $memo 标识
     * @param boolean $isPush 是否追加,默认true
     * @param string $titleStr title
     * @return boolean 成功与否
     */
    final public static function log($data, $memo = 'None', $isPush = true, $titleStr = '日志记录') {
        self::_setBaseParam();
        return self::_baseLog($data, $memo, $isPush, $titleStr);
    }
    /**
     * 获取当前的缓存文件
     * @return type
     */
    final public static function getCacheFile() {
        return self::$_cacheFile;
    }


    /**
     * 基础的日志方法
     * @param mix $data 内容
     * @param string $memo 标识
     * @param boolean $isPush 是否追求,默认true
     * @param string $titleStr Title
     * @return boolean|int
     */
    private static function _baseLog($data, $memo, $isPush = true, $titleStr = '日志记录') {
        if(!MINI_DEBUG_FLAG) return false;
        $cacheFile = MINI_DEBUG_PATH . self::$config['cacheFile'];
        if(!$isPush)
            unlink ($cacheFile);
        switch (strtolower(MINI_DEBUG_TYPE)) {
            case 'txt':
                $str = self::_setFormatTxt($data, $memo);
                break;
            default:
                $str = self::_setFormatHtml($data, $memo, $cacheFile, $titleStr);
                break;
        }
        self::$_cacheFile = $cacheFile;
        try{
            if($isPush)
                file_put_contents($cacheFile, $str, 8);
            else
                file_put_contents($cacheFile, $str);
        } catch (Exception $ex) {
        }
        return true;
    }
    /**
     * 设置html格式,可以浏览器上方便查看
     * @param type $data 数据
     * @param type $memo 标识
     * @param type $cacheFile 缓存文件
     * @param type $titleStr
     * @return string
     */
    private static function _setFormatHtml($data, $memo, $cacheFile, $titleStr){
        $DebugFilePath = $_SERVER["PHP_SELF"];//当前处理页面
        $timespan = microtime(true);//时间戳
        $sBlockHTML = "\n\n\n<div class='block' _k='".md5($memo)."' _l='".$memo."'><span style='display:none'><------orderIndex-------></span>";
        /*判断是否存在头信息*/
        $baseHtml = '';
        if(!is_file($cacheFile)) {
            $baseHtml = self::_getBaseHtml(MINI_DEBUG_JSPAHT, $titleStr);
        }
        $str = '';
        $str .= $baseHtml;
        $str .= $sBlockHTML;
        $str .= "<span  class='no' style='color:blue;'>NO</span>:\n\n";
        $str .= "<br/><span  style='color:blue;'>Date</span>:\t".date("Y-m-d H:i:s")."\n";
        $str .= "<br/><span  style='color:blue;'>File</span>:\t".$DebugFilePath."\n";
        $str .= "<br/><span class='memo' style='color:blue;'>Memo</span>:\t".$memo."<br>\n";
//        $str .= "<span style='color:blue;'>Action:</span>:\t".$_SERVER['QUERY_STRING']."<br>\n";
        $str .= "----------------------------------------<span class='infoswitch'><a  href='javascript:void(0)' >展开/收起</a></span>\n<div class='info'>";
        ob_start();
        if(is_array($data))
            print_r($data);
        elseif(is_string($data))
            echo $data;
        else
            var_dump($data);
        $a = ob_get_contents();
        ob_end_clean();
        $str .= "<xmp>";
        $str .= $a;
        $str .= "</xmp>";
        $str .= "</div>\n<hr></div>\n\n\n";
        return $str;
    }
    /**
     * 设置txt纯文本格式
     * @param type $data
     * @param type $memo
     * @return type
     */
    private static function _setFormatTxt($data, $memo) {
        $DebugFilePath = $_SERVER["PHP_SELF"];//当前处理页面
        $str = '';
        $str .= 'Memo:' . $memo;
        $str .= ' Time:' . date('Y-m-d H:i:s');
        $str .= ' File:' . $DebugFilePath;
        $str .= PHP_EOL;
        ob_start();
        if(is_array($data))
            print_r($data);
        elseif(is_string($data))
            echo $data;
        else
            var_dump ($data);
        $a = ob_get_contents();
        ob_end_clean();
        $str .= $a;
        $str .= PHP_EOL;
        return $str;
    }

    /**
     * 获取处理的js html
     * @param type $jsPath
     * @param type $titleStr
     * @return type
     */
    private static function _getBaseHtml($jsPath, $titleStr) {
        $baseHtml = <<<___html
    <!doctype html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>{$titleStr}</title><script src="{$jsPath}" type="text/javascript"></script><style type="text/css">
    body {
    margin: 0px;
    padding: 0px;
    height: 100%;
    }

    body, th, td {
    font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #333;
    }
    </style></head><body><div id="tabs"></div></body></html>
    <script>
    $(function() {
        var _oMemo = {all:{label:'all', total:$("div.block").length}};
        var j=1;
        $("div.block").each(function(){
            if(typeof _oMemo[$(this).attr('_k')] == 'undefined') {
                _oMemo[$(this).attr('_k')] = {};
            }  
            if(typeof _oMemo[$(this).attr('_k')]['total'] == 'undefined'){          
                _oMemo[$(this).attr('_k')]['total'] = 1;
                _oMemo[$(this).attr('_k')]['label'] = $(this).attr('_l');
                $(this).find(".no").html("NO:" + j);
            }else {
                _oMemo[$(this).attr('_k')]['total'] += 1;  
                $(this).find(".no").html("NO:" +  j);
            }
            j++;
        });

        var sUl = "";
        for(var k in _oMemo){
            sUl += '<li><a _k="'+k+'" href="javascript:void(0)" >'+_oMemo[k]['label']+'('+_oMemo[k]['total']+')</a></li>';
        }
        $('div#tabs').html("<ul>"+sUl+"</ul><div  style=\"position:absolute;top:10px;right:20px;\" class='allinfoSwith'><a href='javascript:void(0)' >全部 展开/收起</a></div>");
        $('div#tabs li a').click(function(){
            var _showK = $(this).attr('_k');
            if(_showK == 'all'){
                var i = 1;
                $("div.block").each(function(){
                    $(this).find(".no").html("NO:" + i);
                    i++;              
                });
                $('div.block').show();          
            }else{          
                $('div.block').hide();
                $('div.block[_k="'+_showK+'"]').show();
                var p = 1;
                $('div.block[_k="'+_showK+'"]').each(function(){
                    $(this).find('.no').html("NO:"+p);
                    p++;
                });
            }
        });
        $('div.block span.infoswitch a').click(function(){
            var _o = $(this).parents('div.block').find('div.info').eq(0);
            _o.toggle();
        });
        var allinfoSwithIndex = 0;
        $('div.allinfoSwith a').click(function(){
            allinfoSwithIndex%2==0 ? $('div.info').hide() : $('div.info').show();
            allinfoSwithIndex++;
        });
    });
    </script>
___html;
        return $baseHtml;
    }
    /**
     * 初使常量及判断
     */
    private static function _setBaseParam(){
        /**支持html便捷浏览模式或纯txt查看,值html|txt*/
        defined('MINI_DEBUG_TYPE') or define('MINI_DEBUG_TYPE', 'html');
        /**调试模式,1可写,0不可写*/
        defined('MINI_DEBUG_FLAG') or define('MINI_DEBUG_FLAG', 1);
        /**jquery 地址*/
        defined('MINI_DEBUG_JSPAHT') or define('MINI_DEBUG_JSPAHT', 'http://cdn.bootcss.com/jquery/1.8.3/jquery.js');
        /**debug 可写的目录设置,结尾一定要加 / */
        defined('MINI_DEBUG_PATH') or define('MINI_DEBUG_PATH', __DIR__ . DIRECTORY_SEPARATOR);
        self::_setFileFixx();
    }
    /**
     * 设置文件后缀
     * @param type $cacheFile
     */
    private static function _setFileFixx() {
        $_default_name = '_log';
        if(stripos(self::$config['cacheFile'], 'debug') !== false) {
            $_default_name = '';
        }
        $baseName = pathinfo(self::$config['cacheFile'], PATHINFO_BASENAME);
        if(strpos($baseName, '.') !== false && self::$config['isSetFixx'] == true) {
            return;
        }
        switch (strtolower(MINI_DEBUG_TYPE)) {
            case 'txt':
                self::$config['cacheFile'] .= $_default_name . '.txt';
                self::$config['isSetFixx'] = true;
                break;
            default:
                self::$config['cacheFile'] .= $_default_name . '.html';
                self::$config['isSetFixx'] = true;
                break;
        }
    }
}

<typecho目录>/config.inc.php配置Logger

加入以下代码

// 定义日志文件类型:txt文本,html网页,建议开发使用网页,便于查看
define('MINI_DEBUG_TYPE', 'html');
// 定义日志文件目录
define('MINI_DEBUG_PATH', __TYPECHO_ROOT_DIR__ . '/logs/');

require_once 'Logger.php';

typecho目录下新建 logs文件夹并给权限

[root@10-23-159-191 typecho]# mkdir logs
[root@10-23-159-191 typecho]# chmod -R 777 logs

使用

// 参数1:日志内容,参数2:日志业务TAG
Logger::log('测试日志','baidu');

//支持数组形式输出
Logger::log(array('url'=>'测试1','name'=>'淘宝'),'taobao');

在浏览器中访问 http://测试域名/logs/debug.html即可查看日志内容

Typecho的搭建过程及问题解决

Typecho安装

LNMP环境+Typecho参考CentOS下Typecho的安装

配置

参考内容安装完成后,配置基本如下

nginx配置

默认配置目录

[root@10-23-159-191 conf.d]# cd /etc/nginx/conf.d^C
[root@10-23-159-191 conf.d]# ls
default.conf  php.conf  php-fpm.conf  typecho.conf

default.conf

server {
    listen       80;
    server_name  nginx.vkxx.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

php.conf

server {
        listen 80;
        server_name php.vkxx.com;
        index index.php;
        root /usr/share/nginx/php;
        location ~ \.php$ {
                fastcgi_pass  unix:/run/php-fpm/www.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include fastcgi_params;
    }
}

php-fpm.conf

# PHP-FPM FastCGI server
# network or unix domain socket configuration

upstream php-fpm {
        server unix:/run/php-fpm/www.sock;
}

typecho.conf
需要注意如果fastcgi_pass不配置成和php-fpm.conf一样是unix:/run/php-fpm/www.sock,可能会导致Typecho访问404

server {
        listen 80;
        server_name vkxx.com www.vkxx.com;
        index index.php;
        root /usr/share/nginx/typecho;
        location ~ .*\.php(\/.*)*$ {
                fastcgi_pass  unix:/run/php-fpm/www.sock;
                fastcgi_index  index.php;
        if (!-e $request_filename){
                        rewrite ^(.*)$ /index.php?q=$1 last;
                        break;
                }
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include fastcgi_params;
  
    }
}

Typecho配置

config.inc.php
注:其中注释掉的Logger.php是后续自己扩展用于调试功能

<?php
/**
 * Typecho Blog Platform
 *
 * @copyright  Copyright (c) 2008 Typecho team (http://www.typecho.org)
 * @license    GNU General Public License 2.0
 * @version    $Id$
 */

/** 定义根目录 */
define('__TYPECHO_ROOT_DIR__', dirname(__FILE__));

/** 定义插件目录(相对路径) */
define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins');

/** 定义模板目录(相对路径) */
define('__TYPECHO_THEME_DIR__', '/usr/themes');

/** 后台路径(相对路径) */
define('__TYPECHO_ADMIN_DIR__', '/admin/');

/* 日志功能
// 定义日志文件类型:txt文本,html网页,建议开发使用网页,便于查看
define('MINI_DEBUG_TYPE', 'html');
// 定义日志文件目录
define('MINI_DEBUG_PATH', __TYPECHO_ROOT_DIR__ . '/logs/');
 */

/** 开启HTTPS */
/** define('__TYPECHO_SECURE__',true);*/

/** 设置包含路径 */
@set_include_path(get_include_path() . PATH_SEPARATOR .
__TYPECHO_ROOT_DIR__ . '/var' . PATH_SEPARATOR .
__TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__);

/* 日志功能
require_once 'Logger.php';
 */

/** 载入API支持 */
require_once 'Typecho/Common.php';

/** 载入Response支持 */
require_once 'Typecho/Response.php';

/** 载入配置支持 */
require_once 'Typecho/Config.php';

/** 载入异常支持 */
require_once 'Typecho/Exception.php';

/** 载入插件支持 */
require_once 'Typecho/Plugin.php';

/** 载入国际化支持 */
require_once 'Typecho/I18n.php';

/** 载入数据库支持 */
require_once 'Typecho/Db.php';

/** 载入路由器支持 */
require_once 'Typecho/Router.php';

/** 程序初始化 */
Typecho_Common::init();

/** 定义数据库参数 */
$db = new Typecho_Db('Mysql', 'typecho_');
$db->addServer(array (
  'host' => '127.0.0.1',
  'user' => 'root',
  'password' => '你的密码',
  'charset' => 'utf8',
  'port' => '3306',
  'database' => 'typecho',
), Typecho_Db::READ | Typecho_Db::WRITE);
Typecho_Db::set($db);

安装问题

网页无样式问题

Typecho进入管理员,然后设置->基本里的站点地址要填对就没问题了

无法提交评论(点击提交评论界面刷新了却没反应)

<typecho目录>/var/Widget/Feedback.php文件Widget_Feedback::comment函数,注释以下两句

    /**
     * 评论处理函数
     *
     * @throws Typecho_Widget_Exception
     * @throws Exception
     * @throws Typecho_Exception
     */
    private function comment()
    {
        // 使用安全模块保护
        // 这个安全保护模块有问题,有空检查下 mark by jzl
        //$this->security->enable($this->options->commentsAntiSpam);
        //$this->security->protect();

无法上传附件

a.<typecho目录>/var/Typecho/Common.php文件isAppEngine函数更改为直接返回false

    /**
     * 检测是否在app engine上运行,屏蔽某些功能
     *
     * @static
     * @access public
     * @return boolean
     */
    public static function isAppEngine()
    {
        return false;
        /* 不能上传问题
        return !empty($_SERVER['HTTP_APPNAME'])                     // SAE
            || !!getenv('HTTP_BAE_ENV_APPID')                       // BAE
            || !!getenv('HTTP_BAE_LOGID')                           // BAE 3.0
            || (ini_get('acl.app_id') && class_exists('Alibaba'))   // ACE
            || (isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'],'Google App Engine') !== false) // GAE
            ;
         */
    }

isAppEngine是判断是否为虚拟机什么的,虚拟机默认不支持上传附件
b.给附件文件夹权限
进入typecho目录

[root@10-23-159-191 typecho]# chmod -R 777 usr/uploads

参考:typecho 不能上传附件问题Typecho上传附件失败最佳解决方法