前言
腾讯云Nginx配置SSL,实现HTTPS访问
准备工作
下载SSL证书,并发送到云服务器
已经搭建好Nginx环境
配置SSL
<domain_name>
:以域名为名的压缩包文件名
1 2 3 4 5
| mkdir <domain_name> mv <domain_name>.zip ./<domain_name> cd <domain_name>
unzip <domain_name>.zip
|
1 2
| cp Nginx/1_<domain_name>_bundle.crt /etc/nginx/ cp Nginx/2_<domain_name>.key /etc/nginx/
|
- 修改Nginx配置文件,追加一个server代码块
/etc/nginx/nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| server { listen 443 ssl; server_name feiju12138.xyz;
ssl_certificate 1_<domain_name>_bundle.crt; ssl_certificate_key 2_<domain_name>.key;
ssl_session_timeout 5m;
location / { root html; index index.html index.htm; } }
|
同时配置反向代理
- 通过反向代理实现端口转发
- 添加
proxy_pass
语句
<port>
:反向代理指向得到端口号
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| server { listen 443 ssl; server_name feiju12138.xyz;
ssl_certificate 1_<domain_name>_bundle.crt; ssl_certificate_key 2_<domain_name>.key;
ssl_session_timeout 5m;
location / { root html; proxy_pass http://127.0.0.1:8080; index index.html index.htm; } }
|
踩坑
- 报错:
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in ...
原因
解决问题
1
| ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
|
完成
参考文献
腾讯云文档——Nginx 服务器 SSL 证书安装部署
博客园——ノGHJ