分类目录归档:网站建设

阿里云 php php-fpm mysql nginx apc

vi /etc/yum.repos.d/nginx.repo

[root@w1 ~]# vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

[root@w1 ~]# yum update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.esocc.com
 * extras: mirror.esocc.com
 * updates: mirror.esocc.com
nginx                                                    | 2.9 kB     00:00
nginx/primary_db                                         |  28 kB     00:00
Setting up Update Process
No Packages marked for Update
[root@w1 ~]# yum list|grep nginx
nginx.x86_64                              1.4.7-1.el6.ngx               nginx
nginx-debug.x86_64                        1.4.7-1.el6.ngx               nginx
[root@w1 ~]#
[root@w1 ~]# yum install nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.esocc.com
 * extras: mirror.esocc.com
 * updates: mirror.esocc.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 0:1.4.7-1.el6.ngx will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package        Arch            Version                    Repository      Size
================================================================================
Installing:
 nginx          x86_64          1.4.7-1.el6.ngx            nginx          312 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 312 k
Installed size: 771 k
Is this ok [y/N]: y
Downloading Packages:
nginx-1.4.7-1.el6.ngx.x86_64.rpm                         | 312 kB     00:10
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : nginx-1.4.7-1.el6.ngx.x86_64                                 1/1
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

----------------------------------------------------------------------
  Verifying  : nginx-1.4.7-1.el6.ngx.x86_64                                 1/1

Installed:
  nginx.x86_64 0:1.4.7-1.el6.ngx

Complete!
[root@w1 ~]#
[root@w1 ~]# service nginx status
nginx is stopped
[root@w1 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@w1 ~]# service nginx start
Starting nginx:                                            [  OK  ]
[root@w1 ~]#
[root@w1 nginx]# yum install php-fpm
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.esocc.com
 * extras: mirror.esocc.com
 * updates: mirror.esocc.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php-fpm.x86_64 0:5.3.3-27.el6_5 will be installed
--> Processing Dependency: php-common(x86-64) = 5.3.3-27.el6_5 for package: php-fpm-5.3.3-27.el6_5.x86_64
--> Running transaction check
---> Package php-common.x86_64 0:5.3.3-27.el6_5 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package            Arch           Version                Repository       Size
================================================================================
Installing:
 php-fpm            x86_64         5.3.3-27.el6_5         updates         1.1 M
Installing for dependencies:
 php-common         x86_64         5.3.3-27.el6_5         updates         525 k

Transaction Summary
================================================================================
Install       2 Package(s)

Total download size: 1.7 M
Installed size: 6.1 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): php-common-5.3.3-27.el6_5.x86_64.rpm              | 525 kB     00:00
(2/2): php-fpm-5.3.3-27.el6_5.x86_64.rpm                 | 1.1 MB     00:00
--------------------------------------------------------------------------------
Total                                           5.1 MB/s | 1.7 MB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : php-common-5.3.3-27.el6_5.x86_64                             1/2
  Installing : php-fpm-5.3.3-27.el6_5.x86_64                                2/2
  Verifying  : php-fpm-5.3.3-27.el6_5.x86_64                                1/2
  Verifying  : php-common-5.3.3-27.el6_5.x86_64                             2/2

Installed:
  php-fpm.x86_64 0:5.3.3-27.el6_5

Dependency Installed:
  php-common.x86_64 0:5.3.3-27.el6_5

Complete!
[root@w1 nginx]#
[root@w1 nginx]# service php-fpm status
php-fpm is stopped
[root@w1 nginx]# service php-fpm start
Starting php-fpm:                                          [  OK  ]
[root@w1 nginx]#

[root@w1 php-fpm]# yum install php-pecl-apc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.esocc.com
 * extras: mirror.esocc.com
 * updates: mirror.esocc.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php-pecl-apc.x86_64 0:3.1.9-2.el6 will be installed
