Apache实现不同域名访问

环境:CentOS6.2_X64

软件:httpd-2.2.9.tar.gz  mysql     apache-tomcat-6.0.37.tar.gz

需求:通过公网访问不同域名跳转mail_server和 gm_server(java语言)

邮件服务器    192.168.100.95:80端口

GM服务器     192.168.100.95:8080端口

公网IP             49.5.2.211

 

1. 安装apache软件

[root@mail~]# tar -zxvf /data/soft/httpd-2.2.9.tar.gz -C /usr/local/src/

[root@mail~]# cd /usr/local/src/httpd-2.2.9/

[[email protected]]# yum -y install make gcc gcc-c++             #如已安装可忽略

[[email protected]]# ./configure --prefix=/usr/local/apache2 --enable-so--enable-rewrite

[[email protected]]# make ; make install

[[email protected]]# /usr/local/apache2/bin/apachectl start

httpd: Could not reliably determine theserver's fully qualified domain name, using mail.utongame.com for ServerName

#修改配置文件可解决以上报错

[[email protected]]# vi /usr/local/apache2/conf/httpd.conf

#ServerName www.example.com:80

ServerName mail.utongame.com:80

[[email protected]]# /usr/local/apache2/bin/apachectl restart

[[email protected]]# echo "/usr/local/apache2/bin/apachectl start" >>/etc/rc.local

[[email protected]]# netstat -anptl | grep :80

tcp       0      0 :::80         :::*                 LISTEN     21473/httpd

2. 安装mysql软件

[[email protected]]# useradd -M -s /sbin/nologin mysql

[[email protected]]# tar -zxvf /data/soft/mysql-5.0.95.tar.gz -C /usr/local/src/

[[email protected]]# cd /usr/local/src/mysql-5.0.95/

[[email protected]]# ./configure --prefix=/usr/local/mysql ;make ;make install

checking for termcap functions library...configure: error: No curses/termcap library found

#出现以上报错,安装软件包ncurses-devel即可解决

[[email protected]]# yum -y install ncurses-devel

[[email protected]]# cp support-files/my-medium.cnf /etc/my.cnf     

[[email protected]]# /usr/local/mysql/bin/mysql_install_db --user=mysql   #初始化

[[email protected]]# chown -R root:mysql /usr/local/mysql

[[email protected]]# chown -R mysql /usr/local/mysql/var

#添加库文件路径,否则编译安装postfix会提示找不到lmysqlclient

[[email protected]]# vim/etc/ld.so.conf.d/mysql.conf

/usr/local/mysql/lib/mysql/                                      #添加此行

[root@mail mysql-5.0.95]# ldconfig -v |grep mysql

/usr/local/mysql/lib/mysql:

         libmysqlclient.so.15-> libmysqlclient.so.15.0.0

/usr/lib64/mysql:

         libmysqlclient.so.16-> libmysqlclient.so.16.0.0

         libmysqlclient_r.so.16-> libmysqlclient_r.so.16.0.0

[[email protected]]# cp support-files/mysql.server /etc/init.d/mysqld

[[email protected]]# chmod +x /etc/init.d/mysqld

[[email protected]]# chkconfig --add mysqld

[[email protected]]# chkconfig mysqld on

[[email protected]]# service mysqld start

Starting MySQL. SUCCESS!

[[email protected]]# echo "export PATH=$PATH:/usr/local/mysql/bin/">> /etc/profile

[[email protected]]# source /etc/profile

3.  安装JDK环境

[root@mail~]# sh /data/soft/jdk-6u43-linux-x64.bin  

[root@mail~]# echo "exportJAVA_HOME=/data/soft/java/jdk1.6.0_43" >> /etc/profile

[root@mail ~]# echo 'export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH' >> /etc/profile

[root@mail ~]# echo 'exportCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' >> /etc/profile

source /etc/profile

4.  安装tomcat

[root@mail~]# tar zxf /data/soft/apache-tomcat-6.0.37.tar.gz

[root@mail~]# mv apache-tomcat-6.0.37 tomcat6

[root@mail~]# sh /data/soft/tomcat6/bin/startup.sh

注意:

#/data/soft/tomcat6/webapps/目录只留程序yltx目录,ROOT空目录

#也可以保持默认,不删除;

5.  整合apache和tomcat实现代理逆转

# 安装代理模块proxy

[root@mail~]# cd /data/soft/httpd-2.0.59/modules/proxy

[root@mail~]# /usr/local/apache/bin/apxs -c -i -a mod_proxy.c proxy_util.c 

[root@mail~]# /usr/local/apache/bin/apxs -c -i -a mod_proxy_http.c proxy_util.c 

#修改apache配置文件

ServerNamemail.utongame.com

DocumentRoot/usr/local/apache2/htdocs/extmail/html/

ScriptAlias/extmail/cgi/ "/usr/local/apache2/htdocs/extmail/cgi/"

Alias/extmail "/usr/local/apache2/htdocs/extmail/html/"

ScriptAlias/extman/cgi "/usr/local/apache2/htdocs/extman/cgi/"

Alias/extman "/usr/local/apache2/htdocs/extman/html/"


ServerNamegm.utongame.com

ProxyRequestsOff

 

        Order deny,allow

        Allow from all

 

ProxyPass/ http://127.0.0.1:8080/

ProxyPassReverse/ http://127.0.0.1:8080/

ErrorLoglogs/www.error_log

CustomLoglogs/www.access_log common

#重启服务

#映射内网80端口到公网80端口

#DNS服务器解析

#实现访问一下结果

访问mail.xx.com跳转到内网80端口web邮件

访问gm.xx.com跳转到内网8080端口java程序

 

 

 

 

 

 

 

 

 

 

 

 

 



你可能感兴趣的:(WEB)