Home > Backend Development > PHP Tutorial > nginx configuration prohibits access to directories or files

nginx configuration prohibits access to directories or files

WBOY
Release: 2016-07-29 09:13:46
Original
1957 people have browsed it

Please support for more: http://www.webyang.net/Html/web/article_168.html

Some website systems require users to upload pictures and other files to certain directories. It is inevitable that the program has some loopholes, resulting in Users uploaded php, cgi and other executable files, causing the website to fall into a very difficult situation. At this time, we can use nginx to prohibit users from accessing executable files in these directories.


nginx configuration:
<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>
Copy after login
tips: All php and jsp under the uploads and images directories cannot be accessed.
Some people may also choose to write like this:
<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>
Copy after login
This is the same. If a 403 page is configured, it will jump to it.
403 page configuration:
<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>
Copy after login

There are also some issues that need to be paid attention to, that is, we may place .sql files in any directory of the site. We can prohibit browser access through the following methods.
<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>
Copy after login

In this way, the sql files in any directory will not be accessed by users.

The above introduces nginx configuration to prohibit access to directories or files, including vulnerability aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template