大网数据广告活动
服务器运维问答

Apache2 give access to specific locations (.htaccess file)

· 52CE 我爱测

Could someone help me with making a .htaccess file or how can i limit access to specific locations. All my user accessible files are located in /var/www/website however I also have some more folders like /var/www/website/secrets,…

问题原文

原帖链接 · ACristian24 · CC BY-SA 3.0

Could someone help me with making a .htaccess file or how can i limit access to specific locations.

All my user accessible files are located in /var/www/website however I also have some more folders like /var/www/website/secrets, var/www/website/tools that I want them inaccessible from a web browser.

My main issue is that I have cronjobs executing php scripts from var/www/website/tools and I do not want to deny them access also.

已采纳解答

原帖链接 · Adam V · CC BY-SA 3.0

To block all web access to those directories, in each one just drop an .htaccess file with the following line:

  • Apache 2.4.x:

    Require all denied
    
  • Apache 2.2.x:

    Order deny,allow
    Deny from all
    

This all of course assumes that you have AllowOverride configured such that .htaccess files can be used. If not, then you can place those lines in the virtualhost entry in the global configuration wrapped in something like this:

<Directory "/var/www/website/secrets">
    ...whichever entry from above here....
</Directory>

Also, so long as your crons are invoking the scripts directly (with the PHP binary) and aren't doing silly things like curl's or wget's back to itself, then those .htaccess entries will have no affect on them since it only affects web-based traffic (things coming through Apache).

I would also recommend giving the Apache documentation on this subject matter a read - it really is quite informative and helpful:

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-01-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。