日志标签:WordPress

Nginx配置fastcgi_cache缓存PHP输出为WordPress加速

分类:网站技术日期:2019-07-15 - 0:54:52评论:5条作者:老谢

  闲来无事折腾一波,好久没折腾Nginx了。

  高并发网站架构的核心原则其实就一句话”把所有的用户访问请求都尽量往前推“,即:能缓存在用户电脑本地的,就不要让他去访问 CDN。 能缓存 CDN 服务器上的,就不要让 CDN 去访问源(静态服务器)了。能访问静态服务器的,就不要去访问动态服务器。以此类推:能不访问数据库和存储就一定不要去访问数据库和存储。

安装ngx_cache_purge模块

  ngx_cache_purge是为了后面配合插件完成自动刷新使用,ngx_cache_purge是个控制Nginx缓存的模块。

  军哥LNMP一键包默认不编译ngx_cache_purge模块,所以需要自行编译该模块进去,使用nginx -V命令可以看到当前的编译参数,编译该模块只需要增添–-add-module=../ngx_cache_purge-2.3参数即可,顺便升级一波Nginx。

wget http://nginx.org/download/nginx-1.17.0.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
tar -zxf nginx-1.17.0.tar.gz
tar -zxf ngx_cache_purge-2.3.tar.gz
cd nginx-1.17.0
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/root/lnmp1.5/src/openssl-1.0.2o --with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib --add-module=/root/lnmp1.5/src/lua-nginx-module-0.10.11 --add-module=/root/lnmp1.5/src/ngx_devel_kit-0.3.0 --add-module=/root/ngx_cache_purge-2.3
make
make upgrade
/etc/init.d/nginx stop
cp objs/nginx /usr/local/nginx/sbin/nginx
/etc/init.d/nginx start

继续阅读…

博客开启强制HTTPS访问

分类:折腾日期:2017-02-16 - 23:04:41评论:11条作者:老谢

  自为博客安装SSL证书以后,老谢博客一直是支持HTTPS协议访问的,但是并没有强制跳转HTTPS,最近Let’s Encrypt的免费SSL证书流行开来,老薛主机的cPanel控制面板也已经支持了一键安装SSL证书启用HTTPS访问,身边的朋友也越来也多使用HTTPS访问,老谢也按耐不住启用强制HTTPS访问。

# 又拍云启用HTTPS

  老谢博客使用又拍云作为外链资源好几年了,要启用全站HTTPS,外链资源必须也要使用HTTPS协议,登录又拍云的后台,在“工具箱” – “SSL证书服务”里面可以自定申请Let’s Encrypt的免费SSL证书,该证书是受Chrome和Firefox等主流浏览器信任的,免费3个月,又拍云支持自动续期的功能。

  申请证书速度很快,我在操作的时候只用了十来分钟就完成了,另外要注意的是需要在又拍云的HTTPS设置里面选择启用HTTPS访问以及强制SSL的选项。

# 修改站点地址、资源地址以及修改文章内链接

  首先在wp后台的设置里面,修改站点地址为HTTPS的地址,然后把站内的静态资源如CSS、JS以及小图标等链接修改为HTTPS,确保无非HTTPS的资源载入。

  最后修改站内的图片资源地址,老谢博客一直使用又拍云的外链资源,地址为http://upyun.xj123.info/,这里只需要修改为https://upyun.xj123.info/即可,可以使用SQL语句完成:

UPDATE wp_posts SET post_content = REPLACE( post_content, 'http://www.old.com', 'http://www.new.com' ) ;

  最最后也可以在wp-config.php添加下面参数启用wp后台强制HTTPS访问:

/* 强制后台和登录使用 SSL */
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);
# Nginx重定向到https

  在server字段添加下面的语句即可:

                if ( $scheme = http ){
                    return 301 https://$server_name$request_uri;
                }

WordPress文章形式

分类:折腾日期:2014-05-06 - 17:53:10评论:2条作者:老谢

官方关于文章形式帮助文档:http://codex.wordpress.org/zh-cn:文章形式

需要说明下的是在使用相册形式的时候,需要在循环体内加入下面的一句代码,以让可以使用自己定义的css样式

<?php add_filter( 'use_default_gallery_style', '__return_false' ); ?>

下面直接贴出我的loop.php以便大家参考:

