NGINX 中HTTP请求大小相关配置及解决方案-1

NGINX中收到HTTP请求大小相关的错误,以下典型错误及相关解决方案。 nginx 配置文件 nginx.conf user root; worker_processes 1; error_log logs/error.log debug; #pid logs/nginx.pid; events { worker_connections 1024; } http { #large_client_header_buffers 4 16k; server { listen 80; server_name localhost; location / { root /root/nginx-quic/html; index index.html index.htm; } } } 1. 请求头超长(HTTP 400/414) HTTP 400 (Bad Request):请求头过大,导致无法解析。 HTTP 414 (URI Too Long):请求行(URI 部分)过长。 模拟请求头超长 curl -v -H "$(head -c 8192 < /dev/zero | tr '\0' 'A'): value" http://localhost 此命令发送一个包含 8192 个字符的请求头字段, 返回结果 < HTTP/1.1 400 Bad Request < Server: nginx/1.25.4 < Date: Sat, 23 Nov 2024 13:26:23 GMT < Content-Type: text/html < Content-Length: 233 < Connection: close 检查 error.log,通常会看到类似以下错误: ...

2024-11-24 · 2 min · 275 words

Troubleshooting HTTP 400/414/413 Errors in NGINX: A Complete Guide

Common NGINX HTTP Request Size Errors and Their Solutions Here is a sample nginx.conf configuration file: user root; worker_processes 1; error_log logs/error.log debug; #pid logs/nginx.pid; events { worker_connections 1024; } http { #large_client_header_buffers 4 16k; server { listen 80; server_name localhost; location / { root /root/nginx-quic/html; index index.html index.htm; } } } 1. Oversized Request Headers (HTTP 400/414) HTTP 400 (Bad Request): The request headers are too large and cannot be parsed. HTTP 414 (URI Too Long): The request line (URI) is excessively long. Simulating Oversized Request Headers You can use the following command to simulate a request with an overly large header: ...

2024-11-24 · 3 min · 431 words

shell heredoc

shell中如果定义多行的字符串可以使用heredoc 先检查一下当前使用shell echo $0 -bash heredoc 是一种在 Shell 脚本、编程语言(例如 Bash、PHP、Ruby 等)中,用来定义多行字符串的方法。它可以使代码中的字符串定义更加清晰和可读,尤其适用于需要定义包含多行内容的文本块时。以下是 heredoc 的基本用法和一些示例。 Bash 中的 Heredoc 语法 在 Bash 中,heredoc 的语法如下: command <<EOF 内容... EOF command 表示你要将这些多行内容传递给的命令,例如 cat、echo 等。 &lt;&lt;EOF 表示开始使用 heredoc,其中 EOF 是一个标识符,用来定义多行文本的结束位置。你可以使用其他标识符来替代 EOF,例如 END,但开始和结束的标识符必须一致。 结束标识符必须单独一行,且通常没有前后的空格。 示例 1. 输出多行文本 你可以使用 heredoc 来输出多行文本: cat <<EOF 这是第一行 这是第二行 这是第三行 EOF 输出结果为: 这是第一行 这是第二行 这是第三行 2. 写入文件 你可以将 heredoc 的内容重定向到一个文件: cat < myfile.txt 这是要写入文件的内容 第二行 第三行 EOF 这会将文本块写入名为 myfile.txt 的文件中。 3. 结合命令 也可以将 heredoc 与其他命令结合使用,例如 while 循环: ...

2024-11-14 · 1 min · 187 words

intermediate CA certificate 中间证书

