使用mod_proxy改进LAMP 安全

http://tech.ddvip.com   2007年03月04日    社区交流

使用mod_proxy改进LAMP 安全。

# Stuff every Apache configuration needs
LockFile /var/lock/apache/accept.www-data.lock
PidFile /var/run/apache.www-data.pid
ServerName necessaryevil.facade.server
DocumentRoot "/home/www-data"
# Essential modules
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
# Which user to run this Apache configuration as
User www-data
Group www-data
# These must be set else the host isn't passed correctly
UseCanonicalName Off
ProxyVia On
ProxyRequests Off
# This must also be set, though it's only an option in Apache2
ProxyPreserveHost On  
# The IP/port combination to listen on
Listen 9.20.1.1:80
# Using name-based virtual hosting allows you to host multiple sites per IP/port combo
NameVirtualHost 9.20.1.1:80
# Configuration to forward requests for startup.tld
<VirtualHost 9.20.1.1:80>
    ServerName www.startup.tld
    ServerAlias startup.tld
    ProxyPass / http://127.0.0.2:10000/
    ProxyPassReverse / http://127.0.0.2:10000/
    ProxyPassReverse / http://www.startup.tld:10000/
    ProxyPassReverse / http://startup.tld:10000/
</VirtualHost>
# Configuration to forward requests for reckless.tld
<VirtualHost 9.20.1.1:80>
    ServerName www.reckless.tld
    ServerAlias reckless.tld
    ProxyPass / http://127.0.0.2:10001/
    ProxyPassReverse / http://127.0.0.2:10001/
    ProxyPassReverse / http://www.reckless.tld:10001/
    ProxyPassReverse / http://reckless.tld:10001/
</VirtualHost>

  一定要注意这里的 ProxyPreserveHost 指令。这个指令是 Apache 2 提供的,它解决了将正确的 HTTP 头转发给后端服务器的一些问题。因此,强烈建议使用 Apache 2 实例作为 facade 服务器。

  运行示例配置

  根用户应该运行每个配置。Apache 将取得配置文件中指定的特权,并将其用于所有与主机相关的进程。清单 5 说明运行示例的方法。

  清单 5. 启动示例服务器

        /usr/sbin/apache -f /etc/apache/startup.tld.conf
/usr/sbin/apache -f /etc/apache/nimrod.tld.conf
/usr/sbin/apache2 -f /etc/apache2/facade.tld.conf

  mod_proxy 方法的限制

  一定要注意,本文中描述的方法不适用于需要 SSL 连接的域。这是因为 SSL 协议不允许域的虚拟主机。由于这个限制,任何 SSL 主机必须以适当的方式执行,让每个 SSL 域使用它自己的 IP/端口组合。这个限制对所有 Apache 配置都存在,使用这个解决方案的 Apache 也不例外。仍然可以在它们的所有者的用户 ID 下运行 SSL 域。

  结束语

  在本文中,使用 Apache 的 mod_proxy 模块构建了一个环境,在这个环境中有一个门面服务器将请求转发给两个后端服务器。可以对一系列后端服务器采用同样的方法。这种方法使系统管理员能够降低潜在的安全风险,同时保持 PHP 等工具提供的灵活性。

来源:IBM DW中国    作者:Nick Maynard    责编:豆豆技术应用

正在加载评论...