<?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>为IT服务 [龙飞的博客] &#187; location</title>
	<atom:link href="http://226617.cn/archives/tag/location/feed" rel="self" type="application/rss+xml" />
	<link>http://226617.cn</link>
	<description>什么都略懂一点，生活就多彩一些</description>
	<lastBuildDate>Thu, 09 Feb 2012 04:03:10 +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漏洞想到的禁止某个目录执行php权限</title>
		<link>http://226617.cn/archives/839.htm</link>
		<comments>http://226617.cn/archives/839.htm#comments</comments>
		<pubDate>Sat, 22 May 2010 07:13:12 +0000</pubDate>
		<dc:creator>龙飞</dc:creator>
				<category><![CDATA[nginx相关]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://226617.cn/?p=839</guid>
		<description><![CDATA[这次的nginx漏洞可谓是惊天，具体就不说了，详情见 http://www.80sec.com/nginx-securit.html 这漏洞可怕之处就是一旦有用户可以上传的地方如果能把php改后缀方式上传到服务器的话，就能任意执行。 其... ]]></description>
			<content:encoded><![CDATA[<div style="clear:both; margin-top:5px; margin-bottom:5px;"></div><p>这次的nginx漏洞可谓是惊天，具体就不说了，详情见 http://www.80sec.com/nginx-securit.html<br />
这漏洞可怕之处就是一旦有用户可以上传的地方如果能把php改后缀方式上传到服务器的话，就能任意执行。<br />
其实有一个通用的方法可以来避免这种未知漏洞，就是禁止用户上传目录执行php权限。<br />
在apache下面我们可以通过：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;">   &lt;<span style="color: #000000; font-weight:bold;">Directory</span> /website/attachments&gt;
        <span style="color: #00007f;">php_flag</span> engine <span style="color: #0000ff;">off</span>
   &lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;</pre></td></tr></table></div>

<p>的方式来来禁用目录下文件php执行权限。<br />
那么在nginx里面同样可以实现这种方法，那就是location的优先匹配，关于location可以参考我之前的一批文章http://226617.cn/archives/392.htm<br />
这里简单就举个例子</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="nginx" style="font-family:monospace;">   location ^~ /attachments/
   {
      access_log  off;
   }</pre></td></tr></table></div>

<p>这样 attachments这个目录 就不会再去跳转给fastcgi去执行php了</p>
<div style="float:left"><!-- JiaThis Button BEGIN -->
<script type="text/javascript">var jiathis_config = {data_track_clickback:true};</script>
<script type="text/javascript" src="http://v2.jiathis.com/code/jiathis_r.js?move=0&amp;btn=r3.gif&amp;uid=907308" charset="utf-8"></script>
<!-- JiaThis Button END -->|2|left|yes</div><div style="clear:both; margin-top:5px; margin-bottom:5px;"></div>]]></content:encoded>
			<wfw:commentRss>http://226617.cn/archives/839.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx配置文件中的location中文详解</title>
		<link>http://226617.cn/archives/392.htm</link>
		<comments>http://226617.cn/archives/392.htm#comments</comments>
		<pubDate>Thu, 15 Jan 2009 03:46:15 +0000</pubDate>
		<dc:creator>龙飞</dc:creator>
				<category><![CDATA[nginx相关]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://226617.cn/?p=392</guid>
		<description><![CDATA[location 语法:location [=&#124;~&#124;~*&#124;^~] /uri/ { … } 默认:否 上下文:server 这个指令随URL不同而接受不同的结构。你可以配置使用常规字符串和正则表达式。如果使用正则表达式，你必须使用 ~* 前... ]]></description>
			<content:encoded><![CDATA[<div style="clear:both; margin-top:5px; margin-bottom:5px;"></div><p>location</p>
<p>语法:location [=|~|~*|^~] /uri/ { … }<br />
默认:否</p>
<p>上下文:server</p>
<p>这个指令随URL不同而接受不同的结构。你可以配置使用常规字符串和正则表达式。如果使用正则表达式，你必须使用 ~* 前缀选择不区分大小写的匹配或者 ~ 选择区分大小写的匹配。</p>
<p>确定 哪个location 指令匹配一个特定指令，常规字符串第一个测试。常规字符串匹配请求的开始部分并且区分大小写，最明确的匹配将会被使用（查看下文明白 nginx 怎么确定它）。然后正则表达式按照配置文件里的顺序测试。找到第一个比配的正则表达式将停止搜索。如果没有找到匹配的正则表达式，使用常规字符串的结果。</p>
<p>有两个方法修改这个行为。第一个方法是使用 “=”前缀，将只执行严格匹配。如果这个查询匹配，那么将停止搜索并立即处理这个请求。例子：如果经常发生”/”请求，那么使用 “location = /” 将加速处理这个请求。</p>
<p>第二个是使用 ^~ 前缀。如果把这个前缀用于一个常规字符串那么告诉nginx 如果路径匹配那么不测试正则表达式。</p>
<p>而且它重要在于 NGINX 做比较没有 URL 编码，所以如果你有一个 URL 链接’/images/%20/test’ , 那么使用 “images/ /test” 限定location。</p>
<p>总结，指令按下列顺序被接受:<br />
1. = 前缀的指令严格匹配这个查询。如果找到，停止搜索。<br />
2. 剩下的常规字符串，长的在前。如果这个匹配使用 ^~ 前缀，搜索停止。<br />
3. 正则表达式，按配置文件里的顺序。<br />
4. 如果第三步产生匹配，则使用这个结果。否则使用第二步的匹配结果。</p>
<p>例子：</p>
<p>location = / {<br />
# 只匹配 / 查询。<br />
[ configuration A ]<br />
}</p>
<p>location / {<br />
# 匹配任何查询，因为所有请求都已 / 开头。但是正则表达式规则和长的块规则将被优先和查询匹配。<br />
[ configuration B ]<br />
}</p>
<p>location ^~ /images/ {<br />
# 匹配任何已 /images/ 开头的任何查询并且停止搜索。任何正则表达式将不会被测试。<br />
[ configuration C ]<br />
}</p>
<p>location ~* \.(gif|jpg|jpeg)$ {<br />
# 匹配任何已 gif、jpg 或 jpeg 结尾的请求。然而所有 /images/ 目录的请求将使用 Configuration C。<br />
[ configuration D ]<br />
}</p>
<p>例子请求:</p>
<p>/ -> configuration A</p>
<p>/documents/document.html -> configuration B</p>
<p>/images/1.gif -> configuration C</p>
<p>/documents/1.jpg -> configuration D</p>
<p>注意：按任意顺序定义这4个配置结果将仍然一样。</p>
<div style="float:left"><!-- JiaThis Button BEGIN -->
<script type="text/javascript">var jiathis_config = {data_track_clickback:true};</script>
<script type="text/javascript" src="http://v2.jiathis.com/code/jiathis_r.js?move=0&amp;btn=r3.gif&amp;uid=907308" charset="utf-8"></script>
<!-- JiaThis Button END -->|2|left|yes</div><div style="clear:both; margin-top:5px; margin-bottom:5px;"></div>]]></content:encoded>
			<wfw:commentRss>http://226617.cn/archives/392.htm/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

