Category Archives: Tomcat

Tomcat配置

场景:

一台主机:IP

一个域名:www.test.com.cn

2个站点: mainsite 和subsite

mainsite访问方式  http://www.test.com.cn

subsite访问方式 http://www.test.com.cn/subsite

配置如下:

tomcat配置文件Server.xml (tomcat安装目录conf文件下)

<Engine name=”Catalina” defaultHost=”localhost”>

<!–For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) –>
<!–
<Cluster className=”org.apache.catalina.ha.tcp.SimpleTcpCluster”/>
–>

<!– Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack –>
<Realm className=”org.apache.catalina.realm.LockOutRealm”>
<!– This Realm uses the UserDatabase configured in the global JNDI
resources under the key “UserDatabase”. Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. –>
<Realm className=”org.apache.catalina.realm.UserDatabaseRealm”
resourceName=”UserDatabase”/>
</Realm>

<Host name=”www.test.com.cn” appBase=”webapps”
unpackWARs=”true” autoDeploy=”true”>
<!–subsite配置 –>
<Context path=”/test” docBase=”subsite”></Context>
<!–mainsite配置 –>
<Context path=”” docBase=”mainsite”></Context>
<!– SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html –>
<!–
<Valve className=”org.apache.catalina.authenticator.SingleSignOn” />
–>

<!– Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern=”common” –>
<Valve className=”org.apache.catalina.valves.AccessLogValve” directory=”logs”
prefix=”localhost_access_log” suffix=”.txt”
pattern=”%h %l %u %t &quot;%r&quot; %s %b” />

</Host>
</Engine>

How to install Tomcat on CentOS

How to Install Tomcat 8 on CentOS 7.0 (Multiple Instances)

https://www.howtoforge.com/how-to-install-tomcat-on-centos-7

Install Oracle Java JDK 8 On CentOS 7

yum install java-1.8.0-openjdk.x86_64

# java -version

# cd /usr/share
# wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.9/bin/apache-tomcat-8.0.9.tar.gz
# tar zxvf apache-tomcat-8.0.9.tar.gz

# groupadd tomcat
# useradd -g tomcat -s /bin/bash -d /usr/share/apache-tomcat-8.0.9 tomcat
# chown -Rf tomcat.tomcat /usr/share/apache-tomcat-8.0.9/

# su – tomcat

$ cd bin
$ ./startup.sh

start the service: sh startup.sh or ./startup.sh

stop the service sh :shutdown.sh or ./shutdown.sh

netstat -an | grep 8080

ps -ef  | grep tomcat

kill

tomcat修改默认端口:

<connector port=”80“protocol=”HTTP/1.1″connectionTimeout=”20000”      redirectPort=”8443″/>

tomcat设置IP地址或者域名访问

<Host name=”www.mydomain.com”  appBase=”webapps”     unpackWARs=”true”/>

SSL免费证书申请:

腾讯云 SSL证书管理

tomcat 配置SSl:

conf/server.xml中

<Connector
protocol=”org.apache.coyote.http11.Http11NioProtocol”
port=”443″ maxThreads=”200″
scheme=”https” secure=”true” SSLEnabled=”true”
keystoreFile=”conf/xxx.jks” keystorePass=”password”
clientAuth=”false” sslProtocol=”TLS”/>