博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NGINX 4xx 5xx 状态码构造
阅读量:7023 次
发布时间:2019-06-28

本文共 4104 字,大约阅读时间需要 13 分钟。

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 

4xx系列

400

NGX_HTTP_BAD_REQUEST

Host头不合法 curl localhost:8070  -H 'Host:123/com'400 Bad Request

400 Bad Request


nginx/1.14.0
Content-Length头重复curl localhost:8070 -H 'Content-Length:1' -H 'Content-Length:2'400 Bad Request

400 Bad Request


nginx/1.14.0

401

NGX_HTTP_UNAUTHORIZED

参考如上nginx配置,访问abc.html需要认证 curl localhost:8070/abc.html401 Authorization Required

401 Authorization Required


nginx/1.14.0

403

NGX_HTTP_FORBIDDEN

chmod 222 index.html将index.html设置为不可读 curl localhost:8070403 Forbidden

403 Forbidden


nginx/1.14.0

404

NGX_HTTP_NOT_FOUND

curl localhost:8070/cde.html404 Not Found

404 Not Found


nginx/1.14.0

405

NGX_HTTP_NOT_ALLOWED

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

5xx系列

500

NGX_HTTP_INTERNAL_SERVER_ERROR

修改index.php为
curl localhost:8070/index.php -IHTTP/1.1 500 Internal Server ErrorServer: nginx/1.14.0Date: Tue, 18 Sep 2018 11:29:19 GMTContent-Type: text/html; charset=UTF-8Connection: keep-aliveSet-Cookie: PHPSESSID=aoesvcuvbh1nh95kdkp152r9e1; path=/Expires: Thu, 19 Nov 1981 08:52:00 GMTCache-Control: no-store, no-cache, must-revalidatePragma: no-cache

501

NGX_HTTP_NOT_IMPLEMENTED

nginx的transfer-encoding现在只支持chunked,如果客户端随意设置这个值,会报501 curl localhost:8070  -H 'Transfer-Encoding:1'501 Not Implemented

501 Not Implemented


nginx/1.14.0

502

NGX_HTTP_BAD_GATEWAY

修改nginx配置为fastcgi_pass 127.0.0.1:8000;指向一个未监听的端口
curl localhost:8070/index.php -IHTTP/1.1 502 Bad GatewayServer: nginx/1.14.0Date: Tue, 18 Sep 2018 11:28:17 GMTContent-Type: text/htmlContent-Length: 537Connection: keep-aliveETag: "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;
连续发送两个请求,第二请求会报503curl localhost:8070/index.php -IHTTP/1.1 503 Service Temporarily UnavailableServer: nginx/1.14.0Date: Tue, 18 Sep 2018 11:31:43 GMTContent-Type: text/htmlContent-Length: 537Connection: keep-aliveETag: "5ad6113c-219"

504

NGX_HTTP_GATEWAY_TIME_OUT

修改index.php为
curl localhost:8070/index.php -IHTTP/1.1 504 Gateway Time-outServer: nginx/1.14.0Date: Tue, 18 Sep 2018 12:17:57 GMTContent-Type: text/htmlContent-Length: 537Connection: keep-aliveETag: "5ad6113c-219"

505

NGX_HTTP_VERSION_NOT_SUPPORTED

telnet8070端口,输入GET /index.html HTTP/2.1不支持http/2.1,会报505 $telnet localhost 8070Trying 127.0.0.1...Connected to localhost.Escape character is '^]'.GET /index.html HTTP/2.1HTTP/1.1 505 HTTP Version Not SupportedServer: nginx/1.14.0Date: Tue, 18 Sep 2018 12:26:35 GMTContent-Type: text/htmlContent-Length: 203Connection: close505 HTTP Version Not Supported

505 HTTP Version Not Supported


nginx/1.14.0

转载地址:http://rnpxl.baihongyu.com/

你可能感兴趣的文章
Hadoop新特性
查看>>
必会的next.js自定义App和Document
查看>>
深入总结Javascript原型及原型链
查看>>
Spring Cloud的介绍以及环境搭建
查看>>
求数组中第K大的数
查看>>
前端开发中使用mac自带apache服务
查看>>
#情人节专题#利用Three.js实现一个记录两个人走过岁月的点点滴滴的idea
查看>>
Vue中,利用JSX语法生成不同html模板
查看>>
部分vue webpack打包配置问题简介
查看>>
入门笔记 --- Golang 语法注意事项(一)
查看>>
A的女儿是B的女儿的妈妈,A是B的谁?
查看>>
axios封装以及前端接口处理策略
查看>>
魅族PRO 5详细开启Usb调试模式的流程
查看>>
需要上级处理的双亲委派模型
查看>>
Basic Of Concurrency(九: 线程通讯)
查看>>
flutter 自定义带水波纹和点击态的cell
查看>>
小程序 | 注释级微信小程序demo,助你快速切入开发
查看>>
VS Code markdown格式化的插件编写(3)[解难反思]
查看>>
webpack
查看>>
Django框架环境搭建
查看>>