轉載自 https://www.zfl9.com/tomcat.htmlphp
Tomcat是一個開放源代碼、運行servlet和JSP Web應用軟件的基於Java的Web應用軟件容器;
隨着Catalina Servlet引擎的出現,Tomcat第四版號的性能獲得提高,使得它成爲一個值得考慮的Servlet/JSP容器,所以目前許多WEB服務器都是採用Tomcathtml
java環境配置
SunJDK for Linux 配置java
tomcat8.5
-
-
-
-
tar xf tomcat.tar.gz -C /opt/tomcat/
-
-
-
export CATALINA_HOME=/opt/tomcat
-
export PATH=$PATH:$CATALINA_HOME/bin
-
-
-
-
-
-
-
-
熱部署
-
-
-
-
-
-
-
-
-
-
-
<Engine name="Catalina" defaultHost="localhost">
-
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
-
<Context debug="0" docBase="/opt/webapps/blog" path="/blog" privileged="true" reloadable="true"/>
-
-
-
-
-
3. conf/Catalina/localhost/apps.xml
-
<?xml version="1.0" encoding="UTF-8"?>
-
<Context docBase="/opt/webapps/blog" reloadable="true" />
-
-
基於域名的虛擬主機
-
-
<Host name="www.zfl.com" appBase="/opt/webapps/www.zfl.com" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
-
<Context docBase="/opt/webapps/www.zfl.com/www" path="" reloadable="true" />
-
-
<Host name="blog.zfl.com" appBase="/opt/webapps/blog.zfl.com" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
-
<Context docBase="/opt/webapps/blog.zfl.com/blog" path="" reloadable="true" />
-
-
-
-
-
apache + tomcat
-
-
-
-
-
cd /usr/local/src/mod_jk/native/
-
./configure --with-apxs
=/opt/www/httpd/bin/apxs
-
-
libtool --finish /opt/www/httpd/modules/
-
-
-
-
cp -af httpd-jk.conf /opt/www/httpd/conf/extra/
-
cp -af uriworkermap.properties /opt/www/httpd/conf/extra/
-
cp -af workers.properties /opt/www/httpd/conf/
-
-
-
-
-
Include conf/extra/httpd-jk.conf
-
AddType application/x-httpd-jsp .jsp
-
-
-
--- conf/extra/httpd-jk.conf ---
-
LoadModule jk_module modules/mod_jk.so
-
-
JkWorkersFile conf/workers.properties
-
JkLogFile logs/mod_jk.log
-
-
JkShmFile logs/mod_jk.shm
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
--- conf/workers.properties ---
-
worker.template.type
=ajp13
-
worker.template.socket_connect_timeout
=5000
-
worker.template.socket_keepalive
=true
-
worker.template.ping_mode
=A
-
worker.template.ping_timeout
=10000
-
worker.template.connection_pool_minsize
=0
-
worker.template.connection_pool_timeout
=600
-
worker.template.reply_timeout
=300000
-
worker.template.recovery_options
=3
-
-
-
-
-
-
-
-
-
-
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
-
<Context path="" docBase="/opt/www/httpd/htdocs" debug="0"/>
-
-
-
-
-
-
-
-
--- /opt/www/httpd/htdocs/test.jsp ---
-
<%@page language="java" import="java.util.*" %>
-
Stay hungry Stay foolish
!!!
-
Now the
time is: <%out.println(new Date());%>
-
nginx + tomcat
-
-
-
-
server_name www.zfl.com
;
-
root /opt/www/nginx/html
;
-
index index.jsp index.php index.html
;
-
-
fastcgi_pass 127.0.0.1:9000
;
-
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
-
-
-
-
-
-
proxy_set_header Host
$host;
-
proxy_set_header X-Real-IP
$remote_addr;
-
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
-
-
-
自定義錯誤頁
-
-
-
-
-
<error-code>404</error-code>
-
<location>/404.html</location>
-
-
-
-
https相關
keytool用法nginx
-
-
keytool -genkey -keyalg RSA -validity 3650 -
alias tomcat -keystore tomcat.jks -storepass 123456 -keypass 123456 -dname "cn=www.zfl.com,ou=otokaze,o=otokaze,l=gd,st=gz,c=cn"
-
-
-
-
-
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />
-
-
-
<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true">
-
-
-
certificateKeystoreFile
="/etc/pki/tomcat/tomcat.jks"
-
certificateKeyAlias
="tomcat"
-
certificateKeystorePassword
="123456"
-
-
-
-
-
-
<Connector port="8009" protocol="AJP/1.3" redirectPort="443"/>
-
-
-
-
-
-
-
-
<web-resource-collection >
-
<web-resource-name >SSL</web-resource-name>
-
<url-pattern>/*</url-pattern>
-
</web-resource-collection>
-
-
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
-
-
-
-
-
-
-
-
nginx與client之間用https通訊 nginx與tomcat之間用http通訊
-
---
$nginx/conf.d/www.conf ---
-
-
-
-
-
proxy_set_header Host
$host;
-
proxy_set_header X-Real-IP
$remote_addr;
-
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
-
proxy_set_header X-Forwarded-Proto
$scheme;
-
-
-
-
-
---
$tomcat/conf/server.xml ---
-
-
-
-
<Valve className="org.apache.catalina.valves.RemoteIpValve"
-
remoteIpHeader
="X-Forwarded-For"
-
protocolHeader
="X-Forwarded-Proto"
-
protocolHeaderHttpsValue
="https"/>
-
-
-