linux服务器+tomcat+域名+https


1、Tomcat 服务绑定域名的方法

步骤1:将Engine的defaultHost改为自己的域名,默认为localhost

步骤2:将Host的name改为自己的域名,默认为localhost

步骤3:在 节点下加多一句

 这个是项目路径  ,要绝对路径。

配置完毕,这样就可以通过域名访问我们服务器上的项目了。

 2、Tomcat 服务配置https访问

步骤1:生成证书

pfx证书安装和jks证书安装的区别

相同点:pfx和jks都是安装SSL证书时可用的证书合成文件;

不同点:pfx和jks适用的web服务器统不一样;

pfx仅用于iis,不限制iis版本但是安装时不同版本操作界面不一样;

jks仅用于tomcat,不限制tomcat版本但是不同tomcat版本不同使用的命令不一样。

接下来我们来了解一下tomcat下安装pfx和jks的方式:

pfx:需要增加keystoreFile 、 keystoreType 、 keystorePass,代码如下:

<Connector port=”8443″ protocol=”HTTP/1.1″

maxThreads=”150″ SSLEnabled=”true” scheme=”https” secure=”true”

keystoreFile=”/证书路径/名称.pfx”

keystoreType=”PKCS12″

keystorePass=”证书密码”

clientAuth=”false” sslProtocol=”TLS” />

jks :需要增加keystoreFile、 keystorePass,代码如下:

<Connector port=”8443″ protocol=”HTTP/1.1″

maxThreads=”150″ SSLEnabled=”true” scheme=”https” secure=”true”

keystoreFile=”/证书路径/名称.jks”

keystorePass=”证书密码”

clientAuth=”false” sslProtocol=”TLS” />

步骤2:修改tomcat配置文件server.xml

 将8443 改成443 ,因为https默认的端口是443,http默认的80

释放以下,将8443改成443,保持对称 keystoreFile 和 keystorePass 添加上

 步骤3:修改tomcat配置文件web.xml

 只运行 https,不允许http 则 web.xml 的 welcome-file-list 下面 中添加

    <welcome-file-list>
        <welcome-file>index.htmlwelcome-file>
        <welcome-file>index.htmwelcome-file>
        <welcome-file>index.jspwelcome-file>
    welcome-file-list>
     
    <login-config>
        
        <auth-method>CLIENT-CERTauth-method>
        <realm-name>Client Cert Users-only Arearealm-name>
    login-config>
    <security-constraint>
        
        <web-resource-collection >
        <web-resource-name >SSLweb-resource-name>
        <url-pattern>/*url-pattern>
        web-resource-collection>
        <user-data-constraint>
        <transport-guarantee>CONFIDENTIALtransport-guarantee>
        user-data-constraint>
    security-constraint>        

配置完毕,再次重启tomcat,访问http后会自动跳转到https,这样就可以通过https访问我们服务器上的项目了。