<?php if ( has_post_format( 'status' )) { ?>
<div class="post<?php sticky_class(); ?>"  id="post-<?php the_ID(); ?>">
		<div class="post-data">
			<div class="title">
			<!--<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>-->
			<h3 class="aside"><span>分类:<?php the_category(', '); ?></span><span>日期:<?php the_time('Y-m-d'); ?></span><span><span>作者:<?php the_author(); ?></span><span><?php if (function_exists('custom_the_views')) : ?>阅读:<?php custom_the_views($post->ID); ?></span><?php endif; ?>
			</h3>
			</div>
		</div>
		<div class="post-txt"><a href="<?php the_permalink() ?>" rel="bookmark"><?php echo get_avatar( get_the_author_meta('ID'), 42 ); ?></a><?php the_content(); ?></div>
</div>
<?php 
}else if ( has_post_format( 'gallery' ) ){ ?>
		<?php add_filter( 'use_default_gallery_style', '__return_false' );   ?>
<div class="post<?php sticky_class(); ?>"  id="post-<?php the_ID(); ?>">
		<div class="post-data">
			<div class="title">
			<!--<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>-->
			<h3 class="aside"><span>标题:<?php echo the_title(); ?></span><span>分类:<?php the_category(', '); ?></span><span>日期:<?php the_time('Y-m-d'); ?></span><span><span>作者:<?php the_author(); ?></span><span><?php if (function_exists('custom_the_views')) : ?>阅读:<?php custom_the_views($post->ID); ?></span><?php endif; ?>
			</h3>
			</div>
		</div>
		<div class="post-txt"><?php echo do_shortcode('[gallery columns="3" size="thumbnail" link="file"]'); ?></div>
</div>
<?php 
}else{ ?>                      
<div class="post<?php sticky_class(); ?>"  id="post-<?php the_ID(); ?>">
		<div class="post-data">
			<div class="title">
			<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
			<h3><span>分类:<?php the_category(', '); ?></span><span>日期:<?php the_time('Y-m-d'); ?></span><span>评论:<?php comments_popup_link(__('0条'), __('1条'), __('%条'), '', __('已关闭评论')); ?></span><span>作者:<?php the_author(); ?></span><span><?php if (function_exists('custom_the_views')) : ?>阅读:<?php custom_the_views($post->ID); ?></span><?php endif; ?>
			</h3>
			</div>
		</div>
		<div class="post-txt"><?php the_content( __( '<b>继续阅读...</b>') ); ?></div>
	    <?php the_tags('<div class="tags">Tags: ', ' , ', '</div>'); ?>
</div>
<?php } ?>
Tags:

wordpress文章评论后可见

分类:折腾日期:2012-02-27 - 18:15:33评论:27条作者:老谢

function reply_to_read($atts,$content=null){
    extract(shortcode_atts(array("notice"=>'<span class="reply-to-read">此處內容需要
<a href="'. get_permalink().'#respond" title="評論本文">評論本文</a>後
<a href="javascript:window.location.reload();" 
title="刷新">刷新本頁</a>才能查看.</span>'),$atts));
    $email=null;
    $user_ID=(int)wp_get_current_user()->ID;
    if($user_ID>0){
        $email =  get_userdata($user_ID)->user_email; //如果用戶已登錄,從登錄信息中獲取email
    }else if(isset($_COOKIE['comment_author_email_'.COOKIEHASH])){
        $email=str_replace('%40','@',$_COOKIE['comment_author_email_'.COOKIEHASH]); 
//如果用戶未登錄但電腦上有本站的Cookie信息,從Cookie裏讀取email
    }else{
        return $notice; //無法獲取email,直接返回提示信息
    }
    if(empty($email)){
        return $notice;
    }
    global $wpdb;
    $post_id=get_the_ID(); //文章的ID
    $query="SELECT `comment_ID` 
FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} 
and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
    if($wpdb->get_results($query)){
        return $content; //查詢到對應的已經審核通過的評論則返回內容
    }else{
        return $notice; //否則返回提示信息
    }
}
 
add_shortcode('reply', 'reply_to_read');

以上代码复制到function.php即可,用法如下:

[reply]评论可见内容[/reply]

原文传送门:http://zuidongting.com/non-plug-ins-to-achieve-the-contents-of-the-article-shows-the-code-reply-share.html