更多请支持:http://www.webyang.net/Html/web/article_168.html
某些网站系统需要用户上传图片等文件到某些目录下,难免程序有些漏洞,导致用户上传了php、cgi等等可执行的文件,导致网站陷入非常为难的境地. 此时我们可以通过nginx来禁止用户访问这些目录下的可执行文件。
<ol> <li value="1"> <span>location </span><span>~</span><span></span><span>^</span><span>/(uploads|images)/</span><span>.*</span><span>\.</span><span>(</span><span>php</span><span>|</span><span>php5</span><span>|</span><span>jsp</span><span>)</span><span>$ </span><span>{</span> </li> <li> <span> deny all</span><span>;</span> </li> <li><span>}</span></li> </ol>
<ol> <li value="1"> <span>location </span><span>~</span><span></span><span>^</span><span>/(uploads|images)/</span><span>.*</span><span>\.</span><span>(</span><span>php</span><span>|</span><span>php5</span><span>|</span><span>jsp</span><span>)</span><span>$ </span><span>{</span> </li> <li> <span></span><span>return</span><span></span><span>403</span><span>;</span> </li> <li><span>}</span></li> </ol>
<ol><li value="1"> <span>error_page </span><span>403</span><span> http</span><span>:</span><span>//www.webyang.net/public/404.html;</span> </li></ol>
<ol> <li value="1"> <span>location </span><span>~.*</span><span>\.sql </span><span>{</span> </li> <li> <span> deny all</span><span>;</span> </li> <li><span>}</span></li> </ol>
这样,任一目录的sql文件都不会被用户访问到了。
以上就介绍了nginx配置禁止访问目录或文件,包括了漏洞方面的内容,希望对PHP教程有兴趣的朋友有所帮助。