当前位置:Linux教程 - Apache - 用Apache反向代理设置对外的WWW和文件服务器

用Apache反向代理设置对外的WWW和文件服务器



        

    作者:吴阿亭 [中国Linux论坛]

    简介:一台机器用专线接入Internet作为防火墙,在内部网段上有一台WWW服务器 (Redhat 6.1,Apache 1.3.9)希望这台机器能对外提供WWW服务器和基于apache的文件服务。供外部世界公共访问WWW服务器,或者外地分公司下载需要的文件。

    优点: 内部的WWW服务器和文件服务完全与外部世界隔开,不直接连接到外部,通过防火墙上运行的Apache服务提供对内部的代理访问,增强了安全性,同时在防火墙上运行的Apache服务运用基于名字的虚拟主机技术,使得防火墙上的主页不会被访问到。符合了作为防火墙要求运行服务越少越安全的准则。

    实现方法:在内部网段上的Apache服务器(192.168.11.2)存放的是公司主页,供内部和外部用户公共访问,并设置/home/ftp/pub目录为文件存放区域,用http://download.yourdomain.com/pub/来访问。在防火墙上设置apache反向代理技术,由防火墙代理对内部网段上的访问。

    步骤:
    一. 内部网段上的Apache服务器设置
      apache采用默认配置。主目录为/home/httpd/html,主机域名为 sun.yourdomain.com,且别名到www.yourdomain.com, 并且设置srm.conf加一行别名定义如下:
    Alias /pub /home/ftp/pub/

    且更改默认应用程序类型定义如下:
    DefaultType application/octet-stream

    最后在/etc/httpd/conf/access.conf中增加一项定义

    Options Indexes
    AllowOverride AuthConfig
    order allow,deny
    allow from all

    注:Options Indexes允许在找不到index.html文件的情况下允许列出目录/文件列表。AllowOverride AuthConfig允许做基本的用户名和口令验证。这样的话,你需要在/home/ftp/pub目录下放入.htaccess,内容如下:
    -------
    [root@shopu pub]# more .htaccess
    AuthName Branch Office Public Software Download Area
    AuthType Basic
    AuthUserFile /etc/.usrpasswd
    require valid-user
    ------
    然后用#htpasswd -c /etc/.usrpasswd user1
    分别创建不同的允许访问/pub下文件服务的外部用户名和口令。


    二. 防火墙上反向代理配置:
      加下面的行到/etc/httpd/conf/httpd.conf
    NameVirtualHost 1.2.3.4

    # 1.2.3.4是防火墙外部网卡的互联网上永久IP地址


    servername www.yourdomain.com
    errorlog /var/log/httpd/error_log
    transferlog /var/log/httpd/access_log
    rewriteengine on
    proxyrequests off
    usecanonicalname off
    rewriterule ^/(.*)$ http://192.168.11.2/$1 [P,L]



    servername download.yourdomain.com
    errorlog /var/log/httpd/download/error_log
    transferlog /var/log/httpd/download/access_log
    rewriteengine on
    proxyrequests off
    usecanonicalname off
    rewriterule ^/(.*)$ http://192.168.11.2/$1 [P,L]


    注:设置防火墙上的DNS,让download.yourdomain.com和www.yourdomain.com都指向防火墙的外部网卡地址。用www.yourdomain.com防问你的公司主页, 用http://download.yourdomain.com/pub/访问你的公共文件下载区。


      你需要在内部网段的apache主机上建立目录/var/log/httpd/download/目录,否则会出错。另外,你也可以设置防火墙主机上的/home/httpd/html/index.html的属性为750阻止访问,万一外部用户能访问到防火墙上的Apache主页的话。



    发布人:netbull 来自:Linux中文资料