中间证书 中间证书的使用是随着公共密钥基础设施(PKI)的发展而逐渐普及。 早期数字证书体系中根证书直接签发终端(客户端)证书,这种方式存在的问题 根证书安全风险: 一旦根证书泄露整个信任体系就会崩溃; 证书管理的灵活性:根证书通常有大型认证机构管理,工作不能合理分发; 证书撤销机制:仅用根证书签发,一旦撤销将影响整个信任链; 相关标准 X.509 证书标准: X.509 v3 证书标准中, 引入了更多扩展字段,使得中间证书可以更有效地运作。它允许通过设置 basicConstraints 扩展来定义证书是否是一个证书颁发机构(CA)证书,并引入路径长度约束(pathlen),以确保中间证书不能签发超出其级别的证书。 X.509 v3 是证书链中的关键标准,它允许将证书分层,使得根证书签发中间证书,中间证书再签发终端证书。这一机制在 1996 年被纳入 X.509 v3 标准。 互联网工程任务组 (IETF) 标准:RFC 5280: RFC 5280 是互联网标准的一个重要文档,它详细说明了证书路径验证的标准,定义了如何使用 X.509 证书和证书吊销列表(CRL)来建立信任链。 X.509 v3 侧重于定义证书和结构, RFC 5280 侧重于在互联网应用中的使用,包括如何处理证书路径验证和证书撤销。 记得刚工作时正赶上银行收单系统一机一密改造,为每个终端生成终端密钥,与PKI体系不同,当时的pos和收单系统终端大多用的还是对称加密体系。 收单终端签到会根据其对应终端主密钥生成工作密钥,用于保护用户密码和用于报文校验。最早的终端密钥用的都是各省一个, 后来为每个终端生成一个终端主密钥, 防止主密钥泄露导致全省密钥泄露。 其实大体改造思路和中间正式类似。 实际使用 看下实际网站证书使用情况 # openssl s_client -connect baidu.com:443 -showcerts CONNECTED(00000003) depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA verify return:1 depth=1 C = US, O = DigiCert Inc, CN = DigiCert Secure Site Pro CN CA G3 verify return:1 depth=0 C = CN, ST = \E5\8C\97\E4\BA\AC\E5\B8\82, O = "BeiJing Baidu Netcom Science Technology Co., Ltd", CN = www.baidu.cn verify return:1 --- Certificate chain 0 s:C = CN, ST = \E5\8C\97\E4\BA\AC\E5\B8\82, O = "BeiJing Baidu Netcom Science Technology Co., Ltd", CN = www.baidu.cn i:C = US, O = DigiCert Inc, CN = DigiCert Secure Site Pro CN CA G3 -----BEGIN CERTIFICATE----- ....PMdeTgwOzn2nJhPcJFZ5yUGPZ8thorOYjMLHQ4DKsy7mnGMnKLwmz17L/0Tx 8GU= -----END CERTIFICATE----- 1 s:C = US, O = DigiCert Inc, CN = DigiCert Secure Site Pro CN CA G3 i:C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA -----BEGIN CERTIFICATE----- ....+AgqbDB91mdnxIr1MuTtHGn/Q1YE2x9OSTb2f2k0ArhFxFdcjKTfLLewG1xD -----END CERTIFICATE----- --- Server certificate subject=C = CN, ST = \E5\8C\97\E4\BA\AC\E5\B8\82, O = "BeiJing Baidu Netcom Science Technology Co., Ltd", CN = www.baidu.cn issuer=C = US, O = DigiCert Inc, CN = DigiCert Secure Site Pro CN CA G3 --- 根证书(depth=2):由 DigiCert 签发,是整个信任链的起点,受操作系统或浏览器信任。 中间证书(depth=1):DigiCert 的中间 CA,用于签发百度的终端服务器证书。 服务器证书(depth=0):这是百度的具体服务器证书,表明它属于 www.baidu.cn,并由 DigiCert 的中间 CA 签发。 ...

2024-10-12 · 10 min · 1995 words

证书common name

项目自签名证书,common name 超过64个字节报错 # openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=01234567890123456789012345678901234567890123456789012345678901234" Generating a RSA private key ........................++++ ........................................++++ writing new private key to 'key.pem' ----- problems making Certificate Request 140059529942848:error:0D07A097:asn1 encoding routines:ASN1_mbstring_ncopy:string too long:crypto/asn1/a_mbstr.c:107:maxsize=64 Common Name在 RFC5280中有描述(https://datatracker.ietf.org/doc/html/rfc5280#appendix-A) -- Naming attributes of type X520CommonName id-at-commonName AttributeType ::= { id-at 3 } -- Naming attributes of type X520CommonName: -- X520CommonName ::= DirectoryName (SIZE (1..ub-common-name)) -- -- Expanded to avoid parameterized type: X520CommonName ::= CHOICE { teletexString TeletexString (SIZE (1..ub-common-name)), printableString PrintableString (SIZE (1..ub-common-name)), universalString UniversalString (SIZE (1..ub-common-name)), utf8String UTF8String (SIZE (1..ub-common-name)), bmpString BMPString (SIZE (1..ub-common-name)) } 可以看到ub-common-name就是其长度定义, 当然也有一系列定义。 ...

