置頂文章

2019年2月25日 星期一

[Web Service] 使用 Apache 設定的 https 接到 Tomcat 上

在apache設定ssl之後,

加上:
ProxyPreserveHost On
ProxyRequests Off
ServerName {domain name}
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

接著重啟apache即可。

Tomcat不用設定憑證,用apache的443接轉到tomcat的8080 port即可。

[Web Service] Tomcat 的 https 憑證設定

免費ssl憑證申請:
https://www.sslforfree.com/

按照網站說明成功取得憑證:
ca_bundle.crt ,
certificate.crt ,
private.key ,
上述三個檔案,


接著製作Tomcat用的憑證:

輸入指令:
openssl pkcs12 -export -in certificate.crt -inkey private.key -out cqihttp.p12 -certfile ca_bundle.crt
接著設定密碼,

完成後再輸入指令:
keytool -importkeystore -alias 1 -destkeystore tomcat.keystore -srckeystore cqihttp.p12 -srcstoretype pkcs12
接著設定密碼,產生憑證完畢「tomcat.keystore」。


然後在tomcat server.xml 增加下述設定:

<Connector
           protocol="org.apache.coyote.http11.Http11NioProtocol"
           port="8443" maxThreads="150"
           scheme="https" secure="true" SSLEnabled="true"
           keystoreFile="conf/tomcat.keystore" keystorePass="{密碼}"
           sslProtocol="TLS" SSLProtocol="TLSv1+TLSv1.1+TLSv1.2"/>

再重新啟動Tomcat即可。

但是在Linux上不允許使用者安裝的服務在小於1024 port運行,所以需要apache轉到tomcat上。

[Web Service] Apache 的 https 憑證設定

免費ssl憑證申請:
https://www.sslforfree.com/

按照網站說明成功取得憑證:
ca_bundle.crt ,
certificate.crt ,
private.key ,
上述三個檔案,
在ubuntu的apache ssl conf檔案加上:

SSLCertificateFile      certificate.crt的路徑
SSLCertificateKeyFile    private.key的路徑
SSLCertificateChainFile    ca_bundle.crt的路徑

重新啟動apache即可。

參考網址:
https://n.sfs.tw/content/index/10939