网站首页 > 技术文章 正文
什么是 HTTP 状态码?
HTTP 状态码由服务器响应浏览器对服务器的请求而发出的状态信息。
HTTP 状态码有官方、非官方、扩展以及自定义等几种,相同的状态码在不同的环境下有可能有不同的含义。作为运维人员,对于常见的 HTTP 状态码肯定并不陌生且张口就来,但也有一些状态码可能职业生涯结束也不会遇见。
背景
前段时间在使用 curl 测试一个网站请求的时候,发现返回码是 000,甚是觉得奇怪。那么今天我们来一起看看 curl 返回的 000 到底是什么鬼?
标准状态码
一个运维、开发人员我们需要熟知的状态码有哪些呢,下面会列举一些生产环境中常见的标准状态码:
2XX 成功
200 - OK,服务器成功返回网页
- Standard response for successful HTTP requests.
3XX 重定向
301 - Moved Permanently(永久跳转),请求的网页已永久跳转到新位置。
- This and all future requests should be directed to the given.
302 - Moved Temporarily(临时跳转),请求的网页已临时跳转到新位置。
4XX 客户端错误
401 - Unauthorized(未经授权),与 403 Forbidden 类似,但是专门用于需要身份验证且失败或尚未提供的情况。
403 - Forbidden(禁止访问),服务器拒绝请求
- forbidden request (matches a deny filter) => HTTP 403
- The request was a legal request, but the server is refusing to respond to it.
404 - Not Found, 服务器找不到请求的页面。
- The requested resource could not be found but may be available again in the future.
5XX 服务器错误
500 - Internal Server Error(内部服务器错误)
- internal error in haproxy => HTTP 500
- A generic error message, given when no more specific message is suitable.
502 - Bad Gateway(坏的网关), 一般是网关服务器请求后端服务时,后端服务没有按照 http 协议正确返回结果。
- the server returned an invalid or incomplete response => HTTP 502
- The server was acting as a gateway or proxy and received an invalid response from the upstream server.
503 - Service Unavailable(服务当前不可用), 可能因为超载或停机维护。
- no server was available to handle the request => HTTP 503
- The server is currently unavailable (because it is overloaded or down for maintenance).
504 - Gateway Timeout(网关超时), 一般是网关服务器请求后端服务时,后端服务没有在特定的时间内完成服务。
- the server failed to reply in time => HTTP 504
- The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
* 提示:在 Web 领域 nginx 的盛行程度非常高,加上目前多数网站都在大量使用 HTTPS,故大家还需要关注 nginx 扩展的 4XX 状态码(跟 SSL 相关)。
返回码 000 是什么呢?
简单点说:就是没有得到有效的 HTTP 请求响应。那么出现 000 的情况又有哪些呢?下面会罗列一些可能导致 000 返回码的情况,但不限于以下情况:
Failed DNS resolution (6) $ curl -w "%{http_code}\n" http://example.invalid/ ; echo "Exit code: $?"000curl: (6) Could not resolve host: example.invalid Exit code: 6 Connection refused (7) $ curl -w "%{http_code}\n" http://localhost:81/ ; echo "Exit code: $?"000curl: (7) Failed to connect to localhost port 81: Connection refused Exit code: 7 Connection timed out (28) $ curl -w "%{http_code}\n" -m 5 http://10.255.255.1/ ; echo "Exit code: $?"000curl: (28) Connection timed out after 5001 milliseconds Exit code: 28 Server actually returns 000 for some reason (0)
开启一个监听端口:
nc -l -p 65535 & <<EOF HTTP/1.1 000 Fake Status Code Content-Length: 0Connection: close EOF
客户端请求:
$ curl -w "%{http_code}\n" http://localhost:65535/ ; echo "Exit code: $?"000Exit code: 0
* 提示:脚本测试时记录日志,curl 参数:-sS , 然后将 curl 的错误 2>> /tmp/err.log。
总结
对于生产环境中常用的状态码我们需要非常熟悉,但一旦遇到一些特殊的返回码,我们也应该搞清楚它背后的事情。
猜你喜欢
- 2024-10-23 微软发布6月Win11累积更新KB5039212/KB5039213
- 2024-10-23 快速体验之《gor+diffy实现线上流量复制到测试环境》
- 2024-10-23 Colbie Caillat: Try(colbiecaillattry歌词)
- 2024-10-23 基于阿里云 ASK 的 Istio 微服务应用部署初探
- 2024-10-23 浅谈ElasticSearch 集群部署(elastic集群配置)
- 2024-10-23 Python项目中跟踪系统导入Zipkin(基于python的目标跟踪算法)
- 2024-10-23 JVM参数及调优(jvm调优常用参数)
- 2024-10-23 Elasticsearch的路由routing的应用技巧
- 2024-10-23 如何将Elasticsearch的快照备份至OSS
- 2024-10-23 利用工具curl来查看http请求和https请求
- 1507℃桌面软件开发新体验!用 Blazor Hybrid 打造简洁高效的视频处理工具
- 505℃Dify工具使用全场景:dify-sandbox沙盒的原理(源码篇·第2期)
- 484℃MySQL service启动脚本浅析(r12笔记第59天)
- 465℃服务器异常重启,导致mysql启动失败,问题解决过程记录
- 462℃启用MySQL查询缓存(mysql8.0查询缓存)
- 442℃「赵强老师」MySQL的闪回(赵强iso是哪个大学毕业的)
- 422℃mysql服务怎么启动和关闭?(mysql服务怎么启动和关闭)
- 418℃MySQL server PID file could not be found!失败
- 最近发表
-
- netty系列之:搭建HTTP上传文件服务器
- 让deepseek教我将deepseek接入word
- 前端大文件分片上传断点续传(前端大文件分片上传断点续传怎么操作)
- POST 为什么会发送两次请求?(post+为什么会发送两次请求?怎么回答)
- Jmeter之HTTP请求与响应(jmeter运行http请求没反应)
- WAF-Bypass之SQL注入绕过思路总结
- 用户疯狂点击上传按钮,如何确保只有一个上传任务在执行?
- 二 计算机网络 前端学习 物理层 链路层 网络层 传输层 应用层 HTTP
- HTTP请求的完全过程(http请求的基本过程)
- dart系列之:浏览器中的舞者,用dart发送HTTP请求
- 标签列表
-
- c++中::是什么意思 (83)
- 标签用于 (65)
- 主键只能有一个吗 (66)
- c#console.writeline不显示 (75)
- pythoncase语句 (81)
- es6includes (73)
- windowsscripthost (67)
- apt-getinstall-y (86)
- node_modules怎么生成 (76)
- chromepost (65)
- c++int转char (75)
- static函数和普通函数 (76)
- el-date-picker开始日期早于结束日期 (70)
- js判断是否是json字符串 (67)
- checkout-b (67)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- & (66)
- java (73)
- js数组插入 (83)
- linux删除一个文件夹 (65)
- mac安装java (72)
- eacces (67)
- 查看mysql是否启动 (70)
- 无效的列索引 (74)