【笔记】腾讯云Nginx配置SSL

前言

腾讯云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
  • 复制证书到Nginx配置目录
1
2
cp Nginx/1_<domain_name>_bundle.crt /etc/nginx/
cp Nginx/2_<domain_name>.key /etc/nginx/
  • 修改Nginx配置文件,追加一个server代码块

example.com:指定域名

/etc/nginx/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
server {
listen 443 ssl;
server_name example.com;

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 example.com;

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 ...

原因

  • 缺少ngx_http_ssl_module模块

解决问题

  • 进入到源码安装包目录
1
cd nginx
  • 重新配置模块
1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
  • 重新编译,但不要安装,否则会覆盖安装
1
make

完成

参考文献

腾讯云文档——Nginx 服务器 SSL 证书安装部署
博客园——ノGHJ