<?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>I@laoer.com &#187; Nginx</title>
	<atom:link href="http://i.laoer.com/tag/nginx/feed" rel="self" type="application/rss+xml" />
	<link>http://i.laoer.com</link>
	<description>技术、生活、感悟 -- Laoer的博客</description>
	<lastBuildDate>Mon, 30 Jan 2012 10:03:43 +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>Nginx下alias支持PHP的问题</title>
		<link>http://i.laoer.com/nginx-alias-php.html</link>
		<comments>http://i.laoer.com/nginx-alias-php.html#comments</comments>
		<pubDate>Wed, 06 Jan 2010 02:01:04 +0000</pubDate>
		<dc:creator>Laoer</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://i.laoer.com/?p=411</guid>
		<description><![CDATA[这几天在配置Nginx，PHP用FastCGI，想装一个phpMyAdmin管理数据库，phpMyAdmin不想放在网站根目录下，这样不容易和网站应用混在一起，这样phpMyAdmin的目录就放在别处，在Apache里，有alias，比较方便，在Nginx下没有虚拟目录概念的，是用location配合alias使用，我先试了简单的配置方式 location /web/ { alias  /data/web/; index  index.html index.htm index.php; } location ~ .*\.(php&#124;php5)?$ { fastcgi_pass  127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } 我用http://localhost/web/可以访问到/data/web目录下的静态文件，但访问php文件，却报No input file specified.的错误，而且在Nginx的error日志上却什么信息也没有，我在网上搜索了一下，判断应该是php文件并没有被后端的FastCGI运行，我又继续搜索一些文章，试着增加了一段配置 location /web/ { alias  /data/web/; index  index.html index.htm index.php; } location ~ ^/web/.+\.php$ { root /data/; rewrite /web/(.*\.php?) /$1 break; include fcgi.conf; fastcgi_pass   127.0.0.1:9000; fastcgi_index  index.php; fastcgi_param SCRIPT_FILENAME /data/web$fastcgi_script_name; [...]]]></description>
			<content:encoded><![CDATA[<p>这几天在配置Nginx，PHP用FastCGI，想装一个phpMyAdmin管理数据库，phpMyAdmin不想放在网站根目录下，这样不容易和网站应用混在一起，这样phpMyAdmin的目录就放在别处，在Apache里，有alias，比较方便，在Nginx下没有虚拟目录概念的，是用location配合alias使用，我先试了简单的配置方式</p>
<p>location /web/ {<br />
alias  /data/web/;<br />
index  index.html index.htm index.php;<br />
}</p>
<p>location ~ .*\.(php|php5)?$ {<br />
fastcgi_pass  127.0.0.1:9000;<br />
fastcgi_index index.php;<br />
include fcgi.conf;<br />
}</p>
<p>我用http://localhost/web/可以访问到/data/web目录下的静态文件，但访问php文件，却报No input file specified.的错误，而且在Nginx的error日志上却什么信息也没有，我在网上搜索了一下，判断应该是php文件并没有被后端的FastCGI运行，我又继续搜索一些文章，试着增加了一段配置</p>
<p>location /web/ {<br />
alias  /data/web/;<br />
index  index.html index.htm index.php;<br />
}</p>
<p>location ~ ^/web/.+\.php$ {<br />
root /data/;<br />
rewrite /web/(.*\.php?) /$1 break;<br />
include fcgi.conf;<br />
fastcgi_pass   127.0.0.1:9000;<br />
fastcgi_index  index.php;<br />
fastcgi_param SCRIPT_FILENAME /data/web$fastcgi_script_name;<br />
}</p>
<p>location ~ .*\.(php|php5)?$ {<br />
fastcgi_pass  127.0.0.1:9000;<br />
fastcgi_index index.php;<br />
include fcgi.conf;<br />
}</p>
<p>这下可以了，原理应该是采用rewrite的方法，对于/web/下php类型的的请求交给后端的FastCGI处理，并且指定了php脚本的位置，这样我们就可以配置phpMyAdmin了，配置如下</p>
<p>location /phpmyadmin/ {<br />
alias  /data/phpmyadmin/;<br />
index  index.html index.htm index.php;<br />
}</p>
<p>location ~ ^/phpmyadmin/.+\.php$ {<br />
root /data/;<br />
rewrite /phpmyadmin/(.*\.php?) /$1 break;<br />
include fcgi.conf;<br />
fastcgi_pass   127.0.0.1:9000;<br />
fastcgi_index  index.php;<br />
fastcgi_param SCRIPT_FILENAME /data/phpmyadmin$fastcgi_script_name;<br />
}</p>
<p>location ~ .*\.(php|php5)?$ {<br />
fastcgi_pass  127.0.0.1:9000;<br />
fastcgi_index index.php;<br />
include fcgi.conf;<br />
}</p>
<p>要注意的是</p>
<p>location ~ .*\.(php|php5)?$ {<br />
fastcgi_pass  127.0.0.1:9000;<br />
fastcgi_index index.php;<br />
include fcgi.conf;<br />
}</p>
<p>这段，要放在phpmyadmin的后面，放在前面就有问题，这是和Nginx的location规则有关，具体看Nginx的文档，另外，phpMyAdmin里要配置一下URI的绝对路径，就可以了。</p>
]]></content:encoded>
			<wfw:commentRss>http://i.laoer.com/nginx-alias-php.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LVS和Nginx的一些杂记</title>
		<link>http://i.laoer.com/lvs-keepalived-nginx.html</link>
		<comments>http://i.laoer.com/lvs-keepalived-nginx.html#comments</comments>
		<pubDate>Fri, 03 Apr 2009 04:47:22 +0000</pubDate>
		<dc:creator>Laoer</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[keepalived]]></category>
		<category><![CDATA[LVS]]></category>
		<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://i.laoer.com/?p=245</guid>
		<description><![CDATA[LVS（Linux Virtual Server）是章文嵩博士创立的开源项目，可以帮助我们建立高可用性和高扩展性的Linux集群，LVS性能非常好，在暂时不能花费巨资购买F5、NetDispatcher之类硬件的时期，LVS还是能够很好的满足需要的。 LVS的Linux组件IPVS在新版本的Linux内核里已经支持，不需要单独再安装，可以通过命令 lsmod &#124;grep ip_vs 检查内核是否支持IPVS。 ipvsadm是LVS的管理软件，在编译安装的时候要注意，先做一个ln连接，类似 ln -s /usr/src/kernels/2.6.9-42.EL-smp-i686 /usr/src/linux 或 ln -s /usr/src/kernels/2.6.18-8.el5-x86_64 /usr/src/linux keepalived是一个很方便的LVS管理工具，只要需要配置keepalived的配置文件就可以了，不用一条一条的执行ipvsadm命令了。 将keepalived加为服务的方法（keepalived默认安装在/usr/local/etc下） cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/ cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/ mkdir /etc/keepalived cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/ cp /usr/local/sbin/keepalived /usr/sbin/ 关于虚拟IP与真实服务器IP的端口对应问题 在测试中，发现虚拟IP的端口只能和真实服务器IP的端口对应，比如虚拟IP的端口是80，后面对应的真实服务器的端口也只能是80，不能任意配置，真实服务器的端口，让我非常的不解，是我配置错误？还是LVS或keepalived得问题呢？ 在Nginx服务器里也可以实现简单的Load Balance，举例 upstream tomcats { ip_hash; server 127.0.0.1:8080 max_fails=3 fail_timeout=30s; server 127.0.0.1:8280 max_fails=3 fail_timeout=30s; } server { location / [...]]]></description>
			<content:encoded><![CDATA[<p>LVS（<a href="http://www.linuxvirtualserver.org/" target="_blank">Linux Virtual Server</a>）是章文嵩博士创立的开源项目，可以帮助我们建立高可用性和高扩展性的Linux集群，LVS性能非常好，在暂时不能花费巨资购买F5、NetDispatcher之类硬件的时期，LVS还是能够很好的满足需要的。</p>
<p>LVS的Linux组件IPVS在新版本的Linux内核里已经支持，不需要单独再安装，可以通过命令</p>
<p>lsmod |grep ip_vs</p>
<p>检查内核是否支持IPVS。</p>
<p><a href="http://www.linuxvirtualserver.org/software/ipvs.html" target="_blank">ipvsadm</a>是LVS的管理软件，在编译安装的时候要注意，先做一个ln连接，类似</p>
<p>ln -s /usr/src/kernels/2.6.9-42.EL-smp-i686 /usr/src/linux<br />
或<br />
ln -s /usr/src/kernels/2.6.18-8.el5-x86_64 /usr/src/linux</p>
<p><a href="http://www.keepalived.org/" target="_blank">keepalived</a>是一个很方便的LVS管理工具，只要需要配置keepalived的配置文件就可以了，不用一条一条的执行ipvsadm命令了。</p>
<p>将keepalived加为服务的方法（keepalived默认安装在/usr/local/etc下）</p>
<p>cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/<br />
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/<br />
mkdir /etc/keepalived<br />
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/<br />
cp /usr/local/sbin/keepalived /usr/sbin/</p>
<p>关于虚拟IP与真实服务器IP的端口对应问题<br />
在测试中，发现虚拟IP的端口只能和真实服务器IP的端口对应，比如虚拟IP的端口是80，后面对应的真实服务器的端口也只能是80，不能任意配置，真实服务器的端口，让我非常的不解，是我配置错误？还是LVS或keepalived得问题呢？</p>
<p>在Nginx服务器里也可以实现简单的Load Balance，举例</p>
<p>upstream tomcats {<br />
ip_hash;<br />
server 127.0.0.1:8080 max_fails=3 fail_timeout=30s;<br />
server 127.0.0.1:8280 max_fails=3 fail_timeout=30s;<br />
}<br />
server {<br />
location / {<br />
proxy_pass http://tomcats;<br />
}<br />
}</p>
<p>其中，ip_hash的作用在于很据用IP做hash算法，分配到相应的后端服务上，这样的话，用可以基本上固定的分配到某台机子上，就不用担心Session的问题，fail_timeout和max_fails是指在单位时间重试的次数，如果连接不成功，则不会再向其转发请求。</p>
]]></content:encoded>
			<wfw:commentRss>http://i.laoer.com/lvs-keepalived-nginx.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>试用Nginx</title>
		<link>http://i.laoer.com/nginx.html</link>
		<comments>http://i.laoer.com/nginx.html#comments</comments>
		<pubDate>Thu, 05 Mar 2009 02:22:16 +0000</pubDate>
		<dc:creator>Laoer</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://i.laoer.com/?p=137</guid>
		<description><![CDATA[Nginx是一款性能非常强劲的Web服务器，也可以用来做反向代理服务器，现在用Nginx做服务器站点越来越多了。 上图是Nginx和Lighttpd的主机数量比较 最近我试用了一下Nginx，做了一个Nginx+Tomcat的测试，具体步骤如下： groupadd www useradd -g www www wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz wget http://sysoev.ru/nginx/nginx-0.7.39.tar.gz tar zxvf pcre-7.8.tar.gz cd pcre-7.8 ./configure make make install cd .. tar zxvf nginx-0.7.39.tar.gz cd nginx-0.7.39 ./configure &#8211;user=www &#8211;group=www &#8211;prefix=/usr/local/nginx &#8211;with-http_stub_status_module &#8211;with-http_ssl_module make make install cd /usr/local/nginx/conf/ 我们编辑nginx.conf文件，内容如下 user  www www; worker_processes  3; error_log  logs/error.log  notice; pid        logs/nginx.pid; events { use epoll; [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Nginx" href="http://www.nginx.net/" target="_blank">Nginx</a>是一款性能非常强劲的Web服务器，也可以用来做反向代理服务器，现在用Nginx做服务器站点越来越多了。</p>
<p><img class="alignnone size-full wp-image-178" title="netcraft_chart_with_lighttpd" src="http://i.laoer.com/wp-content/uploads/2009/03/netcraft_chart_with_lighttpd.png" alt="netcraft_chart_with_lighttpd" width="300" height="200" /></p>
<p>上图是Nginx和Lighttpd的主机数量比较</p>
<p>最近我试用了一下Nginx，做了一个Nginx+Tomcat的测试，具体步骤如下：</p>
<p>groupadd www<br />
useradd -g www www</p>
<p>wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz<br />
wget http://sysoev.ru/nginx/nginx-0.7.39.tar.gz</p>
<p>tar zxvf pcre-7.8.tar.gz<br />
cd pcre-7.8<br />
./configure<br />
make<br />
make install<br />
cd ..</p>
<p>tar zxvf nginx-0.7.39.tar.gz<br />
cd nginx-0.7.39<br />
./configure &#8211;user=www &#8211;group=www &#8211;prefix=/usr/local/nginx &#8211;with-http_stub_status_module &#8211;with-http_ssl_module<br />
make<br />
make install</p>
<p>cd /usr/local/nginx/conf/</p>
<p>我们编辑nginx.conf文件，内容如下</p>
<p>user  www www;<br />
worker_processes  3;</p>
<p>error_log  logs/error.log  notice;</p>
<p>pid        logs/nginx.pid;</p>
<p>events {<br />
use epoll;<br />
worker_connections  1024;<br />
}</p>
<p>http {<br />
include       mime.types;<br />
default_type  application/octet-stream;</p>
<p>include    /usr/local/nginx/conf/proxy.conf;</p>
<p>log_format  main  &#8216;$remote_addr &#8211; $remote_user [$time_local] “$request” &#8216;<br />
&#8216;”$status” $body_bytes_sent “$http_referer” &#8216;<br />
&#8216;”$http_user_agent” “$http_x_forwarded_for”&#8216;;</p>
<p>#access_log  logs/access.log  main;</p>
<p>sendfile        on;<br />
tcp_nopush     on;</p>
<p>#keepalive_timeout  0;<br />
keepalive_timeout  65;</p>
<p>#gzip  on;</p>
<p>server {<br />
listen       80;<br />
server_name  localhost;</p>
<p>#charset koi8-r;</p>
<p>access_log  logs/localhost.access.log  main;</p>
<p>#location / {<br />
#    root   html;<br />
#    index  index.html index.htm;<br />
#}</p>
<p>location / {<br />
proxy_pass http://localhost:8080;<br />
}</p>
<p>#location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {<br />
#    expires      30d;<br />
#}</p>
<p>#location ~ .*\.(js|css)?$ {<br />
#   expires      1h;<br />
#}</p>
<p>location /NginxStatus {<br />
stub_status             on;<br />
access_log              on;<br />
auth_basic              “NginxStatus”;<br />
}</p>
<p>#error_page  404              /404.html;</p>
<p># redirect server error pages to the static page /50x.html<br />
#<br />
error_page   500 502 503 504  /50x.html;<br />
location = /50x.html {<br />
root   html;<br />
}</p>
<p>}</p>
<p>}</p>
<p>同时我们要在/usr/local/nginx/conf下创建proxy.conf文件，内容如下</p>
<p>proxy_redirect off;<br />
proxy_set_header Host $host;<br />
proxy_set_header X-Real-IP $remote_addr;<br />
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br />
client_max_body_size 10m;<br />
client_body_buffer_size 128k;<br />
proxy_connect_timeout 90;<br />
proxy_send_timeout 90;<br />
proxy_read_timeout 90;<br />
proxy_buffers 32 4k;</p>
<p>保存之后，进入/usr/local/nginx/目录下，执行sbin/nginx，即可启动Nginx。</p>
<p>客户端浏览器输入http://ServerIP，可以看到Tomcat的欢迎页面，证明Ngnix已经转发HTTP请求给后端的Tomcat了，打开http://ServerIP/NginxStatus可以查看Nginx的状态，在Shell下我们还可以查看一下HTTP头</p>
<p>curl -I http://localhost<br />
HTTP/1.1 200 OK<br />
Server: nginx/0.7.39<br />
Date: Thu, 05 Mar 2009 02:08:54 GMT<br />
Content-Type: text/html;charset=ISO-8859-1<br />
Connection: keep-alive<br />
Content-Length: 8132</p>
<p>关于Nginx的配置，还是需要看它的文档<a href="http://wiki.nginx.org/Main" target="_blank">http://wiki.nginx.org/Main</a>，国内张宴的<a href="http://blog.s135.com/post/366.htm" target="_blank">《Nginx 0.7.x + PHP 5.2.8（FastCGI）搭建胜过Apache十倍的Web服务器（第4版）[原创]》</a>非常不错，可以参考。</p>
]]></content:encoded>
			<wfw:commentRss>http://i.laoer.com/nginx.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

