环境:
Ubuntu18.04.1 LTS - aliYun
nginx/1.15.3
openssl 1.1.1
目前已经资瓷Https,Http2.0,TLS1.3,HSTS,控制一定时间内请求数等功能
HTTPS
HTTPS本质上是一个公钥和私钥的配对过程,其通过SSL/TLS协议实现,通常只对服务器端进行效验
HTTPS配置就是配置证书
配置HTTPS主要是从使用Service Work角度出发的,Service Work必须配置HTTPS才能work
Https的配置主要难点就是SSL证书的生成+多域名证书的生成
OpenSSL
OpenSSL提供的是自签名证书, 自签名访问时会出现不安全字样
## 生成私钥
openssl genrsa -out server.key 2048
## 修改openssl.cnf文件
cp /etc/ssl/openssl.cnf ./
1. 取消[ req ] 模块下注释:req_extensions = v3_req
2. 确保[ req_distinguished_name ]下没有 0.xxx 的标签,有的话把0.xxx的0. 去掉
3. 在 [ v3_req ] 块下增加一行 subjectAltName = @SubjectAlternativeName
4. 在文件末尾增加所有域名信息:
[SubjectAlternativeName]
DNS.1 = *.wyydsb.xin
DNS.2 = *.wyydsb.cn
DNS.3 = *.wyydsb.com
## 配置证书文件
openssl req -new -key server.key -out server.csr -config ./openssl.cnf
## openssl req -new -newkey rsa:2048 -sha256 -nodes -out wyydsb.csr -keyout wyydsb.key -subj "/C=CN/ST=ZheJiang/L=HangZhou/O=wyydsb/OU=wyydsb/CN=wyydsb.xin"
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:ZheJiang
Locality Name (eg, city) []:HangZhou
Organization Name (eg, company) [Internet Widgits Pty Ltd]:wyydsb
Organizational Unit Name (eg, section) []:wyydsb
Common Name (e.g. server FQDN or YOUR name) []:wyydsb.xin # your server site
Email Address []:yue.li3@21vianet.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:wyydsb
## 生成自签名证书.crt
openssl req -new -x509 -days 3650 -keyout server.key -out server.crt -config openssl.cnf
## 拷贝.crt, .key地址于nginx.conf内
Certbot
Certbot提供的是权威签名证书
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
# 多域名证书生成
certbot certonly --standalone --email your@email.com -d yourdomain.com -d yourdomain2.com -d www.yourdomain.com -d xxx
# 记录命令执行后显示的key address
vim /usr/local/nginx/conf/nginx.conf
# 修改为
server{
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/{yourdomain}.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{yourdomain}.com/privkey.pem;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_p