nginx配置

worker_processes  1;
events {worker_connections  1024;
}
http {include       mime.types;default_type  application/octet-stream;limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;sendfile        on;keepalive_timeout  65;server {listen       8070;server_name  10.96.79.14;limit_req zone=one;location / {root   html;index  index.html index.htm;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}location = /abc.html {root html;auth_basic           "opened site";auth_basic_user_file conf/htpasswd;}location ~ \.php$ {root /home/xiaoju/nginx-1.14.0/html;fastcgi_index index.php;fastcgi_pass 127.0.0.1:9000;fastcgi_param       SCRIPT_FILENAME  /home/xiaoju/nginx-1.14.0/html$fastcgi_script_name;include fastcgi.conf;fastcgi_connect_timeout 300;fastcgi_send_timeout 300;fastcgi_read_timeout 300;}}
}
index.php<?php
echo "124";

4xx系列

400

NGX_HTTP_BAD_REQUEST

Host头不合法curl localhost:8070  -H 'Host:123/com'<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.14.0</center>
</body>
</html>Content-Length头重复
curl localhost:8070  -H 'Content-Length:1'  -H 'Content-Length:2'<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.14.0</center>
</body>
</html>

401

NGX_HTTP_UNAUTHORIZED

参考如上nginx配置,访问abc.html需要认证curl localhost:8070/abc.html<html>
<head><title>401 Authorization Required</title></head>
<body bgcolor="white">
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.14.0</center>
</body>
</html>

403

NGX_HTTP_FORBIDDEN

chmod 222 index.html
将index.html设置为不可读curl localhost:8070<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.14.0</center>
</body>
</html>

404

NGX_HTTP_NOT_FOUND


curl localhost:8070/cde.html<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.14.0</center>
</body>
</html>

405

NGX_HTTP_NOT_ALLOWED

使用非GET/POST/HEAD方法访问一个静态文件
curl -X DELETE localhost:8070/index.html -IHTTP/1.1 405 Not Allowed
Server: nginx/1.14.0
Date: Tue, 18 Sep 2018 10:02:22 GMT
Content-Type: text/html
Content-Length: 173
Connection: keep-alive

5xx系列

500

NGX_HTTP_INTERNAL_SERVER_ERROR

修改index.php为<?php
echo "124"缺少引号,语法错误

curl localhost:8070/index.php -IHTTP/1.1 500 Internal Server Error
Server: nginx/1.14.0
Date: Tue, 18 Sep 2018 11:29:19 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Set-Cookie: PHPSESSID=aoesvcuvbh1nh95kdkp152r9e1; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache

501

NGX_HTTP_NOT_IMPLEMENTED


nginx的transfer-encoding现在只支持chunked,如果客户端随意设置这个值,会报501curl localhost:8070  -H 'Transfer-Encoding:1'<html>
<head><title>501 Not Implemented</title></head>
<body bgcolor="white">
<center><h1>501 Not Implemented</h1></center>
<hr><center>nginx/1.14.0</center>
</body>
</html>

502

NGX_HTTP_BAD_GATEWAY

修改nginx配置为
fastcgi_pass 127.0.0.1:8000;指向一个未监听的端口
curl localhost:8070/index.php -IHTTP/1.1 502 Bad Gateway
Server: nginx/1.14.0
Date: Tue, 18 Sep 2018 11:28:17 GMT
Content-Type: text/html
Content-Length: 537
Connection: keep-alive
ETag: "5ad6113c-219"

503

NGX_HTTP_SERVICE_UNAVAILABLE

修改nginx配置,限速为每分钟10个请求limit_req_zone $binary_remote_addr zone=one:10m rate=10r/m;
limit_req zone=one;
连续发送两个请求,第二请求会报503
curl localhost:8070/index.php -IHTTP/1.1 503 Service Temporarily Unavailable
Server: nginx/1.14.0
Date: Tue, 18 Sep 2018 11:31:43 GMT
Content-Type: text/html
Content-Length: 537
Connection: keep-alive
ETag: "5ad6113c-219"

504

NGX_HTTP_GATEWAY_TIME_OUT


修改index.php为
<?php
echo "124";
sleep(5);
休息5秒钟修改nginx配置为
三秒钟读超时
fastcgi_read_timeout 3;

curl localhost:8070/index.php -IHTTP/1.1 504 Gateway Time-out
Server: nginx/1.14.0
Date: Tue, 18 Sep 2018 12:17:57 GMT
Content-Type: text/html
Content-Length: 537
Connection: keep-alive
ETag: "5ad6113c-219"

505

NGX_HTTP_VERSION_NOT_SUPPORTED

telnet8070端口,输入GET /index.html HTTP/2.1
不支持http/2.1,会报505$telnet localhost 8070
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /index.html HTTP/2.1
HTTP/1.1 505 HTTP Version Not Supported
Server: nginx/1.14.0
Date: Tue, 18 Sep 2018 12:26:35 GMT
Content-Type: text/html
Content-Length: 203
Connection: close
<html>
<head><title>505 HTTP Version Not Supported</title></head>
<body bgcolor="white">
<center><h1>505 HTTP Version Not Supported</h1></center>
<hr><center>nginx/1.14.0</center>
</body>
</html>

