nginx学习随笔--ssl_session_cache

本文介绍了Nginx中配置SSL会话缓存的方法,包括禁用缓存、不存储会话参数等不同模式,以及如何设置内置和共享缓存的大小。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

nginx学习随笔–ssl_session_cache

英文原文:

Syntax: ssl_session_cache off | none | [builtin[:size]] [shared:name:size];
Default:    ssl_session_cache none;
Context:    http, server

Sets the types and sizes of caches that store session parameters. A cache can be of any of the following types:

off
the use of a session cache is strictly prohibited: nginx explicitly tells a client that sessions may not be reused.
none
the use of a session cache is gently disallowed: nginx tells a client that sessions may be reused, but does not actually store session parameters in the cache.
builtin
a cache built in OpenSSL; used by one worker process only. The cache size is specified in sessions. If size is not given, it is equal to 20480 sessions. Use of the built-in cache can cause memory fragmentation.
shared
a cache shared between all worker processes. The cache size is specified in bytes; one megabyte can store about 4000 sessions. Each shared cache should have an arbitrary name. A cache with the same name can be used in several virtual servers.
Both cache types can be used simultaneously, for example:

ssl_session_cache builtin:1000 shared:SSL:10m;

but using only shared cache without the built-in cache should be more efficient.

中文翻译:

设置存储session参数的缓存的类型和大小。缓存可以是下面任何一种类型:

  • off

    严格禁止使用会话缓存:nginx明确告知客户端会话不可重用。

  • none

    会话缓存是不允许的:nginx告知客户端会话可以重用,但并没有在缓存中存储会话参数。

  • builtin

    在OpenSSL中构建缓存;只能被一个工作进程使用。缓存的大小在会话中指定,如果没有指定大小,默认20480个会话。使用内置缓存会导致内存碎片化。

  • shared

    缓存在所有工作进程之间共享。缓存大小按照字节为单位指定;1MB可以存储4000个会话。每块共享内存都应该起个名字。同一块缓存可以在多个虚拟服务中使用。

两种类型的缓存可以同时使用:

ssl_session_cache builtin:1000 shared:SSL:10m;

但是,单独使用共享缓存会更有效。

要正确配置和使用Nginx的with-stream_ssl_module增强SSL功能,可以按照以下步骤进行: 1. **安装Nginx并启用stream模块**: 首先,确保你已经安装了Nginx,并且安装了带有stream模块的版本。你可以通过以下命令安装Nginx: ```bash sudo apt update sudo apt install nginx ``` 如果需要编译安装Nginx并启用stream模块,可以使用以下命令: ```bash wget http://nginx.org/download/nginx-1.18.0.tar.gz tar -zxvf nginx-1.18.0.tar.gz cd nginx-1.18.0 ./configure --with-stream --with-stream_ssl_module make sudo make install ``` 2. **配置SSL证书**: 在配置Nginx之前,确保你已经生成了SSL证书和私钥。你可以使用以下命令生成自签名证书: ```bash sudo mkdir /etc/nginx/ssl sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt ``` 3. **配置Nginx的stream模块**: 编辑Nginx配置文件(通常位于 `/etc/nginx/nginx.conf`),添加以下配置: ```nginx stream { upstream backend { server backend1.example.com:12345; server backend2.example.com:12345; } server { listen 443 ssl; proxy_pass backend; ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate_key /etc/nginx/ssl/nginx.key; } } ``` 这个配置将Nginx配置为一个SSL代理服务器,将收到的请求转发到后端的服务器。 4. **测试配置并重启Nginx**: 在重新启动Nginx之前,测试配置是否正确: ```bash sudo nginx -t ``` 如果配置没有问题,重新启动Nginx: ```bash sudo systemctl restart nginx ``` 通过以上步骤,你就可以正确配置和使用Nginx的with-stream_ssl_module增强SSL功能了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值