--> Processing Dependency: /usr/bin/pecl for package: php-pecl-apc-3.1.9-2.el6.x86_64
--> Processing Dependency: /usr/bin/pecl for package: php-pecl-apc-3.1.9-2.el6.x86_64
--> Running transaction check
---> Package php-pear.noarch 1:1.9.4-4.el6 will be installed
--> Processing Dependency: php-cli >= 5.1.0-1 for package: 1:php-pear-1.9.4-4.el6.noarch
--> Running transaction check
---> Package php-cli.x86_64 0:5.3.3-27.el6_5 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package             Arch          Version                 Repository      Size
================================================================================
Installing:
 php-pecl-apc        x86_64        3.1.9-2.el6             base            96 k
Installing for dependencies:
 php-cli             x86_64        5.3.3-27.el6_5          updates        2.2 M
 php-pear            noarch        1:1.9.4-4.el6           base           393 k

Transaction Summary
================================================================================
Install       3 Package(s)

Total download size: 2.7 M
Installed size: 8.7 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): php-cli-5.3.3-27.el6_5.x86_64.rpm                 | 2.2 MB     00:00
(2/3): php-pear-1.9.4-4.el6.noarch.rpm                   | 393 kB     00:00
(3/3): php-pecl-apc-3.1.9-2.el6.x86_64.rpm               |  96 kB     00:00
--------------------------------------------------------------------------------
Total                                           4.8 MB/s | 2.7 MB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : php-cli-5.3.3-27.el6_5.x86_64                                1/3
  Installing : 1:php-pear-1.9.4-4.el6.noarch                                2/3
  Installing : php-pecl-apc-3.1.9-2.el6.x86_64                              3/3
  Verifying  : php-pecl-apc-3.1.9-2.el6.x86_64                              1/3
  Verifying  : 1:php-pear-1.9.4-4.el6.noarch                                2/3
  Verifying  : php-cli-5.3.3-27.el6_5.x86_64                                3/3

Installed:
  php-pecl-apc.x86_64 0:3.1.9-2.el6

Dependency Installed:
  php-cli.x86_64 0:5.3.3-27.el6_5         php-pear.noarch 1:1.9.4-4.el6

Complete!
[root@w1 php-fpm]#

aliyun 主机修改hostname

1. modify /etc/hosts
[root@AY14032111447fdZ ~]# more /etc/hosts
127.0.0.1 localhost
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
#10.162.90.107 AY14032111447fdZ
10.162.90.107 w1.newhost.com

2.修改/etc/sysconfig/network的hostname一行。
[root@AY14032111447fdZ ~]# vi /etc/sysconfig/network
[root@AY14032111447fdZ ~]# more /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=w1.newhost.com
GATEWAY=218.244.142.242

3. 运行hostname命令
[root@AY14032111447fdZ ~]# hostname w1.newhost.com

4.重新登陆,已经改过来了
[louis@w1 ~]$ hostname
w1.newhost.com
[louis@w1 ~]$ hostname -s
w1



 

禁止cos_slug_translator将全英文标题url翻译为中文

cos_slug_translator是一个很好用的插件,会自动将带有中文的标题翻译为英文,作为永久链接,英文比中文更好。
cos_slug_translator采用了有道的翻译api,目前版本是1.1,这个api会将中文翻译为英文,同时,也会将英文翻译为中文。没有参数可以指定是 中->英 还是 英->中。这样就造成了如果标题是全英文的,那么最终的固定连接会自动被替换为翻译过来的中文,反倒不美。
进行如下修改,如果表里中不含有中文,就不进行翻译

