linux tomcat 部署项目的一些配置

1.tomcat-https配置

keystoreFile 配置的是https证书文件路径

keystorePass 配置的是https证书密码

<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000"         
    redirectPort="443" />

<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol"
    maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
    clientAuth="false" sslProtocol="TLS" 
    keystoreFile="/home/webroot/keystore/XXXX.pfx" 
    keystorePass="XXXXXX" /> 

2.tomcat-path配置、即一个tomcat配置多个项目

<Host name="www.xxxx.com"  appBase="webapps" 
    unpackWARs="true" autoDeploy="true"xmlValidation="false"             
    xmlNamespaceAware="false">
    <Context path="" docBase="/home/webroot/project-name" crossContext="true"                                                               
        reloadable="true"   />
</Host>

3.配置tomcat “http://” 自动跳转成为 “https://” 

打开/apache-tomcat-6.0.29/conf/web.xml,在该文件</welcome-file-list>后面加上这样一段:

<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> 

4.浏览器访问http网站,自动跳转https

tomcat设置,方法有很多,例如:APache、Nginx、IIS都能做到。

这位博主讲的很详细:点击查看

这里采用修改tomcat的conf文件夹下的web.xml文件来实现效果

添加以下代码:

<web-app>
.
.
.
<security-constraint>
	<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>

5.获取项目上传文件绝对路径【java】

String projectUrl = request.getServletContext().getRealPath("/");

控制台打印出来的结果为【注意是编译后的target文件夹下的路径】:

D:\JAVA\IDEA-Workspace\shop-member\target\shop-member\

猜你喜欢

转载自blog.csdn.net/qq_36473199/article/details/86529902