欢迎转载,转载时请保留全文及出处。
Apache 2.4.7在CentOS6.4中安装配置反向代理解决单外网IP对应多个内网主机的方法实践
-
Apache安装
-
下载源程序(http://httpd.apache.org/)
[xiaohui@vmCentOS6 Downloads]$ wgethttp://www.eu.apache.org/dist/httpd/httpd-2.4.7.tar.gz
-
解压缩
$su - root
# tar xvf httpd-2.4.7.tar.gz
-
安装编译环境
yum -y install gcc
yum -y install make
yum -y install gcc-c++
-
下载安装apr和pcre
#wgethttp://archive.apache.org/dist/apr/apr-1.5.0.tar.gz
#wgethttp://archive.apache.org/dist/apr/apr-util-1.5.3.tar.gz
wgethttp://nchc.dl.sourceforge.net/project/pcre/pcre/8.32/pcre-8.32.tar.gz
#tar xvfapr-1.5.0.tar.gz
# tar xvfapr-util-1.5.3.tar.gz
# tar -zxvfpcre-8.32.tar.gz
##进入APR目录编译安装apr
# cd apr-1.5.0
# ./configure--prefix=/usr/local/apr
# make &&make install
##进入APR-UTIL目录编译安装apr-util
# cdapr-util-1.5.3
#./configure--prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make &&make install
进入pcre目录编译安装
#cd pcre-8.32
# ./configure
# make &&make install
-
编译安装apache
# cd httpd-2.4.7
# ./configure--prefix=/usr/local/apache --with-apr-util=/usr/local/apr-util
# make &&make install
-
出现/bin/rm:cannot remove `libtoolT’: No such file or directory错误的解决方法
在编译安装apr时运行”#./configure --prefix=/usr/local/apr”可能出现上面的错误提示,这时直接打开configure文件(就在解压的软件包里面),把 $RM “$cfgfile”那行用#注释掉,重新再运行# ./configure --prefix=/usr/local/apr 就可以了。
-
关闭SELINUX
[root@vmCentOS6 ~]# vi /etc/sysconfig/selinux
# This file controls the state ofSELinux on the system.
# SELINUX= can take one of thesethree values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled #改成DISABLED
# SELINUXTYPE= can take one of thesetwo values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
"/etc/sysconfig/selinux"13L, 457C written
[root@vmCentOS6 ~]#
-
关闭防火墙
[root@vmCentOS6 ~]# chkconfig iptables off
-
修改apache配置
# cd /usr/local/apache/conf
# vi httpd.conf
-
在配置文件httpd.conf中启用服务器名称
ServerName 192.168.xxx.xxx #apache服务器本机IP地址
-
反向代理设置
-
在httpd.conf中启用以下模块
LoadModulerewrite_module modules/mod_rewrite.so
LoadModuleproxy_module modules/mod_proxy.so
LoadModuleproxy_http_module modules/mod_proxy_http.so
-
添加需要被反向代理服务器的域名信息
ServerName www.xxxxx.com
ProxyPass / http://www.xxxxx.com
ProxyPassReverse /http://www.xxxxxx.com
-
在/etc/hosts文件中添加DNS信息
192.168.X.X www.xxxxxx.com #ip地址为此域名对应的内网服务器
4.在域名服务商处将外网域名的DNS指向APACHE代理服务器的公网IP
5.以后添加需要反向代理服务器时要做的工作
a)部署WEB应用服务器(使用内网IP)。
b)在APACHE代理服务器httpd.conf文件中添加上述服务器分配的域名信息
c)在APACHE代理服务器hosts文件中添加DNS信息
d)将外网域名解析到APACHE代理的外网IP
三、启用虚拟主机的方法(此步骤与建立反向代理无关,可以不做)
-
在配置文件httpd.conf中启用虚拟主机的配置文件
# Virtual hosts
Includeconf/extra/httpd-vhosts.conf
感谢您的阅读,欢迎光临我的博客,期待与您的交流http://www.cnblogs.com/coffeebox/