修改 function CosSlugTrans($postID){
    $tableposts = $wpdb->posts ;
        $sql = "SELECT post_title,post_name FROM $tableposts WHERE ID=$postID";
        $res = $wpdb->get_results($sql);    
        $post_title = $res[0]->post_title;
        $tran_title = cos_tranlate($post_title);
        $slug = $tran_title;
        if(function_exists("sanitize_title") ) {
            if( sanitize_title( $res[0]->post_title ) != $res[0]->post_name  ){
                if( !substr_count($path, '%') ) 
....
修改为
    $tableposts = $wpdb->posts ;
        $sql = "SELECT post_title,post_name FROM $tableposts WHERE ID=$postID";
        $res = $wpdb->get_results($sql);    
        $post_title = $res[0]->post_title;

        if (preg_match("/[\x7f-\xff]/", $post_title)) {
            $tran_title = cos_tranlate($post_title);
            $slug = $tran_title;
        } else {
            $slug = $post_title;
        }

        if(function_exists("sanitize_title") ) {
            if( sanitize_title( $res[0]->post_title ) != $res[0]->post_name  ){
                if( !substr_count($path, '%') ) 
....

 

how to debug nginx rewrite rule.

2 method

1.
error_log /srv/www/example.com/log/error.log debug;

2.
rewrite_log on;
error_log /srv/www/example.com/log/error.log notice;

if you want to check a variable’s value , you can direct use following script
rewrite ^ $var_you_want_check break;

then you can find something like following in error.log , the strings in RED , is the value of $var_you_want_check
2012/07/03 14:15:24 [notice] 25289#0: *30519 "^" matches "/2012/02/01/february-1-7-gnc-gold-card-weeks-gnc-com-and-drugstore-com-gnc-products-of-a-discount.html", client: 116.24.4.227, server: 6658.net, request: "GET /2012/02/01/february-1-7-gnc-gold-card-weeks-gnc-com-and-drugstore-com-gnc-products-of-a-discount.html HTTP/1.1", host: "6658.net", referrer: "http://6658.net/wp-content/cache/supercache/6658.net/2012/01/31/gnc-more-than-one-hundred-products-less-than-10-dollar-free-shipping.html/index.html"
2012/07/03 14:15:24 [notice] 25289#0: *30519 rewritten data: "/example.com/public_html/wp-content/cache/supercache/6658.net/2012/02/01/february-1-7-gnc-gold-card-weeks-gnc-com-and-drugstore-com-gnc-products-of-a-discount.htmlindex.html", args: "", client: 116.24.4.227, server: 6658.net, request: "GET /2012/02/01/february-1-7-gnc-gold-card-weeks-gnc-com-and-drugstore-com-gnc-products-of-a-discount.html HTTP/1.1", host: "6658.net", referrer: "http://6658.net/wp-content/cache/supercache/6658.net/2012/01/31/gnc-more-than-one-hundred-products-less-than-10-dollar-free-shipping.html/index.html"

disable wp-cron.php

trace wp-super-cache的时候,发现后台有很多wp-cron.php的调用,每一次访问页面都会调用。

01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 In WP Cache Phase 2
01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 Setting up WordPress actions
01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 Not caching POST request.
01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 Cache garbage collection.
01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 Cleaning expired cache files in /****/public_html/wp-content/cache/
01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 Doing GC on supercache dir: /****/public_html/wp-content/cache/supercache
01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 gc: could not delete /****/public_html/wp-content/cache/supercache/6658.net/2012/01 as it’s not empty: 30

google之,发现该进程会占用很多系统资源。用google到的如下方法disable
在wp-config.php中添加

define(‘DISABLE_WP_CRON’, true);

然后在系统的crontab中添加

0,30 * * * * php -q /path_to_your_website/public_html/wp-cron.php

参考文档
http://blog.mellowhost.com/reducing-cpu-usage-for-wordpress-users.html

nginx+wp-super-cache不生成静态cache文件

网站迁移到nginx后,所有原来apache下面的配置文件都要重新写。
配置完wp-super-cache后,查看后台,发现cache目录已经建立,但是没有生成html文件。
打开wp-super-cache的debug功能,查看后台log

00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Cookie detected: wordpress_logged_in_08459be021d7ddc91806841039286bce
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ No wp-cache file exists. Must generate a new one.
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Cookie detected: wordpress_logged_in_08459be021d7ddc91806841039286bce
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ In WP Cache Phase 2
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Setting up WordPress actions
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Supercache caching disabled. Only using wp-cache. Non empty GET request.
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Created output buffer
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Output buffer callback
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Supercache disabled: GET or feed detected or disabled by config.
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Writing non-gzipped buffer to wp-cache cache file.

发现是因为有GET参数传递给了wp-super-cache,所以disabled.
wordpress所有响应都是rewrite给index.php的,检查nginx rewrite规则。发现确实使用用参数传递给index.php的,

try_files $uri/ $uri /index.php?q=$uri&$args;

网上查找一下,换成如下的rewrite方法

if (!-e $request_filename) { rewrite ^/(.+)$ /index.php last; }

reload配置之后,再次访问同一页面,后台trace如下

01:11:49 /2012/06/27/yourls-rewrite-apache-to-nginx/ Sending buffer to browser
01:11:49 /2012/06/27/yourls-rewrite-apache-to-nginx/ wp_cache_shutdown_callback: collecting meta data.
01:11:49 /2012/06/27/yourls-rewrite-apache-to-nginx/ Did not write meta file: wp-cache-6848e4f0747fac2d2b5b769950bff440.meta *1* *0* *1*
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ supercache dir: /****/public_html/wp-content/cache/supercache/3qs.com/2012/06/27/yourls-rewrite-apache-to-nginx/
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ No wp-cache file exists. Must generate a new one.
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ In WP Cache Phase 2
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Setting up WordPress actions
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Created output buffer
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Output buffer callback
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Anonymous user detected. Only creating Supercache file.
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Writing non-gzipped buffer to supercache file.
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Renamed temp supercache file to /****/public_html/wp-content/cache/supercache/3qs.com/2012/06/27/yourls-rewrite-apache-to-nginx/index.html
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Sending buffer to browser
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ wp_cache_shutdown_callback: collecting meta data.

到后台服务器上产看, 已经生成了对应的index.html静态文件了,访问速度也从1500多ms降到500多ms,多次访问,会返回304,在本地也cache了。。

[09:17:41.414] GET http://3qs.com/2012/06/27/yourls-rewrite-apache-to-nginx/ [HTTP/1.1 304 Not Modified 204ms]

-THE END-

yourls rewrite apache to nginx

Apache rewrite .htaccess file

# BEGIN YOURLS

RewriteEngine on

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([0-9A-Za-z]+)/?$ /yourls-go.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+/?$ /yourls-infos.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+all/?$ /yourls-infos.php?id=$1&all=1 [L]

# END YOURLS

explain

# BEGIN YOURLS

RewriteEngine on
##This line starts the mod_rewrite module

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
##如果访问的文件存在,就不进行rewrite.
RewriteCond %{REQUEST_FILENAME} !-d
##如果访问的目录存在,就不进行rewrite.

RewriteRule ^([0-9A-Za-z]+)/?$ /yourls-go.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+/?$ /yourls-infos.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+all/?$ /yourls-infos.php?id=$1&all=1 [L]

# END YOURLS

#####Nginx

location /{
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = “21″){
rewrite ^/([0-9A-Za-z]+)/?$ /yourls-go.php?id=$1 last;
rewrite ^/([0-9A-Za-z]+)\+/?$ /infos.php?id=$1 last;
rewrite ^/([0-9A-Za-z]+)\+all/?$ /infos.php?id=$1&all=1 last;
}
}

更正历史blog的图片链接错误

今天整理blog,发现部分blog的图片缺失,经过查找,原因是多次迁移,造成原来在/wp-content/upload/year/month/下面的图片都被放到了/wp-content/upload/下面,路径发生改变。

用phpmyadmin,如下sql,查找用旧链接位置的帖子
SELECT *
FROM `3qs_wp_posts`
WHERE post_content LIKE ‘%www.3qs.com/file%’

用如下sql更新
UPDATE 3qs_wp_posts SET post_content=REPLACE(post_content, ‘www.3qs.com/files’, ’3qs.com/wp-content/uploads/2011/03′) where id=458

然后手工将/wp-content/upload下面的图片移动到对应的/wp-content/upload/year/mongth下面。

进行中~~~~~~~~~~