nginx定义客户端请求的相关配置:


1、keepalive_timeout:

  长连接超时时间
  Default: keepalive_timeout 75s;
  Context: http, server, location
  

  示例:在响应头显示此首部字段
  keepalive_timeout 60 60;

示例:

[root@centos7.6 ~]# curl -I www.magedu.tech
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Wed, 03 Mar 2021 03:10:03 GMT
Content-Type: text/html
Content-Length: 24
Last-Modified: Thu, 25 Feb 2021 06:59:03 GMT
Connection: keep-alive
ETag: "60374ab7-18"
Accept-Ranges: bytes
修改配置: [root@centos7.
6 ~]# vi /etc/nginx/conf.d/test.conf server { listen 80; server_name www.magedu.tech; root /opt/testdir/; keepalive_timeout 65 50; }
验证: [root@centos7.
6 ~]# curl -I www.magedu.tech HTTP/1.1 200 OK Server: nginx/1.16.1 Date: Wed, 03 Mar 2021 03:10:51 GMT Content-Type: text/html Content-Length: 24 Last-Modified: Thu, 25 Feb 2021 06:59:03 GMT Connection: keep-alive Keep-Alive: timeout=50 #实际65 ETag: "60374ab7-18" Accept-Ranges: bytes

2、keepalive_requests number;

  

  在一次长连接上所允许请求的资源的最大数量,默认为100
  Default: keepalive_requests 100;
  Context: http, server, location
  This directive appeared in version 0.8.0.

示例:

修改配置:
[root@centos7.6 ~]# vi /etc/nginx/conf.d/test.conf server { listen 80; server_name www.magedu.tech; root /opt/testdir/; keepalive_timeout 65 50; keepalived_requests 2; }
验证:长连接接收2次请求后自动断开 [root@centos7.
6 ~]# telnet www.magedu.tech 80 Trying 10.0.0.125... Connected to www.magedu.tech. Escape character is '^]'. GET / HTTP/1.1 host: www.magedu.tech HTTP/1.1 200 OK Server: nginx/1.16.1 Date: Wed, 03 Mar 2021 03:15:00 GMT Content-Type: text/html Content-Length: 24 Last-Modified: Thu, 25 Feb 2021 06:59:03 GMT Connection: keep-alive Keep-Alive: timeout=50 ETag: "60374ab7-18" Accept-Ranges: bytes /opt/testdir/index.html GET / HTTP/1.1 host: www.magedu.tech HTTP/1.1 200 OK Server: nginx/1.16.1 Date: Wed, 03 Mar 2021 03:15:03 GMT Content-Type: text/html Content-Length: 24 Last-Modified: Thu, 25 Feb 2021 06:59:03 GMT Connection: close ETag: "60374ab7-18" Accept-Ranges: bytes /opt/testdir/index.html Connection closed by foreign host. [root@centos7.6 ~]#

3、keepalive_disable none | browser ...;

  对哪种浏览器禁用长连接
  Default: keepalive_disable msie6;
  Context: http, server, location

4、send_timeout time;

  向客户端发送响应报文的超时时长,此处是指两次写操作之间的间隔时长,而非整个响应过程的传输时长

  Default: send_timeout 60s;
  Context: http, server, location

5、缓存设置想组合

client_max_body_size size;
  指定请求报文中实体的最大值,设为0,则不限制,默认1m,超过报413错误
  Default: client_max_body_size 1m;
  Context: http, server, location

client_body_buffer_size size;
  用于接收每个客户端请求报文的body部分的缓冲区大小;默认为16k;超出此大小时,其将被暂存到磁盘上的由下面client_body_temp_path指令所定义的位置
  Default: client_max_body_size 1m;
  Context: http, server, location

client_body_temp_path path [level1 [level2 [level3]]];
  设定存储客户端请求报文的body部分的临时存储路径及子目录结构和数量目录名为16进制的数字;用hash之后的值从后往前截取第1、2、3级作为文件名
  client_body_temp_path /var/tmp/client_body 1 2 2

说明:
  1 level1级目录占1位16进制,即2^4=16个目录 0-f
  2 level2级目录占2位16进制,即2^8=256个目录 00-ff
  2 level3级目录占2位16进制,即2^8=256个目录 00-ff

[root@centos7.6 ~]# md5sum /etc/fstab 
784610c4b087f5a4dbf18f51699f150a /etc/fstab
假设存储路径是:/var/tmp/client_body/
落磁盘的文件存储路径:/var/tmp/client_body/a/50/f1/
总计可能存在的子目录数量:echo 16*256*256 |bc ---> 1048576

 

posted @ 2024-08-29 09:00  起点·漫步前行  阅读(33)  评论(0)    收藏  举报