# Nginx installs SSL certificates URL: https://chengjinfang.com/posts/2017/install-certificates/ Author: 程锦方 Date: 2017-03-25 Tags: #note #linux #install Summary: 为 Nginx 安装 SSL 证书,配置证书路径和 HTTP 到 HTTPS 的重定向。 ------------------------------------------------------------------------ ## [安装证书] https://certbot.eff.org/ ### 安装完成后记住ssl_certificate_key和ssl_certificate地址 ## nginx站点配置文件更改 ```sh vi /etc/nginx/nginx.conf ``` ### 301重定向 ```nginx server { listen 80; listen [::]:80 ipv6only=on; #开启ipv6,可以不开 server_name example.com example.tk; #多域名 location /.well-known/acme-challenge/ { default_type text/plain; alias /home/username/acme-challenge/; } return 301 https://$host$request_uri; #根据域名返回不同的HTTPS URL } ``` ### 更改证书地址 ```nginx server { listen 80; listen 443 ssl; server_name www.example.com; ssl_certificate www.example.com.crt; #输入你得到的地址 ssl_certificate_key www.example.com.key; #输入你得到的地址 ... } ``` ------------------------------------------------------------------------ Site: https://chengjinfang.com/ · All Index: https://chengjinfang.com/all/ · RSS: https://chengjinfang.com/rss.xml