网站首页 > 技术教程 正文
概述
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; # 指定客户端可以重用会话参数的时间
猜你喜欢
- 2024-10-13 如何在Tomcat中做TLS客户端认证(tomcat clientauth)
- 2024-10-13 我们应该使用 TLS1.3 吗(启用tls1.1)
- 2024-10-13 阿里云环境中TLS/SSL握手失败的场景分析
- 2024-10-13 「首席架构推荐」基于NGINX 的Kubernetes控制器
- 2024-09-28 如何在 NGINX Web 服务器中限制网络带宽 - Part 3
- 2024-09-28 高性能web服务器+反向代理服务器之Nginx
- 2024-09-28 如何在Node.js中使用SSL / TLS(node js server)
- 2024-09-28 「热点」Service Mesh利器:NGINX将支持gRPC
- 2024-09-28 放弃Nginx,Cloudflare开源基于Rust构建的网络服务框架Pingora
- 2024-09-28 Nginx配置最全详解(万字图文总结)
你 发表评论:
欢迎- 最近发表
-
- Win10 TH2正式版官方ESD映像转换ISO镜像方法详解
- 使用iso镜像升级到Windows 10的步骤
- macOS Ventura 13.2 (22D49) Boot ISO 原版可引导镜像
- 安利一个用ISO镜像文件制作引导U盘的的小工具RUFUS
- CentOS 7使用ISO镜像配置本地yum源
- 用于x86平台的安卓9.0 ISO镜像发布下载:通吃I/A/N、完全免费
- AlmaLinux 9.6发布:升级工具、初步支持IBM Power虚拟化技术
- Rufus写入工具简洁介绍与教程(写入模式)
- 新硬件也能安装使用了,Edge版Linux Mint 21.3镜像发布
- 开源工程师:Ubuntu应该抛弃32位ISO镜像
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)