当前位置: 代码迷 >> Web前端 >> Virtualmin/Webmin配备隔离的虚拟主机
  详细解决方案

Virtualmin/Webmin配备隔离的虚拟主机

热度:378   发布时间:2013-02-28 11:33:09.0
Virtualmin/Webmin配置隔离的虚拟主机

需要实现的目标:

  1. 允许使用PHP、MySQL、FTP,不允许使用SSH登录
  2. FTP目录限制在用户的home目录下
  3. 每一个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   
Administration user Core 3.98.gpl 1 Show domains
Home directory Core 3.98.gpl 1 Show domains
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,这里勾上Active,选择Users' home directories,以及Users' home directories。

限制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_html
php_admin_value open_basedir "${HOME}/public_html:/tmp"
ErrorLog /var/log/virtualmin/${DOM}_error_log
CustomLog /var/log/virtualmin/${DOM}_access_log combined
ScriptAlias /cgi-bin/ ${HOME}/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory ${HOME}/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
<Directory ${HOME}/cgi-bin>
allow from all
AllowOverride 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,各选项默认即可。
检查以下内容:
  1. SSH无法登录
  2. FTP登录后,访问被限制在用户目录下
  3. 上传PHP木马,确定只可访问public_html目录

  相关解决方案