<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>百里挑一</title> 
<link>http://www.admin99.net/index.php</link> 
<description>linux命令 &#124; seo优化技术 &#124; linux系统管理员指南 --我的学习园地</description> 
<language>zh-cn</language> 
<copyright>Powered by Bo-blog 2.0.2 sp2</copyright>
<item>
<link>http://www.admin99.net/read.php?484</link>
<title>用nginx做反向代理和缓存并且能让apache服务器得到真实的客户端地址</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>nginx</category>
<pubDate>Thu, 29 Jul 2010 09:50:49 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?484</guid> 
<description>
<![CDATA[ 
	需求<br/>一个网站，客户主要分布在亚洲其它国家和地区，如日本台湾新加坡马来西亚印度香港等。而服务器放在上海。国外用户访问速度不快。现在需要提高国外用户的访问速度。<br/>最终定下来的方案，就是在多个国家租用最便宜的vps做反向代理和缓存，通过智能解析把不同国家的访问定位到不通的vps上。这个简单来说就是自己做了个cdn网络。这个方案里涉及到很多问题。比如各vps的健康检查和故障转移。这里只讨论用nginx做反向代理和缓存的几个问题<br/>环境<br/>1.国外vps一台，运行nginx，做缓存和反向代理<br/>2.国内服务器一台，运行apache，运行一个php＋mysql开发的站点<br/>vps上nginx的配置<br/>nginx用nginx-0.7.67.tar.gz<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">cd /usr/src<br/>wget http://nginx.org/download/nginx-0.7.67.tar.gz<br/>tar xzf nginx-0.7.67.tar.gz<br/>cd nginx-0.7.67<br/>./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_realip_module<br/>make<br/>make install</div></div><br/>配置文件的主要部分如下<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"> &nbsp; &nbsp;proxy_temp_path &nbsp; /data/nginx_proxy_temp;<br/> &nbsp; &nbsp;proxy_cache_path /data/nginx_proxy_cache levels=1:2 keys_zone=cache:50m inactive=1d max_size=3000m;<br/> &nbsp; &nbsp;upstream back_end {<br/> &nbsp; &nbsp; &nbsp; &nbsp;server 192.168.0.2:80;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;server {<br/> &nbsp; &nbsp; &nbsp; &nbsp;listen 80;<br/> &nbsp; &nbsp; &nbsp; &nbsp;server_name www.admin99.net;<br/> &nbsp; &nbsp; &nbsp; &nbsp;location / {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_cache cache;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_cache_valid &nbsp;200 304 12h;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_cache_key $host$uri$is_args$args;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header Host &nbsp;$host;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header X-Real-IP $remote_addr;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_pass http://back_end;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; expires &nbsp; &nbsp; &nbsp;1d;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;location ~ .*&#92;.(php&#124;html)?$<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header Host &nbsp;$host;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header X-Real-IP $remote_addr;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_pass http://back_end;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}</div></div><br/>apache用的是2.0.63 为了能得到用户的真实ip，在编译好之后，要增加一个模块mod_rpaf<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">cd /usr/src<br/>wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz<br/>tar xzf mod_rpaf-0.6.tar.gz<br/>cd mod_rpaf-0.6<br/>/usr/local/apache/bin/apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c</div></div><br/>在apache的配置文件中加上一段<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">LoadModule rpaf_module modules/mod_rpaf-2.0.so<br/>RPAFenable On<br/>RPAFsethostname On<br/>RPAFproxy_ips 192.168.0.1<br/>RPAFheader X-Forwarded-For</div></div><br/>这样就能看到访问者的真实ip<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=nginx" rel="tag">nginx</a> , <a href="http://www.admin99.net/tag.php?tag=apache" rel="tag">apache</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?477</link>
<title>关于最新的nginx漏洞</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>nginx</category>
<pubDate>Fri, 21 May 2010 09:08:36 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?477</guid> 
<description>
<![CDATA[ 
	20号晚上nginx爆了一个漏洞，网上没有说攻击方式，可能是攻击方式太简单别人不屑于说了。<br/>简单测试了一下，果然很简单就可以执行一个伪装成.jpg或者.png的php木马<br/>目前官方没有补丁，补救的办法是临时把原来的<br/> &nbsp; &nbsp; &nbsp; &nbsp;location ~ .*&#92;.php?$<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fastcgi_pass &nbsp;unix:/tmp/php-cgi.sock;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/>改成<br/> &nbsp; &nbsp; &nbsp; &nbsp;location ~ .*&#92;.php?$<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fastcgi_pass &nbsp;unix:/tmp/php-cgi.sock;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ( $fastcgi_script_name ~ &#92;..*&#92;/.*php ) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return 403;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=nginx" rel="tag">nginx</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?468</link>
<title>安装nginx0.8.20</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>nginx</category>
<pubDate>Sun, 21 Mar 2010 01:41:32 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?468</guid> 
<description>
<![CDATA[ 
	nginx最新版本是nginx 0.8.20<br/>下载地址是 http://sysoev.ru/nginx/nginx-0.8.20.tar.gz<br/><br/>安装nginx之前需要确认系统中已经安装了 pcre以及pcre-devel，默认情况下系统里是没有安装pcre-devel的，centos系统可以通过 yum install pcre-devel来安装，redhat系统可以在安装盘中找到相应的pcre-devel的rpm包，安装即可。<br/>安装过程很简单<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">cd /usr/src<br/>wget http://sysoev.ru/nginx/nginx-0.8.20.tar.gz<br/>tar xzvf nginx-0.8.20.tar.gz<br/>cd nginx-0.8.20<br/>./configure --prefix=/usr/local/nginx --with-http_stub_status_module<br/>make<br/>make install</div></div><br/>其中 --with-http_stub_status_module 这个module可以实时查看nginx的运行状态<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=nginx" rel="tag">nginx</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?461</link>
<title>nginx中虚拟目录的配置</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>nginx</category>
<pubDate>Tue, 19 Jan 2010 09:13:50 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?461</guid> 
<description>
<![CDATA[ 
	location /abc/ {<br/>alias /home/html/abc/;<br/>}<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=nginx" rel="tag">nginx</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?460</link>
<title>nginx 301 重定向</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>nginx</category>
<pubDate>Tue, 19 Jan 2010 09:13:09 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?460</guid> 
<description>
<![CDATA[ 
	server {<br/> &nbsp; &nbsp;server_name admin99.net www.admin99.net;<br/><br/> &nbsp; &nbsp;if ($host != 'admin99.net' ) {<br/> &nbsp; &nbsp; &nbsp; &nbsp;rewrite &nbsp;^/(.*)$ &nbsp;http://admin99.net/$1 &nbsp;permanent;<br/> &nbsp; &nbsp;}<br/>}<br/><br/>另一种连二级域名和泛域名一起跳转的配置如下<br/> &nbsp; &nbsp; &nbsp; &nbsp;if ( $http_host ~ "^(.*)&#92;.admin99&#92;.net$" ) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set $name $1;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rewrite &nbsp;^ &nbsp;http://$name.test.cn$request_uri permanent;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=nginx" rel="tag">nginx</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?448</link>
<title>nginx 目录验证</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>nginx</category>
<pubDate>Thu, 27 Aug 2009 04:15:17 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?448</guid> 
<description>
<![CDATA[ 
	htpasswd -c /usr/local/nginx/conf/htpasswd admin99<br/>New password: &nbsp; (此处输入你的密码)<br/>Re-type new password: &nbsp; (再次输入你的密码)<br/>Adding password for user <br/><br/>location ~ ^/test/ &nbsp;{<br/> &nbsp; &nbsp; &nbsp; root &nbsp; &nbsp;/data/htdocs/test;<br/> &nbsp; &nbsp; &nbsp; auth_basic &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"input your username and password";<br/> &nbsp; &nbsp; &nbsp; auth_basic_user_file &nbsp;/usr/local/nginx/conf/htpasswd;<br/>}<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=nginx" rel="tag">nginx</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?445</link>
<title>nginx针对某一目录限制ip</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>nginx</category>
<pubDate>Wed, 29 Jul 2009 07:47:45 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?445</guid> 
<description>
<![CDATA[ 
	不如apache方便<br/>以nginx+factcgi的配置为例<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"> &nbsp; &nbsp; &nbsp; &nbsp;location ~ ^/adpanel/<br/> &nbsp; &nbsp; &nbsp; &nbsp; {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; allow 192.168.0.10;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deny all;<br/> &nbsp; &nbsp; &nbsp; &nbsp; }<br/> &nbsp; &nbsp; &nbsp; &nbsp;location ~ ^/adpanel/.*&#92;.php$<br/> &nbsp; &nbsp; &nbsp; &nbsp; {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; allow 192.168.0.10;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deny all;<br/> &nbsp; &nbsp; &nbsp; &nbsp; fastcgi_pass &nbsp;unix:/tmp/php-cgi.sock;<br/> &nbsp; &nbsp; &nbsp; &nbsp; }</div></div><br/>必须要配两个location，要不然php文件仍然能访问。因为根据nginx的逻辑，正则表达式的优先级比较高<br/>还没找到更好的方式<br/>如果是想要在虚拟主机层面来封ip，比如 www.admin99.net封锁全部美国的ip，那么，不再需要location{}表达式，直接把deny或者allow指令写在server{}中即可<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=nginx" rel="tag">nginx</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?422</link>
<title>nginx 报错 413 request entity too large</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>nginx</category>
<pubDate>Tue, 21 Apr 2009 03:27:44 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?422</guid> 
<description>
<![CDATA[ 
	上传文件的时候，nginx报错<br/>413 request entity too large<br/>因为上传的文件超出了nginx的上传文件大小的限制<br/>默认是1M，需要增大的话。<br/>在nginx.conf中增加一句<br/>client_max_body_size 30m;<br/>重启即可<br/>30m表示最大上传30M，需要多大设置多大。<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=nginx" rel="tag">nginx</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?418</link>
<title>nginx 502 bad gateway 错误的原因及几个可能性</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>nginx</category>
<pubDate>Wed, 08 Apr 2009 03:40:59 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?418</guid> 
<description>
<![CDATA[ 
	从http://www.jefflei.com/post/1049.html转载，备忘<br/><br/>NGINX 502 Bad Gateway错误是FastCGI有问题，造成NGINX 502错误的可能性比较多。将网上找到的一些和502 Bad Gateway错误有关的问题和排查方法列一下，先从FastCGI配置入手：<br/><br/>1.FastCGI进程是否已经启动<br/><br/>2.FastCGI worker进程数是否不够<br/>运行 netstat -anpo &#124; grep "php-cgi" &#124; wc -l 判断是否接近FastCGI进程，接近配置文件中设置的数值，表明worker进程数设置太少<br/>参见：http://blog.s135.com/post/361.htm<br/><br/>3.FastCGI执行时间过长<br/>根据实际情况调高以下参数值<br/>fastcgi_connect_timeout 300;<br/>fastcgi_send_timeout 300;<br/>fastcgi_read_timeout 300;<br/><br/>4.FastCGI Buffer不够<br/>nginx和apache一样，有前端缓冲限制，可以调整缓冲参数<br/>fastcgi_buffer_size 32k;<br/>fastcgi_buffers 8 32k;<br/>参见：http://www.hiadmin.com/nginx-502-gateway-error%E4%B8%80%E4%BE%8B/<br/><br/>5.Proxy Buffer不够<br/>如果你用了Proxying，调整<br/>proxy_buffer_size &nbsp;16k;<br/>proxy_buffers &nbsp; &nbsp; &nbsp;4 16k;<br/>参见：http://www.ruby-forum.com/topic/169040<br/><br/>6.https转发配置错误<br/>正确的配置方法<br/>server_name www.mydomain.com;<br/>location /myproj/repos {<br/>set $fixed_destination $http_destination;<br/>if ( $http_destination ~* ^https(.*)$ )<br/>{<br/>set $fixed_destination http$1;<br/>}<br/>proxy_set_header Host $host;<br/>proxy_set_header X-Real-IP $remote_addr;<br/>proxy_set_header Destination $fixed_destination;<br/>proxy_pass http://subversion_hosts;<br/>}<br/>参见：http://www.ruby-forum.com/topic/169040<br/><br/>当然，还要看你后端用的是哪种类型的FastCGI，我用过的有php-fpm，流量约为单台机器500万PV(动态页面), 现在基本上没有碰到502。<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=nginx" rel="tag">nginx</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?417</link>
<title>nginx 400 bad request 错误的原因和解决办法</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>nginx</category>
<pubDate>Wed, 08 Apr 2009 03:36:35 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?417</guid> 
<description>
<![CDATA[ 
	从http://www.bsdlover.cn/html/39/n-1939.html转载，备忘<br/><br/><br/>经长时间观察和大量试验查明，是request header过大所引起，request过大，通常是由于cookie中写入了较大的值所引起。<br/>所幸在nginx中是有办法解决这个问题：<br/>在nginx.conf中，将client_header_buffer_size和large_client_header_buffers都调大，可缓解此问题。<br/>其中主要配置是client_header_buffer_size这一项，默认是1k，所以header小于1k的话是不会出现问题的。<br/>按我现在配置是：<br/>client_header_buffer_size 16k;<br/>large_client_header_buffers 4 64k;<br/>这个配置可接收16k以下的header，在浏览器中cookie的字节数上限会非常大，所以实在是不好去使用那最大值。<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=nginx" rel="tag">nginx</a>
  ]]> 
</description>
</item>
</channel>
</rss>