配置需求:apache+tomcat7+多個域名的虛擬主機css
配置環境:騰訊雲、Centos6.3 64位html
所需軟件:java
jdk-7u55-linux-x64.tar.gz apache-tomcat-7.0.50.tar.gz tomcat-connectors-1.2.40-src.tar.gz
配置步驟:mysql
安裝Oracle jdk:見這篇 http://my.oschina.net/freegeek/blog/266413linux
安裝apache (這裏直接使用系統自帶的)sql
安裝mysqlshell
安裝tomcatapache
鏈接apache和tomcat:tomcat
配置虛擬主機目錄服務器
編譯安裝tomcat-connectors
安裝前請查看安裝apache庫文件中又沒有mod_jk.so,我就是使用yum安裝的httpd2.2裏面已經有了mod_jk.so,沒有的話請繼續下面編譯
如下兩步參考了:
http://www.shangxueba.com/jingyan/121949.html
http://www.blogjava.net/pengo/archive/2011/04/15/348331.html
http://blog.chinaunix.net/uid-26881541-id-3338854.html
安裝過程當中可能須要解決安裝依賴,分別安裝
yum install autoconf libtool
若是沒有安裝apache開發工具包,還須要安裝,開發包裏有apxs
yum install httpd-devel.x86_64
經過如下命令編譯鏈接器:
tar zxvf tomcat-connectors-1.2.30-src.tar.gz cd tomcat-connectors-1.2.30-src/native ./buildconf.sh ./configure --with-apxs=/usr/sbin/apxs make make install
將編譯後的庫文件複製到apache庫目錄下:
cp /bmdata/software/tomcat-connectors-1.2.40-src/native/apache-2.0/mod_jk.so
經過yum安裝的apache 模塊庫文件在:/usr/lib64/httpd/modules
解壓安裝的庫文件在:apache2/modules/
詳細配置:
如下配置文件爲/etc/httpd/conf/下
mod_jk.conf
#加載jk鏈接器 LoadModule jk_module modules/mod_jk.so #指定jk鏈接器工做配置文件 JkWorkersFile conf/workers.properties #指定jk鏈接器轉發給tomcat的uri JkMountFile conf/uriworkermap.properties #指定jk鏈接器工做日誌文件 JkLogFile logs/mod_jk.log #指定jk鏈接器日誌級別 JkLogLevel info #指定jk鏈接器日誌格式 JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " #指定哪些請求交給tomcat處理 #"worker1"爲在workers.properties裏指定的tomcat JkMount /* worker1
workers.properties
#tomcat列表 worker.list=worker1 #tomcat與apache通訊協議 worker.worker1.type=ajp13 #ajp13 端口號 worker.worker1.port=8009 #tomcat的主機地址,如不爲本機,請填寫ip地址 worker.worker1.host=localhost
uriworkermap.properties
/*=worker1 !/*.gif=worker1 !/*.jpg=worker1 !/*.png=worker1 !/*.css=worker1 !/*.js=worker1 !/*.htm=worker1 !/*.html=worker1
tomcat配置文件:
server.xml
......... <Host name="weixin.banmacoffee.com" appBase="/data/www/weixin.banmacoffee.com" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="" docBase="banmacoffee" reloadable="true" /> </Host> </Engine> </Service> </Server>
httpd文件,採用騰訊雲CentOs6.3 64位中原裝httpd服務器的http.conf文件修改而來:
httpd.conf
Include conf.d/*.conf Include conf/mod_jk.conf ...... #ServerName www.example.com:80 NameVirtualHost *:80 <VirtualHost *:80> ServerName weixin.banmacoffee.com DocumentRoot /data/www/weixin.banmacoffee.com <Directory "/data/www/weixin.banmacoffee.com"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> ErrorLog logs/weixin.banmacoffee.com-error_log CustomLog logs/weixin.banmacoffee.com-access_log common JkMount /* worker1 </VirtualHost> <VirtualHost *:80> ServerAdmin banmacoffee.com DocumentRoot /data/www/banmacoffee.com ServerName banmacoffee.com ErrorLog logs/banmacoffee.com-error_log CustomLog logs/banmacoffee.com-access_log common </VirtualHost>
[參考文獻]
http://www.neoease.com/apache-virtual-host/