apache搭载多个tomcat

来源:互联网 发布:礼物推荐知乎 编辑:程序博客网 时间:2024/06/05 15:52

在ubuntu环境下

1.下载apache2 ,这里使用apt-get下载安装

apt-get  insall apache2


2.安装tomcat

从网上找可用的tomcat 包,解压即可


3.配置java 环境

apt-get install openjdk-7-jre 

文件大约300多M,下载完成用 java  -version查看版本信息。在这里,我没有配置.bash_profile文件但最好也可以正常运行。


4.加载各种模块

#代理核心模块  
a2enmod proxy  
#代理AJP模块  
a2enmod proxy_ajp  
#代理负载均衡模块  
a2enmod proxy_balancer  
#代理HTTP模块  
a2enmod proxy_http

前面将软件和环境基本安装配置好,下面配置apahce2 文件。apache2 主要有以下几个文件需要配置:

1.envvars文件

把tomcat 文件名和网站名一一对应写好

export  WWW_HOME="/home/root"
export xiexie_ROOT="$WWW_HOME/tomcat8-xiexie/webapps/ROOT"
export nihao_ROOT="$WWW_HOME/tomcat8-nihao/webapps/ROOT"
export 333333_ROOT="$WWW_HOME/tomcat8-33333/webapps/ROOT"


2.sites-available里的conf文件

新建一个001-nihao.conf,这个conf所配置的内容对应的是名字为tomcat8-nihao的那个tomcat


<Directory ${nihao_ROOT}>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
        Options -Indexes
</Directory>

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.

        ServerName nihao.abc.com
        ServerAlias abc.com

        ProxyPass / ajp://127.0.0.1:8009/
        ProxyPassReverse / ajp://127.0.0.1:8009/

        ServerAdmin webmaster@localhost
        DocumentRoot ${nihao_ROOT}

        DirectoryIndex index.html index.htm index.jsp

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/nihao-error.log
        CustomLog ${APACHE_LOG_DIR}/nihao-access.log combined

        #RewriteEngine on

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


3.在 site-enabled文件里创建 site-available 里conf文件的软链接

ln -s ../site-available/001-nihao.conf   001-nihao.conf


关于apache2 的配置就是以上


tomcat的配置

1.在tomcat 目录下修改conf/server.xml

server port 每个tomcat 都要不同防止冲突

<Server port="8025" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />

Connector port  要与apache 里.conf 要对应

<Connector port="8029" protocol="AJP/1.3" URIEncoding="UTF-8" redirectPort="8463" />



配置结束,启动apche和tomcat

0 0