【笔记】Nginx配置SSL

前言

Nginx配置SSL,实现HTTPS访问

正文

  • 修改Nginx配置文件,追加一个server代码块

example.com:指定域名
<file>.crt<file>.cer<file>.pem:指定fullchain证书文件路径
<file>.key:指定私钥文件路径

/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 <file>.crt;
ssl_certificate_key <file>.key;

ssl_session_timeout 5m;

location / {
root html;
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