修改Apache的超时设置,解决长连接请求超时问题
时间:2022-05-05
本文章向大家介绍修改Apache的超时设置,解决长连接请求超时问题,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
某日,组内后台开发找到我,问我们的 WEB 服务器超时设置是多少。他反馈的问题是,有一个 VLAN 切换任务 cgi 接口经常返回 504 网关超时错误,要我分析解决下。
我问了一下,得知这个请求遇到网络设备对象较多的时候,需要小半个小时才能完成,也就是要用到长连接才行。
老规矩,从开发那拿到接口地址,得到接入层服务器 IP,是一台 Haproxy 代理,看了一下 Haproxy 的超时设置:
# 设置成功连接到一台服务器的最长等待时间,默认单位是毫秒,新版本的haproxy使用timeout connect替代,该参数向后兼容
contimeout 3600
# 设置连接客户端发送数据时的成功连接最长等待时间,默认单位是毫秒,新版本haproxy使用timeout client替代。该参数向后兼容
clitimeout 3600
# 设置服务器端回应客户度数据发送的最长等待时间,默认单位是毫秒,新版本haproxy使用timeout server替代。该参数向后兼容
srvtimeout 3600
各种 1 小时超时,所以排除 Haproxy 的影响,继续往下看。
Haproxy 代理的是 2 台 Apache,也就是部署了 cgi 接口的服务器。第一时间查看了 httpd.conf 和 httpd-vhost.conf 中的配置,居然没找到超时设置。
于是,搜索了下相关教程,发现原来藏在了 httpd-default.conf 当中:
#
# This configuration file reflects default settings for Apache HTTP Server.
#
# You may change these, but chances are that you may not need to.
#
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300
#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5
#
# UseCanonicalName: Determines how Apache constructs self-referencing
# URLs and the SERVER_NAME and SERVER_PORT variables.
# When set "Off", Apache will use the Hostname and Port supplied
# by the client. When set "On", Apache will use the value of the
# ServerName directive.
#
UseCanonicalName Off
#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess
#
# ServerTokens
# This directive configures what you return as the Server HTTP response
# Header. The default is 'Full' which sends information about the OS-Type
# and compiled in modules.
# Set to one of: Full | OS | Minor | Minimal | Major | Prod
# where Full conveys the most information, and Prod the least.
#
ServerTokens Full
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#
ServerSignature On
#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off
看了下,这些是 Apache 的默认配置,Apache 也没有 include 到 httpd.conf 当中。因此,编辑 httpd.conf,找到如下参数:
#Include conf/extra/httpd-default.conf
去掉注释,保存文件。然后再编辑 /usr/local/apache2/conf/extra/httpd-default.conf 文件,将 Timeout 的值修改为符合生产环境要求的 1800 秒,最后执行 Apache 平滑重启命令即可:
/usr/local/apache2/bin/apachectl -k graceful 或者 /usr/local/apache2/bin/httpd -k graceful
Ps:我之前一直以为只有 Nginx 有一个平滑 reload 命令,后面才知道 Apache、Haproxy 都支持平滑重启名称,这个非常棒!
重载之后,就不会出现 504 网关超时设置了。
- 前后端分离之vue2.0+webpack2 实战项目 -- webpack介绍
- 神经网络 之 感知器的概念和实现
- 图解ByteBuffer
- TensorFlow-1: 如何识别数字
- 你应该知道的Java垃圾收集器 - 串行、并行、CMS、G1
- ckplayer 如何在PC上完美支持 m3u8播放
- TensorFlow-2: 用 CNN 识别数字
- js图片前端预览之 filereader 和 window.URL.createObjectURL
- TensorFlow-3: 用 feed-forward neural network 识别数字
- TensorFlow-4: tf.contrib.learn 快速入门
- TensorFlow-5: 用 tf.contrib.learn 来构建输入函数
- 前后端分离之vue2.0+webpack2 实战项目 -- html模板拼接
- 抛弃vue-resource拥抱axios
- TensorFlow-6-TensorBoard 可视化学习
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 项目驱动-两日速成Docker日记
- python os模块 --- 操作系统接口模块
- 自动采集各种美女图片站并下载图和自动搭建图片站
- 修改其他函数的功能的神器——python装饰器
- AllTube:视频解析下载源码安装教程
- Zsh和Oh My Zsh的安装配置
- 程序猿怎么利用技术挣钱?——python量化实践
- 利用WireGuard建立IPv6隧道
- selenium爬虫相关报错解决
- 小涴熊漫画CMS:非常不错的免费开源的漫画连载系统,带采集API
- 成都电信宽带获取IPV6地址全过程
- android studio 3.6.1导入项目报错提示无法下载classpath里的内容
- Linux VPS使用命令行快速查询百度网盘提取码
- Flutter 首页必用组件NestedScrollView的示例详解
- AUXPI:简单的API图床程序,支持上传到搜狗/新浪/SMMS等多个图床