1024programmer Nginx Apache and nginx prohibit access to specified files or directories

Apache and nginx prohibit access to specified files or directories

Have you tested that after Apache makes the directory prohibited from browsing, the txt file under the directory can still display the contents inside.
For example: http://www.server110.com/linux/ This visit will report a 403 error, but if there are many txt under test, when you visit this txt;
For example: http://www.server110.com/linux/a.txt, at this time all the content in a.txt will be exposed to the outside (sometimes this txt is a very confidential file), so it will not be safe.
Similarly: I also have this problem after Nginx configuration, thanks to the help of NetSeek for the solution of this problem under Apache.

The following is the way to limit this kind of things about Apache and Nginx:

Apache configuration prohibits access
1. Forbid access to certain files/directories
Add Files option to control, such as not allowing access to files with .inc extensions, and protecting php class libraries:
Order allow, deny
Deny from all
Prohibit access to certain specified directories: (can be used for regular matching)
Order allow, deny
Deny from all
Prohibit by file matching, such as prohibiting all access to pictures:
Order allow, deny
Deny from all
Forbidden access for relative URL paths:
Order allow, deny
Deny from all
Prohibit access to certain targets for proxy mode (can be used for regular matching), such as denying access to cnn.com through proxy:
http://cnn.com/*>
Order allow, deny
Deny from all
2. Prohibit certain IP access/only allow certain IP access
If you want to control the prohibition of certain illegal IP access, control in the Directory option:
Order allow, deny
Allow from all
Deny from 10.0.0.1 #block an IP
Deny from 192.168.0.0/24 #block an IP segment
Only certain IPs are allowed to access, for example, internal or cooperative companies are allowed to access:
Order deny, allow
Deny from all
All from server110.com #Allow a certain domain name
All from 10.0.0.1 #Allow an iP
All from 10.0.0.1 10.0.0.2 #Allow multiple iP
Allow from 10.1.0.0/255.255.0.0 #Allow an IP segment, mask pair
All from 10.0.1 192.168 #Allow an IP segment, do not fill in the following
All from 192.168.0.0/24 #Allow an IP segment, network number
Apache: Solution;
Options -Indexes FollowSymLinks
AllowOverride All
Order allow, deny
Deny from all
Nginx: solution;
location ~* .(txt|doc)$ {
if (-f $request_filename) {
root /home/domain/public_html/test;
break;
}
}
Under Nginx, please pay attention to the use of punctuation marks, and don’t miss the following “;”!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/apache-and-nginx-prohibit-access-to-specified-files-or-directories/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索