大佬教程收集整理的这篇文章主要介绍了Springboot+Nginx前后端分离Https部署,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
适用于测试阶段,正常情况下,证书应该向发证CA机构申请。
生成证书密钥库
keytool -genkeypair -alias honor -storetype PKCS12 -keyalg RSA -keystore home.pkcs12 -storepass 123456 -validity 3650 -keysize 2048
查看密钥库
keytool -list -rfc -keystore home.pkcs12
或
keytool -list -v -keystore home.pkcs12
导出证书文件,本质是CERTIFICATE
openssl pkcs12 -in home.pkcs12 -out home_crt.pem -clcerts -nokeys
生成证书密钥文件:本质是私钥
openssl pkcs12 -in home.pkcs12 -out home_key.pem -nocerts -nodes
拷贝密钥库文件home.pkcs12到类路径下:可放在resources目录下,或其他java可查找到的类路径下
application.yml配置:
server:
port: 8000
ssl:
key-store-type: PKCS12
key-store: classpath:home.pkcs12
key-alias: honor
key-store-password: 123456
查看Nginx是否支持SSL和TLS
Nginx -V
Nginx version: Nginx/1.19.2
built by cl 16.00.40219.01 for 80x86
built with OpenSSL 1.1.1g 21 Apr 2020
TLS SNI support enabled
configure arguments: --with-cc=cl --builddir=objs.msvc8 --with-debug --prefix= --conf-path=conf/Nginx.conf --pid-path=logs/Nginx.pid --http-log-path=logs/access.log --error-log-path=logs/error.log --sbin-path=Nginx.exe --http-client-body-temp-path=temp/clienT_Body_temp --http-proxy-temp-path=temp/proxy_temp --http-fastcgi-temp-path=temp/fastcgi_temp --http-scgi-temp-path=temp/scgi_temp --http-uwsgi-temp-path=temp/uwsgi_temp --with-cc-opt=-DFD_SETSIZE=1024 --with-pcre=objs.msvc8/lib/pcre-8.44 --with-zlib=objs.msvc8/lib/zlib-1.2.11 --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_slice_module --with-mail --with-stream --with-openssl=objs.msvc8/lib/openssl-1.1.1g --with-openssl-opt='no-asm no-tests -D_WIN32_WINNT=0x0501' --with-http_ssl_module --with-mail_ssl_module --with-stream_ssl_module
Nginx配置
在http段或者server段加入以下配置,http段的配置对所有server生效。
在Nginx的config目录下新建cert目录,将证书和密钥文件放入,这里采用了相对路径。
server {
listen 443 ssl;
ssl_certificate cert/home_crt.pem;
ssl_certificate_key cert/home_key.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
server_name localhost;
LOCATIOn / {
root html/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
LOCATIOn = /50x.html {
root html;
}
}
转发http
server {
listen 8888;
server_name localhost;
rewrite ^(.*)$ https://${server_namE}$1 peRMANent;
}
以上是大佬教程为你收集整理的Springboot+Nginx前后端分离Https部署全部内容,希望文章能够帮你解决Springboot+Nginx前后端分离Https部署所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。