{"id":452820,"date":"2025-03-23T15:04:09","date_gmt":"2025-03-23T15:04:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=452820"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=452820","title":{"rendered":"<span>\u041a\u043e\u0440\u043e\u0442\u043a\u043e \u043f\u0440\u043e \u0442\u043e, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f Angie<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0438, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u00a0\u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f <a href=\"https:\/\/angie.software\/\">Angie <\/a>\u2014 \u0444\u043e\u0440\u043a\u0430 Nginx, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0440\u043e\u0441 \u0432\u00a0\u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u0441\u0442\u0440\u0430 \u0441\u00a0\u043a\u0443\u0447\u0435\u0439 \u0444\u0438\u0447. <\/p>\n<h3>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0430 Angie<\/h3>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f, \u0447\u0442\u043e\u00a0\u0442\u0430\u043a\u043e\u0435 \u043c\u043e\u0434\u0443\u043b\u044c \u0432\u00a0\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 Angie (\u0438 Nginx, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e\u00a0\u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u043e\u0445\u043e\u0436\u0430).<\/p>\n<p>\u0412\u0430\u0436\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b:<\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c\u00a0\u2014 \u044d\u0442\u043e C\u2011\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 (\u0435\u0441\u043b\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 DSO) \u0438\u043b\u0438\u00a0\u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u00a0\u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043d \u043c\u043e\u0436\u0435\u0442 <strong>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u0432\u00a0\u043a\u043e\u043d\u0444\u0438\u0433<\/strong>, \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043c\u0435\u043d\u044f\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0445\u0443\u043a\u0438: <code>preconfiguration<\/code>, <code>postconfiguration<\/code>, <code>init_module<\/code>, <code>init_process<\/code>, <code>handler <\/code>\u0438 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c <strong>\u0444\u0438\u043b\u044c\u0442\u0440\u044b<\/strong>, <strong>\u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b<\/strong>, <strong>\u043b\u043e\u0433\u0435\u0440\u044b<\/strong> \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043c\u0435\u043d\u044f\u0442\u044c \u0447\u0442\u043e\u00a0\u0443\u0433\u043e\u0434\u043d\u043e.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0413\u043e\u0442\u043e\u0432\u0438\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435<\/h4>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0432\u0441\u0451 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435:<\/p>\n<pre><code class=\"bash\"># \u0421\u0442\u0430\u0432\u0438\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 sudo apt update &amp;&amp; sudo apt install build-essential libpcre3-dev libssl-dev zlib1g-dev  # \u041a\u043b\u043e\u043d\u0438\u043c Angie (\u0435\u0441\u043b\u0438 \u0443 \u0442\u0435\u0431\u044f \u0435\u0433\u043e \u043d\u0435\u0442) git clone https:\/\/github.com\/angie-web\/angie.git &amp;&amp; cd angie  # \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u043a\u0443 .\/configure --with-debug --add-dynamic-module=..\/my_module make &amp;&amp; sudo make install<\/code><\/pre>\n<p>\u0412 <code>--add-dynamic-module<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0443\u0442\u044c \u043a\u00a0\u043d\u0430\u0448\u0435\u043c\u0443 \u0431\u0443\u0434\u0443\u0449\u0435\u043c\u0443 \u043c\u043e\u0434\u0443\u043b\u044e.<\/p>\n<h3>\u041f\u0438\u0448\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c<\/h3>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437\u00a0\u0434\u0432\u0443\u0445 \u0447\u0430\u0441\u0442\u0435\u0439:<\/p>\n<ol>\n<li>\n<p><strong>\u041a\u043e\u0434\u0430 \u0441\u0430\u043c\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430<\/strong><\/p>\n<\/li>\n<\/ol>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"bash\">mkdir -p ~\/my_module\/src cd ~\/my_module<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c <code>src\/ngx_http_my_module.c<\/code> \u0438 \u0437\u0430\u043f\u0438\u0445\u0438\u0432\u0430\u0435\u043c \u0442\u0443\u0434\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cs\">#include &lt;ngx_config.h&gt; #include &lt;ngx_core.h&gt; #include &lt;ngx_http.h&gt;  static ngx_int_t ngx_http_my_handler(ngx_http_request_t *r) {     ngx_str_t response = ngx_string(\"Hello from my module!\");          r-&gt;headers_out.status = NGX_HTTP_OK;     r-&gt;headers_out.content_length_n = response.len;     ngx_http_send_header(r);          ngx_buf_t *b = ngx_create_temp_buf(r-&gt;pool, response.len);     ngx_memcpy(b-&gt;pos, response.data, response.len);     b-&gt;last = b-&gt;pos + response.len;     b-&gt;last_buf = 1;          ngx_chain_t out = { .buf = b, .next = NULL };     return ngx_http_output_filter(r, &amp;out); }  static ngx_command_t ngx_http_my_commands[] = {     { ngx_string(\"my_directive\"),       NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,       ngx_conf_set_flag_slot,       NGX_HTTP_LOC_CONF_OFFSET,       offsetof(ngx_http_conf_t, my_enabled),       NULL },     ngx_null_command };  static ngx_http_module_t ngx_http_my_module_ctx = {     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };  ngx_module_t ngx_http_my_module = {     NGX_MODULE_V1,     &amp;ngx_http_my_module_ctx,     ngx_http_my_commands,     NGX_HTTP_MODULE,     NULL, NULL, NULL, NULL, NULL, NULL, NULL,     NGX_MODULE_V1_PADDING };<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u043e\u0432\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443 my_directive, \u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430, \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u00abHello from my module!\u00bb \u043d\u0430\u00a0HTTP\u2011\u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c config \u0444\u0430\u0439\u043b:<\/p>\n<pre><code class=\"bash\">echo \"ngx_addon_name=\\\"ngx_http_my_module\\\" HTTP_MODULES=\"\\$HTTP_MODULES ngx_http_my_module\" NGX_ADDON_SRCS=\"\\$NGX_ADDON_SRCS \\$(ngx_feature_path ngx_http_my_module.c)\"\" &gt; config<\/code><\/pre>\n<h4>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c<\/h4>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u044c:<\/p>\n<pre><code class=\"bash\">cd ~\/my_module make -f ..\/angie\/objs\/Makefile modules<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f <code>.so<\/code> \u0444\u0430\u0439\u043b \u0432 <code>objs\/ngx_http_my_module.so<\/code>. \u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432 <code>angie.conf<\/code>:<\/p>\n<pre><code class=\"nginx\">load_module modules\/ngx_http_my_module.so;  server {     listen 8080;      location \/test {         my_directive;     } }<\/code><\/pre>\n<p>\u0420\u0435\u0441\u0442\u0430\u0440\u0442\u0443\u0435\u043c Angie \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c:<\/p>\n<pre><code class=\"bash\">curl -i http:\/\/localhost:8080\/test<\/code><\/pre>\n<p>\u0414\u043e\u043b\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f:<\/p>\n<pre><code>HTTP\/1.1 200 OK ... Hello from my module!<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0434\u0443\u043b\u044c \u0433\u043e\u0442\u043e\u0432.<\/p>\n<h4>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0438\u0447\u0438<\/h4>\n<p>\u041f\u043e\u043a\u0430 \u043d\u0430\u0448 \u043c\u043e\u0434\u0443\u043b\u044c \u0442\u0443\u043f\u043e \u0448\u043b\u0451\u0442 \u0442\u0435\u043a\u0441\u0442, \u043d\u043e\u00a0\u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0447\u0442\u043e\u2011\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ul>\n<li>\n<p>\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e\u00a0\u0442\u043e\u043a\u0435\u043d\u0443<\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u00a0\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439:<\/p>\n<pre><code class=\"cs\">static ngx_int_t ngx_http_my_auth_handler(ngx_http_request_t *r) {     ngx_str_t token = ngx_string(\"supersecuretoken\");          if (r-&gt;headers_in.authorization == NULL ||         ngx_strncmp(r-&gt;headers_in.authorization-&gt;value.data, token.data, token.len) != 0) {         return NGX_HTTP_FORBIDDEN;     }          return NGX_DECLINED; }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u043e\u0442\u0434\u0430\u0447\u0435\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>Authorization<\/code>.<\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u043e\u0442\u0434\u0430\u0447\u0435\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a Authorization.<\/p>\n<p><strong>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b<\/strong><\/p>\n<pre><code class=\"cs\">static ngx_int_t ngx_http_my_logger_handler(ngx_http_request_t *r) {     ngx_log_error(NGX_LOG_INFO, r-&gt;connection-&gt;log, 0, \"Incoming request: %V\", &amp;r-&gt;uri);     return NGX_DECLINED; }<\/code><\/pre>\n<p><strong>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043e\u0442\u00a0\u043e\u0434\u043d\u043e\u0433\u043e IP<\/strong><\/p>\n<pre><code class=\"cs\">static ngx_int_t ngx_http_rate_limit_handler(ngx_http_request_t *r) {     static ngx_rbtree_t *request_tracker;     static ngx_rbtree_node_t sentinel;          if (request_tracker == NULL) {         request_tracker = ngx_pcalloc(r-&gt;pool, sizeof(ngx_rbtree_t));         ngx_rbtree_init(request_tracker, &amp;sentinel, ngx_str_rbtree_insert_value);     }          ngx_rbtree_node_t *node = ngx_rbtree_lookup(request_tracker, &amp;r-&gt;connection-&gt;addr_text);          if (node == NULL) {         node = ngx_pcalloc(r-&gt;pool, sizeof(ngx_rbtree_node_t));         node-&gt;key = ngx_crc32_short(r-&gt;connection-&gt;addr_text.data, r-&gt;connection-&gt;addr_text.len);         ngx_rbtree_insert(request_tracker, node);     }          if (node-&gt;data &gt;= 10) {         return NGX_HTTP_TOO_MANY_REQUESTS;     }          node-&gt;data++;     return NGX_DECLINED; }<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043e\u0442\u00a0\u043e\u0434\u043d\u043e\u0433\u043e IP \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0438\u0445.<\/p>\n<p><strong>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u0430<\/strong><\/p>\n<pre><code class=\"cs\">static ngx_int_t ngx_http_add_dynamic_header_handler(ngx_http_request_t *r) {     ngx_table_elt_t *h = ngx_list_push(&amp;r-&gt;headers_out.headers);     h-&gt;hash = 1;     ngx_str_set(&amp;h-&gt;key, \"X-Server-Time\");     h-&gt;value.data = ngx_pnalloc(r-&gt;pool, NGX_TIME_T_LEN);     h-&gt;value.len = ngx_sprintf(h-&gt;value.data, \"%T\", ngx_time()) - h-&gt;value.data;     return NGX_DECLINED; }<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a X\u2011Server\u2011Time \u0441\u00a0\u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c.<\/p>\n<hr\/>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c: \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b, \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c Redis. \u041d\u0430\u043f\u0438\u0448\u0438 \u0432\u00a0\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0445, \u043a\u0430\u043a\u0438\u0435 \u0435\u0449\u0451 \u043c\u043e\u0434\u0443\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c! <\/p>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u043f\u043e\u043c\u043d\u044e \u043f\u0440\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0435 \u0443\u0440\u043e\u043a\u0438 \u043f\u043e Angie:<\/p>\n<ul>\n<li>\n<p><strong>17 \u043c\u0430\u0440\u0442\u0430. \u0411\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0430 HTTP \u0438 L4 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0432 Angie.<\/strong><br \/>\u041f\u043e\u0439\u043c\u0451\u0442\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u0432 Angie, \u043d\u0430\u0443\u0447\u0438\u0442\u0435\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u0438 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. <a href=\"https:\/\/otus.pw\/Xh4V\/\">\u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f<\/a><\/p>\n<\/li>\n<li>\n<p><strong>24 \u043c\u0430\u0440\u0442\u0430. \u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 TLS-\u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u044b: \u043c\u043e\u0434\u0443\u043b\u044c ACME.<\/strong><br \/>\u041d\u0430\u0443\u0447\u0438\u0442\u0435\u0441\u044c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c ACME \u0432 Angie, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c HTTPS-\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435. <a href=\"https:\/\/otus.pw\/3ygK\/\">\u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/890026\/\"> https:\/\/habr.com\/ru\/articles\/890026\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0438, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u00a0\u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f <a href=\"https:\/\/angie.software\/\">Angie <\/a>\u2014 \u0444\u043e\u0440\u043a\u0430 Nginx, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0440\u043e\u0441 \u0432\u00a0\u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u0441\u0442\u0440\u0430 \u0441\u00a0\u043a\u0443\u0447\u0435\u0439 \u0444\u0438\u0447. <\/p>\n<h3>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0430 Angie<\/h3>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f, \u0447\u0442\u043e\u00a0\u0442\u0430\u043a\u043e\u0435 \u043c\u043e\u0434\u0443\u043b\u044c \u0432\u00a0\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 Angie (\u0438 Nginx, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e\u00a0\u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u043e\u0445\u043e\u0436\u0430).<\/p>\n<p>\u0412\u0430\u0436\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b:<\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c\u00a0\u2014 \u044d\u0442\u043e C\u2011\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 (\u0435\u0441\u043b\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 DSO) \u0438\u043b\u0438\u00a0\u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u00a0\u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043d \u043c\u043e\u0436\u0435\u0442 <strong>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u0432\u00a0\u043a\u043e\u043d\u0444\u0438\u0433<\/strong>, \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043c\u0435\u043d\u044f\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0445\u0443\u043a\u0438: <code>preconfiguration<\/code>, <code>postconfiguration<\/code>, <code>init_module<\/code>, <code>init_process<\/code>, <code>handler <\/code>\u0438 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c <strong>\u0444\u0438\u043b\u044c\u0442\u0440\u044b<\/strong>, <strong>\u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b<\/strong>, <strong>\u043b\u043e\u0433\u0435\u0440\u044b<\/strong> \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043c\u0435\u043d\u044f\u0442\u044c \u0447\u0442\u043e\u00a0\u0443\u0433\u043e\u0434\u043d\u043e.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0413\u043e\u0442\u043e\u0432\u0438\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435<\/h4>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0432\u0441\u0451 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435:<\/p>\n<pre><code class=\"bash\"># \u0421\u0442\u0430\u0432\u0438\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 sudo apt update &amp;&amp; sudo apt install build-essential libpcre3-dev libssl-dev zlib1g-dev  # \u041a\u043b\u043e\u043d\u0438\u043c Angie (\u0435\u0441\u043b\u0438 \u0443 \u0442\u0435\u0431\u044f \u0435\u0433\u043e \u043d\u0435\u0442) git clone https:\/\/github.com\/angie-web\/angie.git &amp;&amp; cd angie  # \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u043a\u0443 .\/configure --with-debug --add-dynamic-module=..\/my_module make &amp;&amp; sudo make install<\/code><\/pre>\n<p>\u0412 <code>--add-dynamic-module<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0443\u0442\u044c \u043a\u00a0\u043d\u0430\u0448\u0435\u043c\u0443 \u0431\u0443\u0434\u0443\u0449\u0435\u043c\u0443 \u043c\u043e\u0434\u0443\u043b\u044e.<\/p>\n<h3>\u041f\u0438\u0448\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c<\/h3>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437\u00a0\u0434\u0432\u0443\u0445 \u0447\u0430\u0441\u0442\u0435\u0439:<\/p>\n<ol>\n<li>\n<p><strong>\u041a\u043e\u0434\u0430 \u0441\u0430\u043c\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430<\/strong><\/p>\n<\/li>\n<\/ol>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"bash\">mkdir -p ~\/my_module\/src cd ~\/my_module<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c <code>src\/ngx_http_my_module.c<\/code> \u0438 \u0437\u0430\u043f\u0438\u0445\u0438\u0432\u0430\u0435\u043c \u0442\u0443\u0434\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cs\">#include &lt;ngx_config.h&gt; #include &lt;ngx_core.h&gt; #include &lt;ngx_http.h&gt;  static ngx_int_t ngx_http_my_handler(ngx_http_request_t *r) {     ngx_str_t response = ngx_string(\"Hello from my module!\");          r-&gt;headers_out.status = NGX_HTTP_OK;     r-&gt;headers_out.content_length_n = response.len;     ngx_http_send_header(r);          ngx_buf_t *b = ngx_create_temp_buf(r-&gt;pool, response.len);     ngx_memcpy(b-&gt;pos, response.data, response.len);     b-&gt;last = b-&gt;pos + response.len;     b-&gt;last_buf = 1;          ngx_chain_t out = { .buf = b, .next = NULL };     return ngx_http_output_filter(r, &amp;out); }  static ngx_command_t ngx_http_my_commands[] = {     { ngx_string(\"my_directive\"),       NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,       ngx_conf_set_flag_slot,       NGX_HTTP_LOC_CONF_OFFSET,       offsetof(ngx_http_conf_t, my_enabled),       NULL },     ngx_null_command };  static ngx_http_module_t ngx_http_my_module_ctx = {     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };  ngx_module_t ngx_http_my_module = {     NGX_MODULE_V1,     &amp;ngx_http_my_module_ctx,     ngx_http_my_commands,     NGX_HTTP_MODULE,     NULL, NULL, NULL, NULL, NULL, NULL, NULL,     NGX_MODULE_V1_PADDING };<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u043e\u0432\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443 my_directive, \u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430, \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u00abHello from my module!\u00bb \u043d\u0430\u00a0HTTP\u2011\u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c config \u0444\u0430\u0439\u043b:<\/p>\n<pre><code class=\"bash\">echo \"ngx_addon_name=\\\"ngx_http_my_module\\\" HTTP_MODULES=\"\\$HTTP_MODULES ngx_http_my_module\" NGX_ADDON_SRCS=\"\\$NGX_ADDON_SRCS \\$(ngx_feature_path ngx_http_my_module.c)\"\" &gt; config<\/code><\/pre>\n<h4>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c<\/h4>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u044c:<\/p>\n<pre><code class=\"bash\">cd ~\/my_module make -f ..\/angie\/objs\/Makefile modules<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f <code>.so<\/code> \u0444\u0430\u0439\u043b \u0432 <code>objs\/ngx_http_my_module.so<\/code>. \u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432 <code>angie.conf<\/code>:<\/p>\n<pre><code class=\"nginx\">load_module modules\/ngx_http_my_module.so;  server {     listen 8080;      location \/test {         my_directive;     } }<\/code><\/pre>\n<p>\u0420\u0435\u0441\u0442\u0430\u0440\u0442\u0443\u0435\u043c Angie \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c:<\/p>\n<pre><code class=\"bash\">curl -i http:\/\/localhost:8080\/test<\/code><\/pre>\n<p>\u0414\u043e\u043b\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f:<\/p>\n<pre><code>HTTP\/1.1 200 OK ... Hello from my module!<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0434\u0443\u043b\u044c \u0433\u043e\u0442\u043e\u0432.<\/p>\n<h4>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0438\u0447\u0438<\/h4>\n<p>\u041f\u043e\u043a\u0430 \u043d\u0430\u0448 \u043c\u043e\u0434\u0443\u043b\u044c \u0442\u0443\u043f\u043e \u0448\u043b\u0451\u0442 \u0442\u0435\u043a\u0441\u0442, \u043d\u043e\u00a0\u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0447\u0442\u043e\u2011\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ul>\n<li>\n<p>\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e\u00a0\u0442\u043e\u043a\u0435\u043d\u0443<\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u00a0\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439:<\/p>\n<pre><code class=\"cs\">static ngx_int_t ngx_http_my_auth_handler(ngx_http_request_t *r) {     ngx_str_t token = ngx_string(\"supersecuretoken\");          if (r-&gt;headers_in.authorization == NULL ||         ngx_strncmp(r-&gt;headers_in.authorization-&gt;value.data, token.data, token.len) != 0) {         return NGX_HTTP_FORBIDDEN;     }          return NGX_DECLINED; }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u043e\u0442\u0434\u0430\u0447\u0435\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>Authorization<\/code>.<\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u043e\u0442\u0434\u0430\u0447\u0435\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a Authorization.<\/p>\n<p><strong>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b<\/strong><\/p>\n<pre><code class=\"cs\">static ngx_int_t ngx_http_my_logger_handler(ngx_http_request_t *r) {     ngx_log_error(NGX_LOG_INFO, r-&gt;connection-&gt;log, 0, \"Incoming request: %V\", &amp;r-&gt;uri);     return NGX_DECLINED; }<\/code><\/pre>\n<p><strong>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043e\u0442\u00a0\u043e\u0434\u043d\u043e\u0433\u043e IP<\/strong><\/p>\n<pre><code class=\"cs\">static ngx_int_t ngx_http_rate_limit_handler(ngx_http_request_t *r) {     static ngx_rbtree_t *request_tracker;     static ngx_rbtree_node_t sentinel;          if (request_tracker == NULL) {         request_tracker = ngx_pcalloc(r-&gt;pool, sizeof(ngx_rbtree_t));         ngx_rbtree_init(request_tracker, &amp;sentinel, ngx_str_rbtree_insert_value);     }          ngx_rbtree_node_t *node = ngx_rbtree_lookup(request_tracker, &amp;r-&gt;connection-&gt;addr_text);          if (node == NULL) {         node = ngx_pcalloc(r-&gt;pool, sizeof(ngx_rbtree_node_t));         node-&gt;key = ngx_crc32_short(r-&gt;connection-&gt;addr_text.data, r-&gt;connection-&gt;addr_text.len);         ngx_rbtree_insert(request_tracker, node);     }          if (node-&gt;data &gt;= 10) {         return NGX_HTTP_TOO_MANY_REQUESTS;     }          node-&gt;data++;     return NGX_DECLINED; }<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043e\u0442\u00a0\u043e\u0434\u043d\u043e\u0433\u043e IP \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0438\u0445.<\/p>\n<p><strong>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u0430<\/strong><\/p>\n<pre><code class=\"cs\">static ngx_int_t ngx_http_add_dynamic_header_handler(ngx_http_request_t *r) {     ngx_table_elt_t *h = ngx_list_push(&amp;r-&gt;headers_out.headers);     h-&gt;hash = 1;     ngx_str_set(&amp;h-&gt;key, \"X-Server-Time\");     h-&gt;value.data = ngx_pnalloc(r-&gt;pool, NGX_TIME_T_LEN);     h-&gt;value.len = ngx_sprintf(h-&gt;value.data, \"%T\", ngx_time()) - h-&gt;value.data;     return NGX_DECLINED; }<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a X\u2011Server\u2011Time \u0441\u00a0\u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c.<\/p>\n<hr\/>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c: \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b, \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c Redis. \u041d\u0430\u043f\u0438\u0448\u0438 \u0432\u00a0\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0445, \u043a\u0430\u043a\u0438\u0435 \u0435\u0449\u0451 \u043c\u043e\u0434\u0443\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c! <\/p>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u043f\u043e\u043c\u043d\u044e \u043f\u0440\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0435 \u0443\u0440\u043e\u043a\u0438 \u043f\u043e Angie:<\/p>\n<ul>\n<li>\n<p><strong>17 \u043c\u0430\u0440\u0442\u0430. \u0411\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0430 HTTP \u0438 L4 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0432 Angie.<\/strong><br \/>\u041f\u043e\u0439\u043c\u0451\u0442\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u0432 Angie, \u043d\u0430\u0443\u0447\u0438\u0442\u0435\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u0438 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. <a href=\"https:\/\/otus.pw\/Xh4V\/\">\u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f<\/a><\/p>\n<\/li>\n<li>\n<p><strong>24 \u043c\u0430\u0440\u0442\u0430. \u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 TLS-\u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u044b: \u043c\u043e\u0434\u0443\u043b\u044c ACME.<\/strong><br \/>\u041d\u0430\u0443\u0447\u0438\u0442\u0435\u0441\u044c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c ACME \u0432 Angie, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c HTTPS-\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435. <a href=\"https:\/\/otus.pw\/3ygK\/\">\u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/890026\/\"> https:\/\/habr.com\/ru\/articles\/890026\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-452820","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/452820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=452820"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/452820\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=452820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=452820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=452820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}