请稍侯

macOS下Tomcat项目的布署及8080端口转发

12 June 2017

macOS下Java Web项目的布署及8080端口转发的配置

下载安装JDK 与 Tomcat

下载JDK8: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

下载Tomcat8: http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.15/bin/apache-tomcat-8.5.15.zip

配置 JAVA_HOME 与 Tomcat

  • 编辑:vi ~/.bash_profile
  • 添加以下命令:
export JAVA_HOME=$(/usr/libexec/java_home)

# Tomcat解压目录
export CATALINA_HOME=~/developer/tomcat-8.5.15

  • 然后执行: source ~/.bash_profile

  • 修改Tomcat bin目录权限,并启动Tomcat

chmod -R 755 ~/developer/tomcat-8.5.15/bin

~/developer/tomcat-8.5.15/bin/startup.sh

  • 配置Tomcat App Manager 与 Host Manager 用户 编辑 Tomcat的config目录下的tomcat-users.xml,在tomcat-users节点下添加以下代码:
  <role rolename="manager-gui"/>
  <role rolename="admin-gui"/>
  <user username="tomcat" password="123456" roles="manager-gui,admin-gui"/>

布署war包

  • 下载demo.war
  • demo.war放到tomcat主目录下,并解压到demo目录下.
  • 配置Tomcat目录下的config/server.xml,在Engine节点下添加一个Host
  <Host name="demo.wodedata.com"  appBase=""
          unpackWARs="true" autoDeploy="true">
          <Context path="" docBase="demo" reloadable="false" privileged="true" debug="0"/>
          <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="demo_access_log" suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  </Host>
  • 修改Tomcat默认监听端口8080改为80
 <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
  • 启动Tomcat
~/developer/tomcat-8.5.15/bin/shutdown.sh
~/developer/tomcat-8.5.15/bin/startup.sh

80 到 8080 端口转发配置

  • 编辑httpd.conf:sudo vi /etc/apache2/httpd.conf
  • 开启httpd-vhosts.conf,去掉前面的注释:Include /private/etc/apache2/extra/httpd-vhosts.conf
  • 开启proxy_module和proxy_http_module,也是去掉前面的注释即可:
LoadModule proxy_module libexec/apache2/mod_proxy.so
LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so
  • 编辑httpd-vhosts.conf,删除没用的VirtalHost配置,添加以下配置:
 <VirtualHost *:80> 
   ProxyPreserveHost On
   ProxyRequests Off
   ServerName demo.wodedata.com
   ServerAlias demo.wodedata.com
   ProxyPass / http://demo.wodedata.com:8080/
   ProxyPassReverse / http://demo.wodedata.com:8080/
 </VirtualHost> 
  • 或者编辑/etc/apache2/users下的对应用户的conf,添加proxy转发即可
ProxyPass / http://demo.wodedata.com:8080/
ProxyPassReverse / http://demo.wodedata.com:8080/