更多請支援: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教學有興趣的朋友有幫助。