Heim  >  Artikel  >  Backend-Entwicklung  >  用Apache反向代理设置对外的WWW和文件服务器_PHP

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

WBOY
WBOYOriginal
2016-06-01 12:38:31782Durchsuche

Apache


简介:一台机器用专线接入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.comwww.yourdomain.com都指向 
防火墙的外部网卡地址。www.yourdomain.com防问你的公司主页, 用 
http://download.yourdomain.com/pub/...参募略厍?/a> 


你需要在内部网段的apache主机上建立目录/var/log/httpd/download/目录,否则会 
出错。另外,你也可以设置防火墙主机上的/home/httpd/html/index.html的属性为 
750
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:浅谈PHP语法_PHPNächster Artikel:随机头像PHP版_PHP