Apache和Tomcat限制文件访问或下载

Apache,在http.conf中的<Directory >里面加入

 

Xml代码 

 收藏代码

  1. <FilesMatch "pattern">  
  2.    Order Deny,Allow  
  3.    Deny from all  
  4. </FilesMatch>  

 

Tomcat,在web.xml里加入

 

Xml代码 

 收藏代码

  1. <security-constraint>  
  2. <display-name>HelloApp Configuration Security Constraint</display-name>  
  3. <web-resource-collection>  
  4. <web-resource-name>Protected Area</web-resource-name>  
  5. <!-- Define the context-relative URL(s) to be protected -->  
  6. <url-pattern>/pattern</url-pattern> <!--可在这里设置要被限制的文件夹-->  
  7. </web-resource-collection>  
  8. <auth-constraint>  
  9. <!-- Anyone with one of the listed roles may access this area -->  
  10. </auth-constraint>  
  11. </security-constraint>