【发布时间】:2023-04-08 13:59:01
【问题描述】:
这是我的虚拟主机配置文件
<VirtualHost *:80>
ServerAdmin yo@my-domain.tld
ServerName my-domain.tld
ServerAlias www.my-domain.tld
DocumentRoot /home/my-domain/public_html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/my-domain/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
我想使用 .htaccess 在 /home/my-domain/public_html/uploads 文件夹中禁用脚本执行;已经尝试过
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI
然后
AddType text/plain .html .htm .shtml .php .php3 .phtml .phtm .pl .py .cgi .js
然后
<Files ^(*.jpeg|*.jpg|*.png|*.gif)>
order deny,allow
deny from all
</Files>
以及我发现的所有其他指令,但它们都不能阻止脚本执行。
apachectl -t -D DUMP_MODULES 表示 mime_module 已启用并已加载
php_flag engine off 是唯一阻止 php 文件执行的指令,但其他类型呢?以及为什么其他 apache 指令不起作用。有什么想法...?
【问题讨论】:
-
这里可能是错的,但我还是会问:改变你对目录的执行权限不会解决问题吗?
-
已经有执行权限。无论如何,谢谢。
-
我以为您想禁用脚本执行,难道关闭脚本执行不正是您在 .htaccess 中尝试执行的操作吗?抱歉,如果我遗漏了什么:-)
-
我明白你的意思,但如果目录没有执行权限,Apache 根本无法访问它。刚刚试了一下。
-
如果你省略了执行权限,Apache 会用'Forbidden - 403' 消息打招呼:) 它甚至无法在该目录中读/写。换句话说,我需要该目录是可写的,但我想阻止脚本执行,以防有人上传任何恶意脚本/代码。
标签: apache .htaccess security addhandler