<?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>『博客·琼斯』 &#187; nginx</title>
	<atom:link href="http://shuai.be/tags/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>http://shuai.be</link>
	<description></description>
	<lastBuildDate>Thu, 03 May 2012 15:42:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PhotonVPS现已原生支持IPv6！</title>
		<link>http://shuai.be/archives/photonvps-native-ipv6/</link>
		<comments>http://shuai.be/archives/photonvps-native-ipv6/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 14:16:54 +0000</pubDate>
		<dc:creator>Jones</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[ipv6]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[photonvps]]></category>

		<guid isPermaLink="false">http://shuai.be/archives/photonvps-native-ipv6/</guid>
		<description><![CDATA[我用的vps服务提供商PhotonVPS早在去年底就说要增加ipv6支持，不过一直没收到他们的通知邮件。今天ifconfig查了一下，已经有ipv6地址了，ping6 ipv6.google.com也ping通了，说明vps已经原生支持ipv6。 记得上次编译nginx时没有添加ipv6支持，现在需要重编译一下，顺便升一下级。 wget http://nginx.org/download/nginx-0.8.54.tar.gz tar -xzvf nginx-0.8.54.tar.gz cd nginx-0.8.54 ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ld-opt=-ltcmalloc_minimal --with-ipv6 vi auto/cc/gcc #将CFLAGS=“$CFLAGS -g”注释掉，去掉debug，编译出的文件更小 make #这里只make，不用make install! 编译完后，在objs目录下会生成nginx可执行文件，先将原nginx文件备份 mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak 然后 cp objs/nginx /usr/local/nginx/sbin/ killall nginx #干掉nginx进程 /usr/local/nginx/sbin/nginx #重新启动nginx 同时要在server段是监听ipv6的80端口 server { listen 80; 监听ipv4 80端口 listen [::]:80 ipv6only=on; 一定要加上后面这句，否则在监听ipv6时ipv4也默认被监听了，在nginx启动时会报错[emerg]: bind() to [::]:80 failed (98: [...]]]></description>
			<content:encoded><![CDATA[<p>我用的vps服务提供商<a href="http://www.photonvps.com/" target="_blank" onclick="return redirect('http://www.photonvps.com/billing/aff.php?aff=679')">PhotonVPS</a>早在去年底就说要增加<span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/ipv6/" title="查看 ipv6 中的全部文章" target="_blank">ipv6</a></span>支持，不过一直没收到他们的通知邮件。今天ifconfig查了一下，已经有<span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/ipv6/" title="查看 ipv6 中的全部文章" target="_blank">ipv6</a></span>地址了，ping6 <span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/ipv6/" title="查看 ipv6 中的全部文章" target="_blank">ipv6</a></span>.google.com也ping通了，说明vps已经原生支持ipv6。</p>
<p><span id="more-2386"></span></p>
<p>记得上次编译<span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/nginx/" title="查看 nginx 中的全部文章" target="_blank">nginx</a></span>时没有添加ipv6支持，现在需要重编译一下，顺便升一下级。</p>
<blockquote><p>wget <a href="http://nginx.org/download/nginx-0.8.54.tar.gz">http://nginx.org/download/nginx-0.8.54.tar.gz</a><br />
tar -xzvf <span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/nginx/" title="查看 nginx 中的全部文章" target="_blank">nginx</a></span>-0.8.54.tar.gz<br />
cd <span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/nginx/" title="查看 nginx 中的全部文章" target="_blank">nginx</a></span>-0.8.54<br />
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ld-opt=-ltcmalloc_minimal <span style="color: #ff0000;">--with-ipv6</span><br />
vi auto/cc/gcc #将CFLAGS=“$CFLAGS -g”注释掉，去掉debug，编译出的文件更小<br />
make #这里只make，不用make install!<br />
编译完后，在objs目录下会生成nginx可执行文件，先将原nginx文件备份<br />
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak 然后<br />
cp objs/nginx /usr/local/nginx/sbin/<br />
killall nginx #干掉nginx进程<br />
/usr/local/nginx/sbin/nginx #重新启动nginx</p></blockquote>
<p>同时要在server段是监听ipv6的80端口</p>
<blockquote><p>server {<br />
listen 80; 监听ipv4 80端口<br />
listen [::]:80 <span style="color: #ff0000;">ipv6only=on</span>; 一定要加上后面这句，否则在监听ipv6时ipv4也默认被监听了，在nginx启动时会报错[emerg]: bind() to [::]:80 failed (98: Address already in use)，当然这里要绑定特定的ipv6地址也是可以的<br />
server_name ipv6.xx.com;<br />
… }</p></blockquote>
<p>再次按上面方法重启nginx，然后解析域名AAAA记录到ipv6地址，搞定！</p>
<blockquote><p>现在访问<span class="btn"><a href="http://shuai.be/">Blog of Jones</a></span>，只要网络支持ipv6会默认使用ipv6方式访问了！</p></blockquote>
<p>PS: WordPress默认会把半角转换为全角符号，比如把 -- 转换为 –，这样使正常的代码显示错误，解决方法如下：</p>
<blockquote><p>修改主题theme下的主题函数functions.php文件，在里面的头部加入下面的代码：</p>
<p>&lt;?php remove_filter('the_content', 'wptexturize'); ?&gt;</p></blockquote>
<p><strong>延伸阅读：</strong><ol>
<li><a href='http://shuai.be/archives/nginx-vsftpd-restart/' rel='bookmark' title='VPS主机中最简单的Nginx和vsFTPd重启命令'>VPS主机中最简单的Nginx和vsFTPd重启命令</a></li>
<li><a href='http://shuai.be/archives/nginx-default-server/' rel='bookmark' title='在nginx中配置ip直接访问的默认站点'>在nginx中配置ip直接访问的默认站点</a></li>
<li><a href='http://shuai.be/archives/php-asp-jsp-301-redirection/' rel='bookmark' title='php asp jsp .htaccess nginx的301跳转（永久重定向）方法'>php asp jsp .htaccess nginx的301跳转（永久重定向）方法</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://shuai.be/archives/photonvps-native-ipv6/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>在nginx中配置ip直接访问的默认站点</title>
		<link>http://shuai.be/archives/nginx-default-server/</link>
		<comments>http://shuai.be/archives/nginx-default-server/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 11:15:36 +0000</pubDate>
		<dc:creator>Jones</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://shuai.be/archives/nginx-default-server/</guid>
		<description><![CDATA[在nginx中，每个站点都是由一个server段定义的，这里面设定了监听的ip和端口，站点的域名，根目录等信息。但一般来说vps主机上每个ip上会对应几个不同的站点。这样就会出现一个问题，直接访问这个ip的话，访问的会是哪个站点？ 答案是这样的：在Listen ip:port; 这个指令行中，有一个参数default，指定了它后，这个server段就会是这个ip的默认站点；如果没有这个参数，那么默认ip直接访问的是nginx.conf中出现的第一个server段对应的站点。 server{ listen: 127.0.0.1:80 default; server_name shuai.be; ... } 延伸阅读： PhotonVPS现已原生支持IPv6！ php asp jsp .htaccess nginx的301跳转（永久重定向）方法 VPS主机中最简单的Nginx和vsFTPd重启命令]]></description>
			<content:encoded><![CDATA[<p>在<span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/nginx/" title="查看 nginx 中的全部文章" target="_blank">nginx</a></span>中，每个站点都是由一个server段定义的，这里面设定了监听的<span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/ip/" title="查看 ip 中的全部文章" target="_blank">ip</a></span>和端口，站点的域名，根目录等信息。但一般来说vps主机上每个<span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/ip/" title="查看 ip 中的全部文章" target="_blank">ip</a></span>上会对应几个不同的站点。这样就会出现一个问题，直接访问这个ip的话，访问的会是哪个站点？</p>
<p> <span id="more-2344"></span></p>
<p>答案是这样的：在Listen ip:port; 这个指令行中，有一个参数default，指定了它后，这个server段就会是这个ip的默认站点；如果没有这个参数，那么默认ip直接访问的是<span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/nginx/" title="查看 nginx 中的全部文章" target="_blank">nginx</a></span>.conf中出现的第一个server段对应的站点。</p>
<blockquote>
<p>server{      <br />listen: 127.0.0.1:80 <strong>default</strong>;       <br />server_name shuai.be;       <br />...       <br />}
</p>
</blockquote>
<p><strong>延伸阅读：</strong><ol>
<li><a href='http://shuai.be/archives/photonvps-native-ipv6/' rel='bookmark' title='PhotonVPS现已原生支持IPv6！'>PhotonVPS现已原生支持IPv6！</a></li>
<li><a href='http://shuai.be/archives/php-asp-jsp-301-redirection/' rel='bookmark' title='php asp jsp .htaccess nginx的301跳转（永久重定向）方法'>php asp jsp .htaccess nginx的301跳转（永久重定向）方法</a></li>
<li><a href='http://shuai.be/archives/nginx-vsftpd-restart/' rel='bookmark' title='VPS主机中最简单的Nginx和vsFTPd重启命令'>VPS主机中最简单的Nginx和vsFTPd重启命令</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://shuai.be/archives/nginx-default-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VPS主机中最简单的Nginx和vsFTPd重启命令</title>
		<link>http://shuai.be/archives/nginx-vsftpd-restart/</link>
		<comments>http://shuai.be/archives/nginx-vsftpd-restart/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 06:59:16 +0000</pubDate>
		<dc:creator>Jones</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[photonvps]]></category>
		<category><![CDATA[vps]]></category>
		<category><![CDATA[vsftpd]]></category>

		<guid isPermaLink="false">http://shuai.be/archives/nginx-vsftpd-restart/</guid>
		<description><![CDATA[前几天趁PhotonVPS打折买了一个xen版vps，256M内存。第一个月才2.49美刀很实惠啊，呵呵，先玩玩呗。 Linux命令几乎是从头学起，目前稍微有些了解了。下面是vps配置过程中常用的两个重启命令备忘： Nginx重启：#/usr/local/nginx/sbin/nginx -s  reload Nginx完全重启： 杀掉所有Nginx进程：#killall nginx 重新启动Nginx服务：#/usr/local/nginx/sbin/nginx vsFTPd重启：#service vsftpd restart 延伸阅读： PhotonVPS现已原生支持IPv6！ php asp jsp .htaccess nginx的301跳转（永久重定向）方法 测试服务器网络速度的几个参数和方法]]></description>
			<content:encoded><![CDATA[<p>前几天趁<a href="http://zi.mu/photonvps" target="_blank">PhotonVPS</a>打折买了一个xen版<span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/vps/" title="查看 vps 中的全部文章" target="_blank">vps</a></span>，256M内存。第一个月才2.49美刀很实惠啊，呵呵，先玩玩呗。<br />
Linux命令几乎是从头学起，目前稍微有些了解了。下面是<span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/vps/" title="查看 vps 中的全部文章" target="_blank">vps</a></span>配置过程中常用的两个重启命令备忘：</p>
<p>Nginx重启：#/usr/local/<span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/nginx/" title="查看 nginx 中的全部文章" target="_blank">nginx</a></span>/sbin/<span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/nginx/" title="查看 nginx 中的全部文章" target="_blank">nginx</a></span> -s  reload<br />
Nginx完全重启：</p>
<blockquote><p>杀掉所有Nginx进程：#killall <span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/nginx/" title="查看 nginx 中的全部文章" target="_blank">nginx</a></span><br />
重新启动Nginx服务：#/usr/local/nginx/sbin/nginx</p></blockquote>
<p>vsFTPd重启：#service <span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/vsftpd/" title="查看 vsftpd 中的全部文章" target="_blank">vsftpd</a></span> restart</p>
<p><strong>延伸阅读：</strong><ol>
<li><a href='http://shuai.be/archives/photonvps-native-ipv6/' rel='bookmark' title='PhotonVPS现已原生支持IPv6！'>PhotonVPS现已原生支持IPv6！</a></li>
<li><a href='http://shuai.be/archives/php-asp-jsp-301-redirection/' rel='bookmark' title='php asp jsp .htaccess nginx的301跳转（永久重定向）方法'>php asp jsp .htaccess nginx的301跳转（永久重定向）方法</a></li>
<li><a href='http://shuai.be/archives/check-server-network/' rel='bookmark' title='测试服务器网络速度的几个参数和方法'>测试服务器网络速度的几个参数和方法</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://shuai.be/archives/nginx-vsftpd-restart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php asp jsp .htaccess nginx的301跳转（永久重定向）方法</title>
		<link>http://shuai.be/archives/php-asp-jsp-301-redirection/</link>
		<comments>http://shuai.be/archives/php-asp-jsp-301-redirection/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 05:35:00 +0000</pubDate>
		<dc:creator>Jones</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[301]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://shuai.be/?p=1338</guid>
		<description><![CDATA[当不能控制服务器且不支持自定义.htaccess或http.ini文件，或者需要根据动态的条件进行跳转，可以用动态程序实现301，不管 jsp asp php 程序原理都是一样的，即设置头部状态码和要跳转目标URL，发送头部就行了。 .htaccess 301 跳转代码 Redirect 301 / http://shuai.be nginx 301 跳转代码 server { server_name domain.com; rewrite ^/(.*)$ http://redirect.com permanent; } ASP、ASP.net 301 跳转代码 Response.Status="301 Moved Permanently" Response.AddHeader "Location", "URL" PHP 301 跳转代码 header("HTTP/1.1 301 Moved Permanently"); header("Location: URL"); exit(); //注意：虽然客户端转向了，但程序还会向下执行，所以要exit JSP 301 跳转代码 response.setStatus(301); response.setHeader("Location","URL"); 多个域名绑一个站怎么做301：如a.com,a.net,www.b.net和www.a.com都是绑在一个站，为了网址规范化都要跳转到www.a.com这个主域名上，这时不能光写上面的代码，否则就成循环跳转了，要进行条件判断，即对主机头不是www.a.com才转向，以ASP为例： IF Request.Url.Host"www.a.com" THEN string newurl="http://www.a.com" [...]]]></description>
			<content:encoded><![CDATA[<p>当不能控制服务器且不支持自定义<span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/htaccess/" title="查看 .htaccess 中的全部文章" target="_blank">.htaccess</a></span>或http.ini文件，或者需要根据动态的条件进行跳转，可以用动态程序实现<span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/301/" title="查看 301 中的全部文章" target="_blank">301</a></span>，不管 <span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/jsp/" title="查看 jsp 中的全部文章" target="_blank">jsp</a></span> <span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/asp/" title="查看 asp 中的全部文章" target="_blank">asp</a></span> <span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/php/" title="查看 php 中的全部文章" target="_blank">php</a></span> 程序原理都是一样的，即设置头部状态码和要跳转目标URL，发送头部就行了。</p>
<p><span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/htaccess/" title="查看 .htaccess 中的全部文章" target="_blank">.htaccess</a></span> <span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/301/" title="查看 301 中的全部文章" target="_blank">301</a></span> 跳转代码<br />
<span id="more-1338"></span></p>
<pre lang="apache" line="1">Redirect <span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/301/" title="查看 301 中的全部文章" target="_blank">301</a></span> / http://shuai.be</pre>
<p><span class='wp_keywordlink_affiliate'><a href="http://shuai.be/tags/nginx/" title="查看 nginx 中的全部文章" target="_blank">nginx</a></span> 301 跳转代码</p>
<pre>server {
server_name domain.com;
rewrite ^/(.*)$ http://redirect.com permanent;
}</pre>
<p>ASP、ASP.net 301 跳转代码</p>
<pre lang="asp" line="1">Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "URL"</pre>
<p>PHP 301 跳转代码</p>
<pre lang="php" line="1">header("HTTP/1.1 301 Moved Permanently");
header("Location: URL");
exit(); //注意：虽然客户端转向了，但程序还会向下执行，所以要exit</pre>
<p>JSP 301 跳转代码</p>
<pre lang="jsp" line="1">response.setStatus(301);
response.setHeader("Location","URL");</pre>
<p><!--more--></p>
<p>多个域名绑一个站怎么做301：如a.com,a.net,www.b.net和www.a.com都是绑在一个站，为了网址规范化都要跳转到www.a.com这个主域名上，这时不能光写上面的代码，否则就成循环跳转了，要进行条件判断，即对主机头不是www.a.com才转向，以ASP为例：</p>
<pre lang="asp" line="1">IF Request.Url.Host<>"www.a.com" THEN
string newurl="http://www.a.com" &#038; Request.Url.PathAndQuery
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", newurl
END IF </pre>
<p>当然这种方法很麻烦，要在每个动态文件中都要加这代码才行，这种情况很少吧，因为虚拟主机都可以选择更多做301跳转方法，肯定有更适合的。</p>
<p><strong>Cannot modify header information - headers already sent by... 错误</strong></p>
<p>http头部信息已经发送给客户端了，当然就不能再修改头部状态码进行301了。这种情况是因为有HTML实质内容的输出，所以转向代码要放在HTML输出之前。当然其它情况也能造成输出，以PHP为例，如文件< ?php ... ?>之外有空白行，特别是include或者require的文件，这有可能导致输出，可以开启缓存ob_start();只要在转向之前缓存不满，网页就不会被发送。或者在跳转前运行ob_end_clean()，清除所有缓存并关闭缓存，这样再设置头部信息就没问题了。</p>
<p>还可参考：<br />
1. <a href="http://www.shyedu.net/it-website/301redirect-18.html">301跳转（永久重定向）实现方法</a><br />
2. <a href="http://www.williamlong.info/info/archives/297.html">16个简单实用的.htaccess技巧</a><br />
3. <a href="http://www.anysns.com/article/254.htm">利用.htaccess 的301功能统一网址：让网址变得规范化</a></p>
<p><strong>延伸阅读：</strong><ol>
<li><a href='http://shuai.be/archives/magic-htaccess/' rel='bookmark' title='神奇的.htaccess'>神奇的.htaccess</a></li>
<li><a href='http://shuai.be/archives/setup-wamp-support-htaccess/' rel='bookmark' title='设置wamp支持.htaccess'>设置wamp支持.htaccess</a></li>
<li><a href='http://shuai.be/archives/htaccess-url-remodel/' rel='bookmark' title='.htaccess URL重写教程'>.htaccess URL重写教程</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://shuai.be/archives/php-asp-jsp-301-redirection/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

