Nginx配置HTTPS
前提
通过源码安装 nginx 并在编译时通过 --with-http_ssl_module
将 ssl
模块编译进 nginx 二进制中,安装后保证 nginx 二进制文件在环境变量搜索的路径下,如果没有就通过软连接的方式将其软连接到 /usr/local/bin
等目录下
安装 Let’s Encrypt 客户端
Let's Encrypt
可以为我们办法免费的 CA 证书,有效期 90
天,到期需要续期。下面以 Centos 系统为例:
yum install python2-certbot-nginx
配置 Nginx
保证你的 80
端口可以访问,且可以通过域名访问,注意这个域名需要是 DNS 能够解析到的,使用 server_name
指定你的域名,修改好后启动 nginx
server {
listen 80;
server_name your.domain;
location / {
root html;
index index.html index.htm;
}
}
获取 SSL/TLS 证书
使用 certbot
工具获取证书并自动在 nginx 配置中生成相关配置信息,可以通过 --nginx-server-root
来指定 nginx 的配置文件目录的路径,默认是 /etc/nginx
certbot --nginx-server-root=/usr/local/openresty/nginx/conf/ -d your.domain
参考
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.