nginx 启用HTTPS经历
背景环境
- Linux 环境
- 前端后端分离, 但是部署在同一个服务器上
- 前端angular
- 后端Java
- 腾讯云服务器
nginx 关键配置
在http下添加
server {
listen 80;
server_name ****(域名);
return 301 https://$http_host$request_uri;
access_log off;
}
server {
listen 443 ssl;
server_name ****(域名); #主机名或域名
ssl_certificate /**/**.pem; #ssl证书
ssl_certificate_key /**/**.key; #ssl证书key
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m; #超时
# 加密协议等等
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_prefer_server_ciphers on;
location / {
try_files $uri $uri/ /index.html;
root /**/**; #angular打包文件所在地
index index.html index.htm;
}
location ^~ /** (后端的server.servlet.context-path) **/ {
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:10071; #后端
}
}
注意事项
- 腾讯云入口443端口需要开放
- Linux的443端口需要开放
优点
- 快速
- 简单
缺点
未知
参考链接
每个牛B人物背后都有段苦逼的岁月,只要像SB一样坚持,终将牛B!

浙公网安备 33010602011771号