https部署
準(zhǔn)備證書及秘鑰
?
方式一、springboot項(xiàng)目可直接在yml中配置
1、需要將證書轉(zhuǎn)換成jks或p12格式,如
多個(gè)crt證書轉(zhuǎn)為pem:
cat xxx.crt xxx2.crt xxx3.xrt xxx4.crt > server.pempem證書轉(zhuǎn)為jks: //PEM--->PFXopenssl pkcs12 -export -out test.pfx -inkey test.key -in test.pem//PFX--->JKSkeytool -importkeystore -srckeystore test.pfx -destkeystore test.jks -srcstoretype PKCS12 -deststoretype JKScrt證書轉(zhuǎn)為jks://CRT-->CERopenssl x509 -inform pem -in test.crt -outform der -out test.cer//CER--->JKSkeytool -import -v -alias test -file test.cer -keystore test.jks -storepass 123456 -noprompt
2、然后在yml中進(jìn)行配置
server.port=8443 #https默認(rèn)是443端口好,由于linux下非root用戶無(wú)法使用443,這里改為8443)server.ssl.key-store:/xx/xx/server.jks #證書絕對(duì)路徑server.ssl.key-store-password: xxx #證書轉(zhuǎn)換時(shí)設(shè)置的密碼server.ssl.keyStoreType: JKS #證書類型
3、啟動(dòng)應(yīng)用,順利的話此時(shí)訪問(wèn)https://domain:8443/就訪問(wèn)到了原先的頁(yè)面
4、端口映射,將443端口映射到8443端口
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443
此時(shí)訪問(wèn) https://domain即可
這種方式可能涉及到證書多次轉(zhuǎn)換,并需要改動(dòng)項(xiàng)目的配置文件因此不太推薦。
?
方式二、使用nginx配置https
1、首先安裝nginx,檢查是否有支持ssl模塊,沒(méi)有的話記得安裝
2、配置
server {listen 443;server_name 域名;ssl on;ssl_certificate /xx/pem/xxx.pem;ssl_certificate_key /xx/pem/xxx.key;ssl_session_cache shared:SSL:1m;ssl_session_timeout 5m;ssl_ciphers HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers on;location / {root html;index index.html index.htm;proxy_pass http://域名對(duì)應(yīng)的ip:8080;proxy_set_header X-real-ip $remote_addr;proxy_set_header Host $http_host;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;} }
注意點(diǎn):
填寫域名
指定證書與秘鑰絕對(duì)路徑。證書也可以是crt格式
proxy_pass值指向服務(wù)真實(shí)的訪問(wèn)地址
3、啟動(dòng)nginx
4、訪問(wèn)https://domain即可
5、配置http://domain強(qiáng)制跳轉(zhuǎn)到https://domain
server {listen 80;server_name 域名;rewrite ^(.*)$ https://域名$1 permanent;}注意點(diǎn):http默認(rèn)端口為80參數(shù)$1代表域名后的路徑
在centos環(huán)境下可能會(huì)用到的相關(guān)命令:
查看開放端口及映射
iptables -L -n --line-number
端口映射
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443
取消映射
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443
開放端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
關(guān)閉端口
firewall-cmd --zone=public --remove-port=80/tcp --permanent
刷新配置
firewall-cmd --reload
轉(zhuǎn)載于:https://www.cnblogs.com/half-two-feet/p/10287660.html
總結(jié)
- 上一篇: 爆干3天整理出来,408考研计算机网络复
- 下一篇: 票据纸张尺寸对照表_粉丝要求,这期整理一