概述
1、软件版本要求
- Nginx version 1.9.5+, 应使用 --with-http_v2_module 配置参数启用它; 配置指令: listen 443 ssl http2
- Http2.0 以 https 方式部署, 要求 OpenSSL 版本 v1.0.2e+
- TLS 1.3 要求 OpenSSL 版本 v1.1.1+
- 查看各浏览器对 tls1.3 的支持情况: https://caniuse.com/tls1-3
2、具体部署的软件版本
- CentOS Linux release 7.6.1810
- openssl v1.1.1g
- nginx-1.20.1
openssl
# 编译安装
wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_1g.tar.gz
yum install make gcc-c++ -y
./config --prefix=/usr/local/openssl
make -j4 && make install
# 备份原 openssl 及设置新版 openssl 及动态库
mv /usr/bin/{openssl,openssl.bak}
mv /usr/include/{openssl,openssl.bak}
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
# 让动态链接库为系统所共享
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig /etc/ld.so.conf
# 验证安装是否正常
ldd /usr/local/openssl/bin/openssl
openssl version -a
数字证书
创建 ca、用户私钥、证书
# 生成 CA 私钥
openssl genrsa -out ca.key 2048
# 根据 CA 私钥生成 CA 的自签名证书
openssl req -new -x509 -days 365 -key ca.key -out ca.crt -subj "/C=CN/ST=BJ/L=BJ/O=HD/OU=dev/CN=ca/emailAddress=ca@world.com"
# 生成用户私钥 it123.com.key
openssl genrsa -out it123.com.key 2048
# 由用户私钥生成对应的公钥 it123.com.public.key
openssl rsa -in it123.com.key -pubout -out it123.com.public.key
# 根据私钥生成证书签名请求 it123.com.csr
openssl req -new -key it123.com.key -out it123.com.csr -subj "/C=CN/ST=BJ/L=BJ/O=HD/OU=ops/CN=*.it123.com/emailAddress=admin@it123.com"
# 使用 CA 的私钥和证书对用户证书签名, 生成 x509 证书 it123.com.pem
openssl x509 -req -days 3650 -in it123.com.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out it123.com.pem
查看公钥、私钥、证书签名请求
# 查看证书签名请求明细
openssl req -noout -text -in it123.com.csr
# 查看生成的私钥
openssl rsa -noout -text -in it123.com.key
# 查看公钥明细
openssl rsa -pubin -noout -text -in it123.com.public.key
nginx
添加编译选项--with-openssl=/usr/local/openssl编译安装
1、下载解压源码编译 nginx
# 源码下载及解压
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar xzf nginx-1.20.1.tar.gz && cd nginx-1.20.1
# 去掉配置文件 auto/lib/openssl/conf 中的 .openssl 路径
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
# 编译配置选项
yum install pcre-devel zlib-devel -y
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-openssl=/usr/local/openssl
# 编译安装
make -j4 && make install
mkdir -p /var/cache/nginx/
2、nginx server 配置
server {
listen 443 ssl http2;
server_name demo.it123.com;
ssl_certificate /etc/nginx/ssl/it123.com.pem;
ssl_certificate_key /etc/nginx/ssl/it123.com.key;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:5m;
ssl_session_timeout 5m;
location / {
root html;
index index.html index.htm;
}
}
3、nginx 中 http2、ssl/tls 相关配置项说明:
http2_max_concurrent_streams 128; # 设置连接中并发 HTTP/2 流的最大数量; 配置上下文 http、server
http2_max_concurrent_pushes 10; # 限制连接中并发推送请求的最大数量; http、server
http2_chunk_size 8k; # 设置响应正文切片的块的最大大小; http、server、location
http2_body_preread_size 64k; # 设置每个请求的缓冲区大小, 请求在开始处理之前可以保存在该缓冲区中; http, server
http2_recv_buffer_size 256k; # 设置每个工作进程的输入缓冲区; http
; ssl/tls
ssl_prefer_server_ciphers on; # 指定在使用 SSLv3 和 TLS 协议时,服务器密码应优先于客户端密码
ssl_session_cache shared:SSL:5m; # 设置存储会话参数的缓存的类型和大小
ssl_session_timeout 5m; # 指定客户端可以重用会话参数的时间
本文暂时没有评论,来添加一个吧(●'◡'●)