📄 1281.html
字号:
name=header_r2_c1></TD>
<TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colSpan=5>
<DIV align=right><FONT class=normalfont>当前位置:
<A href="index.html" tppabs="http://www.linuxhero.com/docs/index.html">本站首页</A>
<font color="#FF6699">>></font>
<A href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</A> | <A href="copyright.html" tppabs="http://www.linuxhero.com/docs/copyright.html">版权说明</A></font></DIV>
</TD>
<TD><IMG height=22 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1
border=0></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=10 cellPadding=0 width="100%" bgColor=#ffffff
border=0>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%" border=0>
<TR>
<TD vAlign=top align=middle width="60%">
<TABLE cellSpacing=0 cellPadding=0 width="100%"
background="images/back.gif" tppabs="http://www.linuxhero.com/docs/images/back.gif" border=0>
<TBODY>
<TR>
<TD vAlign=top width="80%">
<DIV align=center>
<FORM action="search.html" tppabs="http://www.linuxhero.com/docs/search.html" method=get>
</FORM>
<TABLE cellSpacing=0 cellPadding=0 width="95%"
border=0><TBODY>
<TR>
<TD background="images/bgi.gif" tppabs="http://www.linuxhero.com/docs/images/bgi.gif"
height=30></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=3 width="95%"
align=center border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%"
border=0>
<TBODY>
<TR>
<TD vAlign=top>
<p><FONT class=normalfont><B><font color=blue>Linux防火墙上的Apache反向代理</font></B></FONT><BR><FONT class=smallfont color=#ff9900>2004-04-23 15:18 pm</FONT><BR><FONT class=normalfont>作者:作者<br>来自:Linux知识宝库<br>联系方式:无名<br><br>---- 本文着重介绍在企业防火墙上安装具有代理和重写规则功能的Web服务器——Apache的方法,以及编译和设置Apache的具体步骤。在成功安装后,弹性的虚拟主机设置可以允许外部用户通过防火墙访问内部局域网上多个Web服务器。<br>
<br>
一、测试环境与网络结构<br>
<br>
---- 本文所使用的测试环境是Redhat Linux 7.2、Apache 1.3.24,公司域名假设是company.com。公司的典型网络构造如附图所示。<br>
<br>
<br>
<br>
<br>
---- 注意: 附图中的防火墙上安装了2块网卡,其中e0端口的外部公共地址为1.2.3.4,e1端口对应内部保留地址为192.168.2.1。局域网内部有3台Web服务器A、B和C,它们对应的域名分别为weba.company.com、webb.company.com和webc.company.com,均使用内部保留地址。<br>
<br>
二、操作步骤<br>
<br>
---- 如附图所示,此公司通过专线连入互联网,安装了防火墙,局域网内部有3台Web服务器,均只有内部保留地址,但是希望他们能够提供对外的Web服务。<br>
<br>
---- 1.设置DNS<br>
---- 在防火墙(同时也是公司的DNS服务器)上设置内部3台Web服务器的DNS,IP地址均为1.2.3.4。这样,在Internet上解析weba.company.com、webb.company.com 和webc.company.com时,均指向同一IP地址即防火墙的外部接口地址1.2.3.4。<br>
<br>
---- 2.下载Apache<br>
---- 从Apache网站(http://www.apache.org)下载目前最新的版本apache 1.3.24到/root目录,下载地址为http://www.apache.org/dist/httpd/apache_1.3.24.tar.gz。<br>
<br>
---- 3. 更改源代码使最大允许的请求连接数超过256<br>
---- 由于Apache默认允许的最多连接数为256,而在一个繁忙的网站上这一连接数量也许不能满足需要,特别是本文介绍的通过防火墙上的Apache反向代理允许外部用户访问多个内部Web服务器的情况,可以采用更改src/include/httpd.h文件的方法,具体步骤如下。<br>
<br>
#cd/root 切换目录到/root下<br>
#tar xvfz apache_1.3.24.tar.gz 解开apache源文件到/root下<br>
#cd apache_1.3.24 进入apache_1.3.24目录<br>
#vi src/include/httpd.h 用vi编辑httpd.h文件<br>
---- 在输入“vi src/include/httpd.h”命令后,继续输入“/256”并按“回车”键搜索数字256,将其改为1024后保存并退出即可。<br>
<br>
---- 注意事项:<br>
<br>
---- ①要支持最多为1024个客户的同时请求,不仅需要更改上面提到的源文件,在编译安装后还需要设置/usr/local/apache/conf/httpd.conf文件,将其中的“MaxClients”一行后面的参数更改为“1024”。<br>
<br>
---- ②如果您仅仅为了进行测试,或者不会有很多人使用,可以不修改httpd.h文件。<br>
<br>
---- 4. 编译Apache<br>
---- 编译代码如代码1所示。<br>
<br>
代码1<br>
#cd apache_1.3.24<br>
#./configure --prefix=/usr/local/apache<br>
--enable-module=most<br>
--enable-shared=max<br>
--enable-module=proxy<br>
--enable-shared=proxy<br>
--enable-module=rewrite<br>
--enable-shared=rewrite 设置安装默认目录<br>
编译大多数模块<br>
设置模块为DSO(动态共享对象)模式<br>
启动代理模块<br>
安装代理模块为DSO模式<br>
启动重写功能模块<br>
安装重写功能模块为DSO模式<br>
<br>
<br>
---- 注意: 在编译Apache的时候,必须编译大多数模块,并将它们设置为DSO模式,同时启动proxy和rewrite模块,同时也将其设置为DSO模式。<br>
---- #make<br>
---- #make install<br>
<br>
---- 将安装所有Apache所需文件到/usr/local/apache目录下。<br>
<br>
---- 5.在httpd.conf文件中设置基于域名的虚拟主机<br>
---- 在/usr/local/apache目录找到httpd.conf文件,并将下面的内容添加至此文件后。<br>
<br>
NameVirtualHost 1.2.3.4:80<br>
< VirtualHost 1.2.3.4:80 ><br>
ServerAdmin root@company.com<br>
DocumentRoot /usr/local/apache/htdocs<br>
ServerName default.company.com<br>
ErrorLog /usr/local/apache_http/logs/error_log<br>
CustomLog /usr/local/apache_http/logs/access_log combined<br>
UseCanonicalName Off<br>
ProxyRequests Off<br>
RewriteEngine on<br>
RewriteCond %{HTTP_HOST}.*.company.com$<br>
RewriteRule ^/(.*)$ http://%{HTTP_HOST}/$1 [P,L]<br>
< /VirtualHost ><br>
---- 注意事项:<br>
<br>
---- ①上面设置了基于域名的反向代理虚拟主机,这样当您从外部访问IP地址为1.2.3.4的主机,且URL地址后面部分的域名为“company.com”,Apache就可以把用户的请求转发到局域网内部的Web服务器上,并重写响应数据包去掉代理协议部分。<br>
<br>
---- ②“ServerName”一行可以任意指定。<br>
<br>
---- ③“ProxyRequest Off”一行用来禁止Apache在IP地址为1.2.3.4的主机和端口80上进行代理服务,在这里Apache作为一个透明的代理服务器来使用。<br>
<br>
---- ④“RewriteEngine on”一行用来启动Apache修改响应数据包的功能,否则下面的“RewriteCond”和“RewriteRule”将不起作用。<br>
<br>
---- 6.添加记录进入/etc/hosts文件<br>
---- 在上面的虚拟主机重写规则中,重写后的URL与您所请求的URL是一样的,我们的设想是将下面3个域名放到防火墙的/etc/hosts文件中,这样Apache将从内部3台Web服务器获得内容,并返回给外部用户,域名对应记录如下。<br>
<br>
---- 192.168.2.2 weba.company.com<br>
---- 192.168.2.3 webb.company.com<br>
---- 192.168.2.4 webc.company.com<br>
<br>
三、总结<br>
<br>
---- 这样,当外部用户访问http://weba.company.com时,请求被送到防火墙的Apache上,而防火墙上的Apache反向代理将根据/etc/hosts文件中定义的记录直接从IP地址为192.168.2.2的Web服务器获取内容并返回给外部用户,从而完成内部Web服务器weba.company.com对外提供访问的功能。<br>
<br>
---- 在对Apache配置完毕后,如果还需要增加更多的内部Web服务器来提供外部访问服务,只需设置其DNS服务器的IP地址为1.2.3.4,并在/etc/hosts文件中增加相应记录即可。<br>
[img][/img]
</FONT><br>
</TD>
</TR>
<TR>
<TD colSpan=2><FONT
class=middlefont></FONT><BR>
<FONT
class=normalfont>全文结束</FONT> </TD>
</TR>
<TR>
<TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2
height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
<TD vAlign=top width="20%"
background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2>
<DIV align=center>
<table class=tableoutline cellspacing=1 cellpadding=4
width="100%" align=center border=0>
<tr class=firstalt>
<td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
<font class=normalfont><b>所有分类</b></font></td>
</tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td> </tr> </table></td></tr> </table>
</DIV></TD></TR>
<TR vAlign=top>
<TD width="80%">
<DIV align=center><BR>
</DIV>
</TD></TR></TBODY></TABLE></TD></TR>
</TABLE></TD></TR>
</TABLE>
<TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee
border=0><TBODY>
<TR>
<TD width="50%">
<P><FONT class=middlefont>版权所有 © 2004 <A
href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
违者必究. </FONT></P>
</TD>
<TD width="50%">
<DIV align=right><FONT class=middlefont>Powered by: <A
href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
</TD></TR></TBODY></TABLE>
<CENTER></CENTER></TD></TR>
</TABLE></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -