1)帮助大家对Nginx有一定的认识
2)熟悉Nginx有哪些应用场景
3)熟悉Nginx特点和架构模型以及相关流程
4)熟悉Nginx定制化开发的几种模块分类
Nginx简介:
Nginx (engine x) 是一个高性能的web服务器和反向代理服务器,也是一个IMAP/POP3/SMTP服务器
Nginx社区分支:
Nginx源码结构:
Nginx特点:
场景如下:
进程组件角色:
框架模型:
框架模型流程:
load_balance:
Handler模块:
#配置文件: server { ... location test { test_counter on; } } #config ngx_addon_name=ngx_http_test_module HTTP_MODULES="$HTTP_MODULES ngx_http_test_module" NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_test_module.c" #ngx_http_test_module.c static ngx_int_t ngx_http_test_handler(ngx_http_request_t *r) { ngx_int_t rc; ngx_buf_t *b; ngx_chain_t out; ngx_http_test_conf_t *lrcf; ngx_str_t ngx_test_string = ngx_string("hello test"); lrcf = ngx_http_get_module_loc_conf(r, ngx_http_test_module); if ( lrcf->test_counter == 0 ) { return NGX_DECLINED; } /* we response to 'GET' and 'HEAD' requests only */ if ( !(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD)) ) { return NGX_HTTP_NOT_ALLOWED; } /* discard request body, since we don't need it here */ rc = ngx_http_discard_request_body(r); if ( rc != NGX_OK ) { return rc; } /* set the 'Content-type' header */ /* *r->headers_out.content_type.len = sizeof("text/html") - 1; *r->headers_out.content_type.data = (u_char *)"text/html"; */ ngx_str_set(&r->headers_out.content_type, "text/html"); /* send the header only, if the request type is http 'HEAD' */ if ( r->method == NGX_HTTP_HEAD ) { r->headers_out.status = NGX_HTTP_OK; r->headers_out.content_length_n = ngx_test_string.len; return ngx_http_send_header(r); } /* set the status line */ r->headers_out.status = NGX_HTTP_OK; r->headers_out.content_length_n = ngx_test_string.len; /* send the headers of your response */ rc = ngx_http_send_header(r); if ( rc == NGX_ERROR || rc > NGX_OK || r->header_only ) { return rc; } /* allocate a buffer for your response body */ b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); if ( b == NULL ) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } /* attach this buffer to the buffer chain */ out.buf = b; out.next = NULL; /* adjust the pointers of the buffer */ b->pos = ngx_test_string.data; b->last = ngx_test_string.data + ngx_test_string.len; b->memory = 1; /* this buffer is in memory */ b->last_buf = 1; /* this is the last buffer in the buffer chain */ /* send the buffer chain of your response */ return ngx_http_output_filter(r, &out); }
解决接入层故障定位慢的问题,帮助OP快速判定问题根因,优先自证清白,提高接入层高效的生产力。
特点:
实现非常灵活的动态的修改策略从而进行切流量。
实现平滑无损的方式进行流量的切换。
通过秒级切换流量可以缩小影响范围,从而减少损失。
按照某一城市或者某个特征,秒级进行切换流量或者禁用流量。
容忍单机房级别容量故障,缩短了单机房故障的止损时间。
快速的将流量隔离或者流量抽样。
高效的灰度测试,提高生产力。
让接入层可以适配动态调度的云环境,实现服务的平滑上下线、弹性扩/缩容。
从而提高接入层高效的生产力以及稳定性,保证业务流量的平滑无损。
链路追踪,梳理接口到后端链路的情况。查询location接口对应upstream server信息。
获取nginx配置文件格式化为json格式信息。
根据配置文件来动态的添加共享内存。
https://github.com/lidaohang/ngx_shm_dict
ngx_shm_dict
共享内存核心模块(红黑树,队列)
ngx_shm_dict_manager
添加定时器事件,定时的清除共享内存中过期的key
添加读事件,支持redis协议,通过redis-cli get,set,del,ttl
ngx_shm_dict_view
共享内存查看
现在注册滴滴云,有机会可得30元无门槛滴滴出行券
新购云服务1月5折 3月4.5折 6月低至4折
滴滴云使者招募,推荐最高返佣50%
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。