2024-07-03 · 2 min · 404 words

linux arp 参数整理 – arp_filter

arp_filter: 控制系统对不同网络接口上收到的 ARP 请求的响应行为 取值范围: 1 - 允许您在同一子网上拥有多个网络接口,并根据内核是否会从ARP请求的IP地址出路由数据包来决定是否应答ARP请求(因此,这需要使用基于源的路由来实现)。换句话说,它允许控制哪些网卡(通常是一个)将响应ARP请求。 0 - (默认)内核可以用其他接口的地址来响应ARP请求。这看似不正确,但通常是有意义的,因为它增加了成功通信的机会。在Linux上,IP地址是由整个主机拥有的,而不是特定的接口拥有。只有在更复杂的设置中,如负载均衡,这种行为才会引起问题。如果设置了conf/{all,interface}/arp_filter中的至少一个为TRUE,那么该接口的arp_filter将被启用,否则将被禁用 验证 还是使用负载均衡的环境, rs1地址 # ip netns exec rs1 ip a 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 10.1.1.10/32 scope global lo valid_lft forever preferred_lft forever 264: veth-rs1@if263: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 00:11:22:33:44:99 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 10.1.1.13/24 scope global veth-rs1 valid_lft forever preferred_lft forever inet 10.1.1.11/24 scope global secondary veth-rs1 valid_lft forever preferred_lft forever 271: veth-rs1-extra@if270: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 66:82:27:71:76:15 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 172.168.1.3/24 scope global veth-rs1-extra valid_lft forever preferred_lft foreversshezh 设置arp_ignore, arp_filter为默认值0 ...

2024-06-23 · 2 min · 242 words

linux arp 参数整理

