nginx反向代理加替换教程

本文适合全新安装,也适合安装了Lnmp.org一键包的安装
1、下载substitutions4nginx模块,这个模块用于替换。

pkill nginx
/etc/init.d/nginx stop #停止nginx
cd
apt-get update
apt-get install -y git gcc g++ make automake
#安装依赖包,Centos将apt-get更改为yum
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module

2、编译nginx

wget -c http://nginx.org/download/nginx-1.3.13.tar.gz
tar zxvf nginx-1.3.13.tar.gz
cd nginx-1.3.13
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --add-module=/root/ngx_http_substitutions_filter_module
make
make install

3、新建一个配置用于反代
vi /usr/local/nginx/conf/vhost/example.com.conf #example.com是你要绑定的域名,当然你也可以用其他名字.conf
输入以下内容:

server{
listen 80;
server_name example.com; #绑定的域名
index index.php; #默认首页
access_log off; #off 关闭日志
location / {
subs_filter u.longsays.com example.com; #替换掉域名
subs_filter static/image/common/logo.png http://xxx/1.jpg; #替换掉LOGO
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Referer http://u.longsays.com; #强制定义Referer,程序验证判断会用到
proxy_set_header Host u.longsays.com; #定义主机头,如果目标站点绑定的域名个server_name项的吻合则使用$host
proxy_pass http://u.longsays.com; #指定目标,建议使用IP或者nginx自定义池
proxy_set_header Accept-Encoding ""; #清除编码
}
}

如果要替换中文,要先把conf文件转成utf-8模式。
4、重启Nginx
/etc/init.d/nginx restart
如无意外,此时访问你的域名就会看到成功反代并替换了。

wordpress首页排除指定分类

wordpress的首页默认是显示所有分类的最新文章,如果你想排除某些分类的文章不让它显示,可以通过以下方法来实现:
1、一般是在 index.php 文件中找到loop(循环)代码,while(have_posts()): 前加入
query_posts('cat=-1,-22');
endwhile; 后插入代码
wp_reset_query(); 继续阅读wordpress首页排除指定分类

wordpress批量替换内容的方法

最近总是更改链接地址,网上也有很多相关的文章,但是总是不够简单明了,很多复制来也没法用,所以本着方便自己方便大家的原则,自己整理了一下。
其实没什么东西 主要就是如下语句:
-- 修改option_value里的站点url和主页地址:
UPDATE wp_options SET option_value = REPLACE(option_value,'替换内容','替换值');
-- 更改文章中内部链接及附件的地址:
UPDATE wp_posts SET post_content = REPLACE(post_content,'替换内容','替换值');
-- 更改wordpress文章默认的永久链接:
UPDATE wp_posts SET guid = REPLACE(guid,'替换内容','替换值');
-- 更改博客用户里你的网站链接:(如果你的个人资料里没有填你的博客地址,可忽略)
UPDATE wp_users SET user_url = REPLACE(user_url,'替换内容','替换值');
-- 更改评论者资料里你的博客链接:
UPDATE wp_users SET user_url = REPLACE(user_url,'替换内容','替换值');
-- 更改评论内容你的博客链接:(如果评论里没有你博客链接,可忽略)
UPDATE wp_comments SET comment_content = REPLACE(comment_content,'替换内容','替换值');

PHP随机产生6位密码


/* 随机生成6位查看密码 函数 调用方式:echo generate_password(); */
function generate_password( $length = 6 ) {
// 密码字符集,可任意添加你需要的字符
$chars = 'abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789';
$password = '';
for ( $i = 0; $i < $length; $i++ ) { // 这里提供两种字符获取方式 // 第一种是使用 substr 截取$chars中的任意一位字符; // 第二种是取字符数组 $chars 的任意元素 // $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); $password .= $chars[ mt_rand(0, strlen($chars) - 1) ]; } return $password;