Virtualmin/Webmin配置隔离的虚拟主机
需要实现的目标:
- 允许使用PHP、MySQL、FTP,不允许使用SSH登录FTP目录限制在用户的home目录下每一个vhost在运行php时不可读取其他目录,防止被挂马后影响其他应用
Virtualmin/Webmin安装
sudo apt-get install webmin webmin-virtual-server
模块设置在System Settings -> Features and Plugins中,关闭不必要的模块。我只保留如下模块:
Feature or Plugin Source Version Domains Default? Actions


Show domains
Show domains
Show domains
Show domains
Show domains
Show domains
Show domains
Show domains
Show domains
Show domains
Show domains
Show domains
Configure | Open
Configure
Configure | Open
Configure | Open
禁止SSH
由于不允许虚拟主机以ssh方式访问,直接在System Customization -> Custom Shells中,保留/bin/false(勾选其enabled, admin, Mailbox, default).
限制FTP根目录在Limits and Validation -> FTP Directory Restrictions,这里
限制php读取目录在System settints -> Edit Server Template中,选择Apache Website,找到Default PHP execution mode,使用mod_php运行。(使用FastCGI模式似乎无法使用php_admin_value配置……)
在Directives and settings for new websites的配置模板中加入一行:php_admin_value open_basedir "${HOME}/public_html:/tmp"
即:
ServerName ${DOM}ServerAlias www.${DOM}DocumentRoot ${HOME}/public_htmlphp_admin_value open_basedir "${HOME}/public_html:/tmp"ErrorLog /var/log/virtualmin/${DOM}_error_logCustomLog /var/log/virtualmin/${DOM}_access_log combinedScriptAlias /cgi-bin/ ${HOME}/cgi-bin/DirectoryIndex index.html index.htm index.php index.php4 index.php5<Directory ${HOME}/public_html>Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatchallow from allAllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch</Directory><Directory ${HOME}/cgi-bin>allow from allAllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch</Directory>
这样就限制了php脚本读取其他文件目录了。另一替代方法是使用apache的mod_chroot,但是只能限制整个apache的运行环境,无法根据vhost分别设置,也不易和virtualmin脚本结合,故舍弃,可以参考这里:http://wiki.ubuntu.org.cn/Apache%E8%AE%BE%E7%BD%AEChroot%E7%8E%AF%E5%A2%83
完成&测试建立一个virtual server,各选项默认即可。检查以下内容:
- SSH无法登录FTP登录后,访问被限制在用户目录下上传PHP木马,确定只可访问public_html目录