linux arp相关参数 在 Linux 中,有多个内核参数可以控制 ARP(地址解析协议)的行为。这些参数可以通过 /proc/sys/net/ipv4/conf/*/ 目录下的文件来配置,或者使用 sysctl 命令来设置。以下是一些常用的 ARP 内核参数及其含义: arp_ignore: 控制系统对不同网络接口上收到的 ARP 请求的响应行为。 取值范围: 0:在任何网络接口上收到 ARP 请求时,系统都会进行响应(默认值)。 1:只有当目标 IP 地址在收到请求的网络接口上配置时,系统才会响应。 2:只有当目标 IP 地址是最接近请求源的地址时,系统才会响应 arp_announce: 控制系统在发送 ARP 请求时,源 IP 地址的选择策略。 取值范围: 0 (默认): 允许使用任意网卡上的 IP 地址作为 ARP 请求的源 IP 地址。通常情况下,会使用 IP 数据包的源 IP。 1: 尽量避免使用不属于该发送网卡子网的本地地址作为发送 ARP 请求的源 IP 地址。 2: 忽略 IP 数据包的源 IP 地址,选择该发送网卡上最合适的本地地址作为 ARP 请求的源 IP 地址。 arp_accept: 控制系统GARP处理,当IP不在ARP表中。(GARP的源地址和目标地址一样), 如果存在直接更新不会判断这个标志 取值范围: 0 (默认值): 始终接受 GARP 数据包并相应地更新 ARP 表。即使 GARP 数据包包含未分配给其任何接口的 IP 地址,系统也会更新其 ARP 缓存。 1: 仅当数据包中的源 IP 地址与分配给系统接口之一的 IP 地址匹配时,才接受 GARP 数据包。这是一种更保守的方法,因为它只更新系统实际使用的地址的 ARP 缓存。 2:(自 Linux 内核 v6.0起)仅当源 IP 地址与接收数据包的接口位于同一子网时,才接受 GARP 数据包。这通过确保仅从同一网络上的设备接受 GARP 数据包来增加另一层安全性。 arp_notify; ...

2024-06-22 · 10 min · 1959 words

负载均衡

负载均衡的定义 In computing, load balancing is the process of distributing a set of tasks over a set of resources (computing units), with the aim of making their overall processing more efficient. Load balancing can optimize response time and avoid unevenly overloading some compute nodes while other compute nodes are left idle. Load balancing is the subject of research in the field of parallel computers. Two main approaches exist: static algorithms, which do not take into account the state of the different machines, and dynamic algorithms, which are usually more general and more efficient but require exchanges of information between the different computing units, at the risk of a loss of efficiency. ...

2024-06-02 · 7 min · 1334 words

VLAN

VLAN A virtual local area network (VLAN) is any broadcast domain that is partitioned and isolated in a computer network at the data link layer (OSI layer 2).[2][3] In this context, virtual refers to a physical object recreated and altered by additional logic, within the local area network. VLANs work by applying tags to network frames and handling these tags in networking systems – creating the appearance and functionality of network traffic that is physically on a single network but acts as if it is split between separate networks. In this way, VLANs can keep network applications separate despite being connected to the same physical network, and without requiring multiple sets of cabling and networking devices to be deployed. ...

2024-05-05 · 27 min · 5562 words

案例学习-Sysbench压测故障

背景: 故障源于知识星球的一个案例: 我们的数据库需要做在线升级丝滑的验证,所以构造了一个测试环境,客户端Sysbench 用长连接一直打压力,同时Server 端的数据库做在线升级,这个在线升级会让 Server进程重启,所以毫无疑问连接会断开重连,所以期望升级的时候 Sysbench端 QPS 跌0几秒钟然后快速恢复。 但是每次升级都是 Sysbench端 QPS永久跌0,再也不能恢复,所以需要分析为什么,问题出在哪里?有人说是服务端的问题因为只有服务端做了变更 整个测试过程中 Sysbench 是配置的2个连接去压 Server 故障重现: https://articles.zsxq.com/id_zj5qazqa4odz.html 下面也保留一份。 1. 数据库 docker run -it -d --net=host -e MYSQL_ROOT_PASSWORD=123 --name=plantegg mysql 2. 安装依赖包 yum install -y java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64 podman-docker.noarch wireshark sysbench mysql.x86_64 mysql -h127.1 -uroot -p123 3. 生成数据库 mysql -h127.1 -uroot -p123 -e "create database test" 4. 生成测试数据 sysbench --mysql-user='root' --mysql-password='123' --mysql-db='test' --mysql-host='127.0.0.1' --mysql-port='3306' --tables='16' --table-size='10000' --range-size='5' --db-ps-mode='disable' --skip-trx='on' --mysql-ignore-errors='all' --time='1180' --report-interval='1' --histogram='on' --threads=1 oltp_read_only prepare 5. 压测 sysbench --mysql-user='root' --mysql-password='123' --mysql-db='test' --mysql-host='127.0.0.1' --mysql-port='3306' --tables='16' --table-size='10000' --range-size='5' --db-ps-mode='disable' --skip-trx='on' --mysql-ignore-errors='all' --time='1180' --report-interval='1' --histogram='on' --threads=1 oltp_read_only run 6. kill,mysql进程,复现故障 # mysql -h127.1 -uroot -p123 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 8.3.0 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [(none)]> show processlist; +----+-----------------+-----------------+------+---------+------+------------------------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+-----------------+-----------------+------+---------+------+------------------------+------------------+ | 5 | event_scheduler | localhost | NULL | Daemon | 94 | Waiting on empty queue | NULL | | 13 | root | 127.0.0.1:33492 | test | Sleep | 0 | | NULL | | 14 | root | 127.0.0.1:51398 | NULL | Query | 0 | init | show processlist | +----+-----------------+-----------------+------+---------+------+------------------------+------------------+ MySQL [(none)]> kill 13; Query OK, 0 rows affected (0.000 sec) ...

2024-04-01 · 6 min · 1098 words