﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gavin&#039;s Blog &#187; Nginx</title>
	<atom:link href="http://laigw.name/tag/nginx/feed" rel="self" type="application/rss+xml" />
	<link>http://laigw.name</link>
	<description>Keep it simple, stupid. Simplicity is beauty.</description>
	<lastBuildDate>Sun, 29 Jan 2012 07:14:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Nginx Rewrite 参数和例子</title>
		<link>http://laigw.name/post/394.html</link>
		<comments>http://laigw.name/post/394.html#comments</comments>
		<pubDate>Tue, 24 Aug 2010 03:57:22 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[默认分类]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[rewrite]]></category>

		<guid isPermaLink="false">http://laigw.name/?p=394</guid>
		<description><![CDATA[
推荐参考地址：
Mailing list ARChives 官方讨论区
http://marc.info/?l=nginx
Nginx 常见应用技术指南[Nginx Tips]
http://bbs.linuxtone.org/thread-1685-1-1.html
本日志内容来自互联网和平日使用经验，整理一下方便日后参考。
正则表达式匹配，其中：
* ~ 为区分大小写匹配

* ~* 为不区分大小写匹配
* !~和!~*分别为区分大小写不匹配及不区分大小写不匹配
文件及目录匹配，其中：
* -f和!-f用来判断是否存在文件
* -d和!-d用来判断是否存在目录
* -e和!-e用来判断是否存在文件或目录
* -x和!-x用来判断文件是否可执行

flag标记有：
* last 相当于Apache里的[L]标记，表示完成rewrite
* break 终止匹配, 不再匹配后面的规则
* redirect 返回302临时重定向 地址栏会显示跳转后的地址
* permanent 返回301永久重定向 地址栏会显示跳转后的地址

一些可用的全局变量有，可以用做条件判断(待补全)

$args
$content_length
$content_type
$document_root
$document_uri
$host
$http_user_agent
$http_cookie
$limit_rate
$request_body_file
$request_method
$remote_addr
$remote_port
$remote_user
$request_filename
$request_uri
$query_string
$scheme
$server_protocol
$server_addr
$server_name
$server_port
$uri


结合QeePHP的例子
if (!-d $request_filename) {
rewrite ^/([a-z-A-Z]+)/([a-z-A-Z]+)/?(.*)$ /index.php?namespace=user&#38;amp;controller=$1&#38;amp;action=$2&#38;amp;$3 last;
rewrite ^/([a-z-A-Z]+)/?$ /index.php?namespace=user&#38;amp;controller=$1 last;
break;

多目录转成参数
abc.domian.com/sort/2 =&#62; abc.domian.com/index.php?act=sort&#38;name=abc&#38;id=2
if ($host ~* (.*)\.domain\.com) {
set $sub_name $1;   
rewrite ^/sort\/(\d+)\/?$ /index.php?act=sort&#38;cid=$sub_name&#38;id=$1 last;
}

目录对换
/123456/xxxx -&#62; /xxxx?id=123456
rewrite ^/(\d+)/(.+)/ /$2?id=$1 last;
例如下面设定nginx在用户使用ie的使用重定向到/nginx-ie目录下：
if ($http_user_agent ~ MSIE) [...]]]></description>
		<wfw:commentRss>http://laigw.name/post/394.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>升级nginx从0.5.37到0.6.33版本</title>
		<link>http://laigw.name/post/275.html</link>
		<comments>http://laigw.name/post/275.html#comments</comments>
		<pubDate>Tue, 25 Nov 2008 06:20:53 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[Web服务器]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Nginx 0.5.37]]></category>
		<category><![CDATA[Nginx 0.6.33]]></category>
		<category><![CDATA[版本升级]]></category>

		<guid isPermaLink="false">http://www.laigw.name/?p=275</guid>
		<description><![CDATA[    服务器上的Nginx原来版本是0.5.37，但在使用过程中发现rewrite时Nginx总会将url中的'+'字符转成编码'%2b'，造成我程序的一些问题。听说0.6版本已经解决了这个问题，并且虽然0.7版本已经出到0.7.22了，但官方还是开发版，所以就升级到0.6的最新版本 0.6.33，问题果然解决。升级过程本来想用make update的方式，但考虑到是大版本的升级(0.5->0.6)，为了避免不必要的麻烦，就用重新编译安装、并覆盖原来配置文件的方式升级了。虽然过程比较简单，但还是有一些地方是需要注意的，特记下来备忘。]]></description>
		<wfw:commentRss>http://laigw.name/post/275.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nginx下用cos-html-cache实现WordPress的真静态化</title>
		<link>http://laigw.name/post/248.html</link>
		<comments>http://laigw.name/post/248.html#comments</comments>
		<pubDate>Wed, 19 Nov 2008 10:51:48 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[wordpress]]></category>
		<category><![CDATA[cos-html-cache]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[静态化]]></category>

		<guid isPermaLink="false">http://www.laigw.name/?p=248</guid>
		<description><![CDATA[由于感觉自己的wordpress访问越来越慢，就狠下心来实现本博客的页面真静态化(之前已经通过Nginx的URL Rewrite实现了伪静态化)。在网上Google了一下，发现了cos-html-cache这个插件，口碑不错，就down下来装了。按照文档一路装下来，挺顺利的。现特记下来备忘。

一、安装步骤：
1、到这里下载插件。我安装的是当期最新版本：v2.6.1；
2、解压缩，确保文件夹里面没有二级目录，然后将其放置到插件目录下，插件目录通常是 `wp-content/plugins/`。Linux下则用命令：
$unzip cos-html-cache.zip
3、在wordpress后台对应的插件管理页激活该插件；
4、更改wordpress的Permalinks(永久链接)为非默认设置，我的是：/article/%post_id%.html；
5、确保gzip已经禁用，请到对应的页面检查设置：http://你wp的地址/wp-admin/options-reading.php(注：我的wordpress是2.6.3版本，没文档上的该设置)；
6、在网站的根目录下创建一个文件 &#8220;index.bak&#8221;，并将属性设置成0666；
7、在网站的根目录下创建一个目录article(对应/article/%post_id%.html中的目录)，并将文件夹属性设置成0777：
#chmod 0777 article/
8、安装完成。
当前端用户访问首页或者相应文章的url时，插件将会自动检测是否已经生成静态文件，如果没有，则于目录html/下生成相应的静态文件。静态文件会在文档末尾添加一句：

二、注意事项：
1、cos-html-cache只当前只能生成首页及文章的静态文件。如果不想首页生成静态文件，则可修改cos-html-cache.php(通过wordpress的后台可以edit)的
define(&#8216;IS_INDEX&#8217;,true);// false = do not create home page cache
为
define(&#8216;IS_INDEX&#8217;,false);// true = do create home page cache
则可。
2、我的Web服务器是Nginx，需要URL Rewrite，如果你也需要URL Rewrite，可以参考以下我的Nginx的虚拟机设置：

&#160;查看代码 DIV1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#
# www.laigw.name virtual host setting
#
server
&#123;
	listen       80;
	server_name  www.laigw.name laigw.name;
	index index.htm index.html index.php;
	root  /srv/nginx/laigw;
&#160;
	location / &#123;
		if &#40;-f $request_filename/index.html&#41;&#123;
		        [...]]]></description>
		<wfw:commentRss>http://laigw.name/post/248.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

