1、配置多個項目
在tomcat的conf目錄下,找到server.xml,在其中添加<Host>節點即可進行多個項目的部署
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context docBase="uim" path="" />
</Host>
<Host name="www.ycyoes.com" appBase="hcode"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context docBase="hcode" path="" />
</Host>
其中,name為localhost或者IP或者是域名,appBase為項目所在目錄,可為絕對路徑或者相對路徑。配置完成后啟動Tomcat即可。
2、配置域名訪問
在server.xml中<Host>節點的name屬性輸入域名即可,如:
<Host name="www.ycyoes.com" appBase="hcode"
unpackWARs="true" autoDeploy="true">
3、項目名缺省
一般的,進行項目訪問時需要在url最后輸入系統名稱,如http://www.ycyoes.com/appName, 可通過tomcat配置,缺省系統名稱也可訪問。
在<Host>節點內添加如下內容:
<Context docBase="hcode" path="" />
其中,docBase即為系統名稱,此時通過http://www.ycyoes.com 即可進行系統的訪問。
4、系統訪問時端口號缺省
在訪問系統時一般需要在ip地址后帶上端口號,如http://ip:port/appName ,但是80端口可缺省,配置tomcat端口為80則不需要在url中輸入端口。配置如下:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" />
5、https訪問配置
在server.xml中打開如下配置:
<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false"
sslProtocol="TLS"
keystoreFile="/home/doc/keys/213972284410468.pfx"
keystoreType="PKCS12"
keystorePass="213972284410468" />
添加keystoreFile,keystoreType,keystorePass即可進行https訪問。
6、自動跳轉到https連接
如果希望輸入http鏈接時自動跳轉到https,需要在web.xml中添加如下內容:
<login-config>
<!-- Authorization setting for SSL -->
<auth-method>CLIENT-CERT</auth-method>
<realm-name>Client Cert Users-only Area</realm-name>
</login-config>
<security-constraint>
<!-- Authorization setting for SSL -->
<web-resource-collection >
<web-resource-name >SSL</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
以上內容位置在</web-app>內,添加后輸入http訪問時會自動跳轉到https連接。
7、https訪問端口號缺省
Tomcat中https默認端口為8443,該為443后可進行端口號缺省訪問系統。如下:
<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false"
sslProtocol="TLS"
keystoreFile="/home/doc/keys/213972284410468.pfx"
keystoreType="PKCS12"
keystorePass="213972284410468" />