nginx常见错误

1: 413 Request Entity Too Large
原因:报错是http request请求body太大,被nginx拒绝
解决方法:在配置文件里面修改client_max_body_size 10M 增大一些

2: HTTP/1.1 405 Method not allowed
原因:这个是由于客户端在用post的方式去请求了静态资源,而静态资源nginx不止允许通过get方式去请求
解决方法:修改nginx的源码,重新编译即可
找到文件http/modules/ngx_http_static_module.c
注释下面的禁止代码即可
/*
if (r->method & NGX_HTTP_POST) {
return NGX_HTTP_NOT_ALLOWED;
}
*/
3:post内容在lua里面无法获取body内容
检查client_max_body_size和client_body_buffer_size是否设置过小
另外,在读取的时候server中使用lua_need_request_body on; 或者在location lua代码块中使用 ngx.req.read_body()

4:nginx错误日志无法关闭
设置error_log off;后任然会输出文件名为off的错误日志,根本原因是错误日志不能off,只能error_log /dev/null;

5:openresty安装geoip时错误
./configure: error: the GeoIP module requires the GeoIP library
apt-get install libgeoip-dev

6:域名太长
nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
解决:server_names_hash_bucket_size 64;

7:nginx post json 跨域问题
Cross-Origin Read Blocking (CORB) blocked cross-origin with MIME type application/json
解决方式为:

location / {  
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
    add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

    if ($request_method = 'OPTIONS') {
        return 204;
    }
} 

参考链接 :

nginx常见错误 : http://ciika.com/page/24/

发布了364 篇原创文章 · 获赞 66 · 访问量 14万+

猜你喜欢

转载自blog.csdn.net/qq_40907977/article/details/105547517
今日推荐