NGINX 4xx 5xx 状态码构造相关推荐

  1. HTTP协议中的1xx,2xx,3xx,4xx,5xx状态码分别表示什么,列举常见错误码及含义

    转载:https://www.cnblogs.com/zouer/p/4991948.html HTTP协议状态码介绍 HTTP协议状态码,是指在HTTP协议运作中由客户端发出请求连接,服务端建立连接 ...

  2. Nginx code 常用状态码学习小结

    最近了解下Nginx的Code状态码,在此简单总结下.一个http请求处理流程: 一个普通的http请求处理流程,如上图所示: A -> client端发起请求给nginx B -> ng ...

  3. 【Nginx】警惕状态码 499 ,不只是 504

    目录 [Nginx]警惕状态码 499 ,不只是 504 状态码含义 499也危险 [Nginx]警惕状态码 499 ,不只是 504 状态码含义 499 499, Client Closed Req ...

  4. nginx返回400状态码

    分析: 1.后端地址正常返回200: 2.确认是url加上参数后,nginx返回400,并且nginx除了400状态码的访问日志,没有输出其他异常日志: nginx地址: https://test.c ...

  5. 请求头有问题导致Nginx返回400状态码

    背景 上个星期有人找我看了Nginx的问题,场景是这样的,用户访问一个网址,这个网址有一个按钮,点击这个按钮后会跳转到新的页面,但这个跳转,有时候可以,有时候不可以--不可以的时候页面显示400状态码 ...

  6. Nginx频繁报状态码400错误,定位到原因是丢包引起

    目录 一.背景说明 二.访问日志分析 三.TCP抓包分析 四.结论 一.背景说明 最近线上服务发布,完成后一切平静,到下午用户量正常起来后,开始频繁收到Nginx状态码是400的告警,初步确认是偶尔出 ...

  7. Nginx HTTP返回状态码修改

    由于在nginx配置中,设置了limit_req的流量限制,导致许多请求返回503错误代码,在限流的条件下,为提高用户体验,希望返回正常Code 200,且返回操作频繁的信息: location /t ...

  8. 简介响应状态码1xx、2xx、5xx

    对于我们前端的小伙伴们,能够多了解一下状态码的规范,还是对处理一些接口问题,有很大帮助的. 有没有看到我的标题是1xx.2xx.5xx并没有3xx.4xx,因为我在之前的文章中写过,如果想看的话,可以 ...

  9. python post与get的区别_Python Requests库 Get和Post的区别和Http常见状态码

    (1)   在客户端,Get方式在通过URL提交数据,数据在URL中可以看到:POST方式,数据放置在HTML HEADER内提交. (2)   GET方式提交的数据最多只能有1024 Byte,而P ...

  10. HTTP/HTTPS 01-不同状态码含义

    转自:http://m.blog.csdn.net/blog/u013857407/21741847 HTTP协议状态码,是指在HTTP协议运作中由客户端发出请求连接,服务端建立连接,客户端发出HTT ...

最新文章

  1. Nagios插件NDOUtils安装
  2. chrome设置微信ua_Chrome谷歌浏览器模拟微信内置浏览器的方法(电脑上)
  3. 源码安装sippyqt4 for ubuntu,anconda3,python3
  4. java GUI怎么输入_在Swing中创建Java GUI以进行表单输入
  5. WPF笔记(1.1 WPF基础)——Hello,WPF!
  6. 基于GEE平台分析湖北省近35年地表水变化特征
  7. 传富士康将在印度建世界最大代工厂
  8. Django学习(二)
  9. 【图文教程】de4dot实战字符串解密(演示:hishop微分销系统)
  10. LIME Low light Image Enhancement via Illumination Map Estimation
  11. Web 3D渲染引擎HOOPS Communicator动画编辑器的使用 | HOOPS教程
  12. QT 使用 QTcpSocket来检测 ip 设备的网络状态
  13. 电脑使用者的眼睛保护
  14. 论文投稿指南——中文核心期刊推荐(环境科学 2)
  15. 数据中心22年基础架构演进史
  16. R 实战 | 使用clusterProfiler进行多组基因富集分析
  17. 【字符识别】模板匹配(区域生长法)字母+数字识别【含Matlab源码 1214期】
  18. 40道Java多线程面试真题及答案
  19. 阿里云服务器vCPU和CPU有什么区别?
  20. bilibili老版本_bilibili老版本

热门文章

  1. Spring Cloud(Greenwich版)-05-Spring Cloud集成Ribbon(客户端负载均衡组件)
  2. duplicate symbols for architecture arm64的问题结决方法
  3. 东农计算机网络技术离线作业,东农16秋《电力系统分析》在线作业
  4. laravel上传文件到s3,打开链接无法下载而是直接在浏览器中显示内容
  5. laravel sql_mode 严格模式
  6. lnmp升级PHP环境
  7. WINDOWS上OpenCV需要有MediaPlayer才能正确运行?
  8. 编译错误:vulkan/vulkan.h:没有那个文件或目录
  9. 我的压缩软件选择:7zip软件+Zip格式
  10. Nsight中给工程添加include目录