{"id":456955,"date":"2025-04-22T15:01:12","date_gmt":"2025-04-22T15:01:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=456955"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=456955","title":{"rendered":"<span>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0434\u0451\u0448\u0435\u0432\u043e \u0438 \u0441\u0435\u0440\u0434\u0438\u0442\u043e<\/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<blockquote>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0439 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d<a href=\"https:\/\/github.com\/tripolskypetr\/bun-ngx-upstream-websocket-bus\" rel=\"noopener noreferrer nofollow\"> \u0432 \u044d\u0442\u043e\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a><\/p>\n<\/blockquote>\n<p>\u041d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 backend \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f DevOps, \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0443\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u043a\u043e\u043c\u0443 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c <a href=\"https:\/\/www.envoyproxy.io\/\" rel=\"noopener noreferrer nofollow\">Envoy proxy<\/a>: \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u044f \u0446\u0435\u043b\u0435\u0432\u043e\u0439 gRPC \u043f\u043e\u0440\u0442 \u0431\u0435\u0437 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043f\u0440\u043e\u0441\u043b\u043e\u0439\u043a\u0438.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/44e\/e17\/8db\/44ee178dbac1ffb5672455ad0ffcd0a3.png\" alt=\"\u0414\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0441\u0435\u0440\u0432\u0435\u0440 \u043b\u0435\u0442\u0430\u043b\" title=\"\u0414\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0441\u0435\u0440\u0432\u0435\u0440 \u043b\u0435\u0442\u0430\u043b\" width=\"750\" height=\"521\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/44e\/e17\/8db\/44ee178dbac1ffb5672455ad0ffcd0a3.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/44e\/e17\/8db\/44ee178dbac1ffb5672455ad0ffcd0a3.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0414\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0441\u0435\u0440\u0432\u0435\u0440 \u043b\u0435\u0442\u0430\u043b<\/figcaption><\/div>\n<\/figure>\n<h2>\u0423\u0434\u0435\u0448\u0435\u0432\u043b\u044f\u0435\u043c \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b<\/h2>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u043b\u043e\u0439\u043a\u0443 NGinx \u043c\u0435\u0436\u0434\u0443 \u0446\u0435\u043b\u0435\u0432\u044b\u043c backend \u0438 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0441\u0435\u0442\u044c\u044e. \u042d\u0442\u0430 \u043f\u0440\u043e\u0441\u043b\u043e\u0439\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u043f\u0430\u0443\u0437\u0443, \u0435\u0441\u043b\u0438 backend \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f<\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439<\/h4>\n<p>\u0421\u0442\u0430\u0432\u0438\u0442\u044c NGinx \u0438 Lua \u043d\u0443\u0436\u043d\u043e \u043d\u0430 \u0445\u043e\u0441\u0442 \u043c\u0430\u0448\u0438\u043d\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a\u0443\u044e \u0435\u0440\u0438\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043f\u0440\u043e\u043f\u0438\u0448\u0443\u0442 \u0432 docker networks: <code>network_mode: host<\/code> \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043f\u043b\u044e\u0441 \u0445\u043e\u0441\u0442 \u043c\u0430\u0448\u0438\u043d\u0430 \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0440\u043e\u043a\u0441\u0438 \u043f\u043e\u0432\u0435\u0440\u0445 \u043f\u0440\u043e\u043a\u0441\u0438<\/p>\n<pre><code class=\"bash\">apt install nginx nginx-extras sudo add-apt-repository ppa:ondrej\/nginx sudo apt update apt install libnginx-mod-http-lua  sudo sysctl net.ipv4.ip_unprivileged_port_start=0 sudo tee -a \/etc\/sysctl.conf &lt;&lt;&lt; \"net.ipv4.ip_unprivileged_port_start=0\"<\/code><\/pre>\n<h4>\u0424\u0430\u0439\u043b \/etc\/nginx\/nginx.conf<\/h4>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 NGinx \u043a\u043e\u043d\u0444\u0438\u0433 \u0431\u0443\u0434\u0435\u0442 \u0436\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a backend 10 \u0441\u0435\u043a\u0443\u043d\u0434. \u0415\u0441\u043b\u0438 backend \u043d\u0435 \u043e\u0442\u0432\u0435\u0442\u0438\u043b, \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u044f\u0435\u0442\u0441\u044f html \u0441 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b: fetch \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0443\u043f\u0430\u0434\u0443\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0438 \u0444\u0440\u043e\u043d\u0442 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0441\u044f, \u0442\u043e\u043d\u043a\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0432\u0435\u0431 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u044f\u0442 \u043f\u043e\u0432\u0442\u043e\u0440 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/p>\n<pre><code class=\"nginx\">load_module \/usr\/lib\/nginx\/modules\/ndk_http_module.so; load_module \/usr\/lib\/nginx\/modules\/ngx_http_lua_module.so;  error_log \/var\/log\/nginx\/error.log warn; pid \/var\/run\/nginx.pid;  events {     worker_connections 1024;     use epoll;     multi_accept on; }  http {     log_format main '$remote_addr - $remote_user [$time_local] \"$request\" '                     '$status $body_bytes_sent \"$http_referer\" '                     '\"$http_user_agent\"';      access_log \/var\/log\/nginx\/access.log main;      map $http_upgrade $connection_upgrade {         default upgrade;         ''      close;     }      server {         listen 50050;         server_name localhost;          error_page 502 @wait_for_upstream;          location \/ {             proxy_pass http:\/\/127.0.0.1:8081$is_args$args;             proxy_http_version 1.1;             proxy_set_header Upgrade $http_upgrade;             proxy_set_header Connection $connection_upgrade;             proxy_set_header Host \"localhost\";             proxy_set_header X-Real-IP \"\";             proxy_set_header X-Forwarded-For \"\";             proxy_set_header X-Forwarded-Proto \"\";             proxy_hide_header Via;             proxy_hide_header Server;              proxy_next_upstream off;             proxy_intercept_errors on;             proxy_buffering off;         }          location @wait_for_upstream {             content_by_lua_block {                 local function is_healthy()                     local res = ngx.location.capture(\"\/health_check\", {                         method = ngx.HTTP_GET,                         args = \"target=127.0.0.1:8081\"                     })                     return res.status and res.status &lt; 400                 end                  ngx.sleep(10)                  if not is_healthy() then                     ngx.status = 200                     ngx.header[\"Content-Type\"] = \"text\/html\"                     ngx.say(\"&lt;p&gt;Updating...&lt;\/p&gt;&lt;script&gt;setTimeout(() =&gt; { window.location.reload() }, 10_000)&lt;\/script&gt;\")                     ngx.exit(ngx.HTTP_OK)                 else                     ngx.exec(\"@wait_for_upstream_proxy\")                 end             }         }          location @wait_for_upstream_proxy {             proxy_pass http:\/\/127.0.0.1:8081$is_args$args;             proxy_http_version 1.1;             proxy_set_header Upgrade $http_upgrade;             proxy_set_header Connection $connection_upgrade;             proxy_set_header Host \"localhost\";             proxy_set_header X-Real-IP \"\";             proxy_set_header X-Forwarded-For \"\";             proxy_set_header X-Forwarded-Proto \"\";             proxy_hide_header Via;             proxy_hide_header Server;              proxy_next_upstream off;             proxy_intercept_errors on;             error_page 502 503 504 = @wait_for_upstream;             proxy_buffering off;         }     } } <\/code><\/pre>\n<h2>\u0428\u0438\u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0441 \u0431\u0435\u0441\u0448\u043e\u0432\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u0440\u0435\u043f\u043b\u0438\u043a<\/h2>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440 \u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u043c\u0435\u043b \u0441\u043c\u044b\u0441\u043b, \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u0442\u0432\u0430\u043b\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439. \u0415\u0441\u043b\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0435 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0445\u043e\u0442\u044f \u0431\u044b \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u044d\u0442\u043e \u043f\u043e\u0440\u0430\u0436\u0434\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043a\u043e\u0433\u0434\u0430 \u0444\u043e\u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/221\/2d3\/484\/2212d3484b29a18eba3df16a87506652.png\" alt=\"https:\/\/bun.sh\/guides\/http\/cluster\" title=\"https:\/\/bun.sh\/guides\/http\/cluster\" width=\"1521\" height=\"874\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/221\/2d3\/484\/2212d3484b29a18eba3df16a87506652.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/221\/2d3\/484\/2212d3484b29a18eba3df16a87506652.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption><a href=\"https:\/\/bun.sh\/guides\/http\/cluster\" rel=\"noopener noreferrer nofollow\">https:\/\/bun.sh\/guides\/http\/cluster<\/a><\/figcaption><\/div>\n<\/figure>\n<p>\u0412 Linux<a href=\"https:\/\/blog.flipkart.tech\/linux-tcp-so-reuseport-usage-and-implementation-6bfbf642885a\" rel=\"noopener noreferrer nofollow\"> \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043f\u043e\u0440\u0442. <\/a>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <code>nginx_upstream<\/code>, \u043d\u0435\u0442 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u0440\u0430\u0442\u0438\u0442 \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u043c\u0435\u0440\u0442\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 event loop \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d, \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u044c\u043c\u0435\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0440\u0435\u043f\u043b\u0438\u043a\u0430. \u041e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u0432\u0435\u0449\u0435\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 \u043c\u0435\u0434\u0438\u0430 \u0444\u0430\u0439\u043b\u044b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 base64<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/898\/f6d\/0ea\/898f6d0eaed1d5bd099121086b2c9d37.png\" alt=\"https:\/\/bun.sh\/guides\/process\/ipc\" title=\"https:\/\/bun.sh\/guides\/process\/ipc\" width=\"1521\" height=\"874\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/898\/f6d\/0ea\/898f6d0eaed1d5bd099121086b2c9d37.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/898\/f6d\/0ea\/898f6d0eaed1d5bd099121086b2c9d37.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption><a href=\"https:\/\/bun.sh\/guides\/process\/ipc\" rel=\"noopener noreferrer nofollow\">https:\/\/bun.sh\/guides\/process\/ipc<\/a><\/figcaption><\/div>\n<\/figure>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0432 Linux \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u0441\u0435\u0442\u044c, \u0430 \u0444\u0430\u0439\u043b\u044b. \u042d\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0444\u0430\u0439\u043b \u043c\u043e\u0436\u043d\u043e \u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a\u0430\u044f \u0448\u0438\u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/geth.ethereum.org\/\" rel=\"noopener noreferrer nofollow\">GETH <\/a>&#8212; \u043d\u043e\u0434\u0435 \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d\u0430 Ethereum, \u0434\u043b\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f GUI \u0441 \u043a\u043e\u0448\u0435\u043b\u044c\u043a\u043e\u043c<\/p>\n<p><strong>ecosystem.config.js<\/strong><\/p>\n<p>\u041d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0440\u0435\u043f\u043b\u0438\u043a\u0443 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u043f\u043e\u0440\u0442. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0443\u043f\u0430\u0434\u0435\u0442. \u0412\u043d\u0443\u0442\u0440\u0438 \u0432\u0435\u0431 \u0441 \u041f\u0440\u043e\u043f\u0438\u0441\u0430\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0440\u0442\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u043f\u044f\u0442\u0443\u044e, \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u044b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u043f\u043b\u0438\u043a\u0438<\/p>\n<pre><code class=\"javascript\">const path = require(\"path\"); const os = require(\"os\"); const dotenv = require(\"dotenv\");  const readConfig = () =&gt; dotenv.parse(\".\/.env\");  const getPath = (unixPath) =&gt; {   return path.resolve(unixPath.replace(\"~\", os.homedir())); };  const apps = [   {     name: \"bun-ws-1\",     exec_mode: \"fork\",     instances: \"1\",     autorestart: true,     cron_restart: \"0 0 * * *\",     max_memory_restart: \"1250M\",     script: \".\/packages\/backend\/src\/index.ts\",     interpreter: getPath(\"~\/.bun\/bin\/bun\"),     env: readConfig(),     args: [\"--bootstrap=8081,8082,8083,8084,8085\"],     out_file: \".\/logs\/pm2\/bun-ws-1-out.log\",     error_file: \".\/logs\/pm2\/bun-ws-1-error.log\",     log_date_format: \"YYYY-MM-DD HH:mm:ss\",     merge_logs: true,   }, ];  module.exports = {   apps, }; <\/code><\/pre>\n<p><strong>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong><\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u043c\u0435\u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f bootstrapService. \u0422\u0430\u043a \u043a\u0430\u043a \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 websocket \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u044d\u0442\u043e \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0439\u0441\u044f HTTP \u0437\u0430\u043f\u0440\u043e\u0441, \u043e\u043d \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u043e\u0434\u043d\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0435 \u0438 \u043d\u0435 \u0448\u0430\u0440\u0438\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. <\/p>\n<pre><code class=\"typescript\">import { errorData, getErrorMessage } from \"functools-kit\"; import type { NotifyRequest } from \"..\/model\/NotifyRequest.model\"; import { app } from \"..\/config\/app\"; import { ioc } from \"..\/lib\";  const { port } = ioc.bootstrapService.getArgs();  app.post(\"\/api\/v1\/notify\", async (ctx) =&gt; {   const request = await ctx.req.json&lt;NotifyRequest&gt;();   ioc.bootstrapService.broadcast(\"broadcast\", {     clientId: request.clientId,     requestId: request.requestId,     port,   }); });<\/code><\/pre>\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 <code>broadcast<\/code>. \u041f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u0440\u0435\u043f\u043b\u0438\u043a\u0435 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 <code>listen<\/code><\/p>\n<pre><code class=\"typescript\">  ioc.bootstrapService.listen(({ topic, data }) =&gt; {     if (server.subscriberCount(topic)) {       console.log(\"Publishing\", { topic, data });       server.publish(topic, JSON.stringify(data));     }   });<\/code><\/pre>\n<p><strong>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0439 WebSocket<\/strong><\/p>\n<p>\u0423 bun \u0435\u0441\u0442\u044c pubsub \u0432\u0435\u0449\u0430\u043d\u0438\u0435 \u0434\u043b\u044f ws \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439. \u042d\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d1b\/d9e\/533\/d1bd9e533af8abc475fd20b2098dfbc6.png\" alt=\"https:\/\/bun.sh\/guides\/websocket\/pubsub\" title=\"https:\/\/bun.sh\/guides\/websocket\/pubsub\" width=\"1521\" height=\"874\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/d1b\/d9e\/533\/d1bd9e533af8abc475fd20b2098dfbc6.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d1b\/d9e\/533\/d1bd9e533af8abc475fd20b2098dfbc6.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption><a href=\"https:\/\/bun.sh\/guides\/websocket\/pubsub\" rel=\"noopener noreferrer nofollow\">https:\/\/bun.sh\/guides\/websocket\/pubsub<\/a><\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0440\u0435\u043f\u043b\u0438\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0430 ws \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0438<\/p>\n<pre><code class=\"typescript\">app.get(   \"\/api\/v1\/listen\",   upgradeWebSocket((c) =&gt; {     return {       onOpen: (_, ws) =&gt; {         const bunWs = ws.raw!;         bunWs.subscribe(\"broadcast\");         ws.send(JSON.stringify({ port }))       },       onClose: (_, ws) =&gt; {         const bunWs = ws.raw!;         bunWs.unsubscribe(\"broadcast\");       },     };   }) ); <\/code><\/pre>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u044d\u0442\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0435\u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043a\u043e\u0433\u0434\u0430 \u0448\u0438\u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430. \u0414\u043b\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0449\u0435 \u0432\u0435\u0441\u0442\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0443 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0437\u0430\u043f\u0440\u043e\u0441-\u043e\u0442\u0432\u0435\u0442.<\/p>\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\/903222\/\"> https:\/\/habr.com\/ru\/articles\/903222\/<\/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<blockquote>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0439 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d<a href=\"https:\/\/github.com\/tripolskypetr\/bun-ngx-upstream-websocket-bus\" rel=\"noopener noreferrer nofollow\"> \u0432 \u044d\u0442\u043e\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a><\/p>\n<\/blockquote>\n<p>\u041d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 backend \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f DevOps, \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0443\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u043a\u043e\u043c\u0443 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c <a href=\"https:\/\/www.envoyproxy.io\/\" rel=\"noopener noreferrer nofollow\">Envoy proxy<\/a>: \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u044f \u0446\u0435\u043b\u0435\u0432\u043e\u0439 gRPC \u043f\u043e\u0440\u0442 \u0431\u0435\u0437 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043f\u0440\u043e\u0441\u043b\u043e\u0439\u043a\u0438.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0414\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0441\u0435\u0440\u0432\u0435\u0440 \u043b\u0435\u0442\u0430\u043b<\/figcaption><\/div>\n<\/figure>\n<h2>\u0423\u0434\u0435\u0448\u0435\u0432\u043b\u044f\u0435\u043c \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b<\/h2>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u043b\u043e\u0439\u043a\u0443 NGinx \u043c\u0435\u0436\u0434\u0443 \u0446\u0435\u043b\u0435\u0432\u044b\u043c backend \u0438 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0441\u0435\u0442\u044c\u044e. \u042d\u0442\u0430 \u043f\u0440\u043e\u0441\u043b\u043e\u0439\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u043f\u0430\u0443\u0437\u0443, \u0435\u0441\u043b\u0438 backend \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f<\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439<\/h4>\n<p>\u0421\u0442\u0430\u0432\u0438\u0442\u044c NGinx \u0438 Lua \u043d\u0443\u0436\u043d\u043e \u043d\u0430 \u0445\u043e\u0441\u0442 \u043c\u0430\u0448\u0438\u043d\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a\u0443\u044e \u0435\u0440\u0438\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043f\u0440\u043e\u043f\u0438\u0448\u0443\u0442 \u0432 docker networks: <code>network_mode: host<\/code> \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043f\u043b\u044e\u0441 \u0445\u043e\u0441\u0442 \u043c\u0430\u0448\u0438\u043d\u0430 \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0440\u043e\u043a\u0441\u0438 \u043f\u043e\u0432\u0435\u0440\u0445 \u043f\u0440\u043e\u043a\u0441\u0438<\/p>\n<pre><code class=\"bash\">apt install nginx nginx-extras sudo add-apt-repository ppa:ondrej\/nginx sudo apt update apt install libnginx-mod-http-lua  sudo sysctl net.ipv4.ip_unprivileged_port_start=0 sudo tee -a \/etc\/sysctl.conf &lt;&lt;&lt; \"net.ipv4.ip_unprivileged_port_start=0\"<\/code><\/pre>\n<h4>\u0424\u0430\u0439\u043b \/etc\/nginx\/nginx.conf<\/h4>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 NGinx \u043a\u043e\u043d\u0444\u0438\u0433 \u0431\u0443\u0434\u0435\u0442 \u0436\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a backend 10 \u0441\u0435\u043a\u0443\u043d\u0434. \u0415\u0441\u043b\u0438 backend \u043d\u0435 \u043e\u0442\u0432\u0435\u0442\u0438\u043b, \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u044f\u0435\u0442\u0441\u044f html \u0441 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b: fetch \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0443\u043f\u0430\u0434\u0443\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0438 \u0444\u0440\u043e\u043d\u0442 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0441\u044f, \u0442\u043e\u043d\u043a\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0432\u0435\u0431 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u044f\u0442 \u043f\u043e\u0432\u0442\u043e\u0440 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/p>\n<pre><code class=\"nginx\">load_module \/usr\/lib\/nginx\/modules\/ndk_http_module.so; load_module \/usr\/lib\/nginx\/modules\/ngx_http_lua_module.so;  error_log \/var\/log\/nginx\/error.log warn; pid \/var\/run\/nginx.pid;  events {     worker_connections 1024;     use epoll;     multi_accept on; }  http {     log_format main '$remote_addr - $remote_user [$time_local] \"$request\" '                     '$status $body_bytes_sent \"$http_referer\" '                     '\"$http_user_agent\"';      access_log \/var\/log\/nginx\/access.log main;      map $http_upgrade $connection_upgrade {         default upgrade;         ''      close;     }      server {         listen 50050;         server_name localhost;          error_page 502 @wait_for_upstream;          location \/ {             proxy_pass http:\/\/127.0.0.1:8081$is_args$args;             proxy_http_version 1.1;             proxy_set_header Upgrade $http_upgrade;             proxy_set_header Connection $connection_upgrade;             proxy_set_header Host \"localhost\";             proxy_set_header X-Real-IP \"\";             proxy_set_header X-Forwarded-For \"\";             proxy_set_header X-Forwarded-Proto \"\";             proxy_hide_header Via;             proxy_hide_header Server;              proxy_next_upstream off;             proxy_intercept_errors on;             proxy_buffering off;         }          location @wait_for_upstream {             content_by_lua_block {                 local function is_healthy()                     local res = ngx.location.capture(\"\/health_check\", {                         method = ngx.HTTP_GET,                         args = \"target=127.0.0.1:8081\"                     })                     return res.status and res.status &lt; 400                 end                  ngx.sleep(10)                  if not is_healthy() then                     ngx.status = 200                     ngx.header[\"Content-Type\"] = \"text\/html\"                     ngx.say(\"&lt;p&gt;Updating...&lt;\/p&gt;&lt;script&gt;setTimeout(() =&gt; { window.location.reload() }, 10_000)&lt;\/script&gt;\")                     ngx.exit(ngx.HTTP_OK)                 else                     ngx.exec(\"@wait_for_upstream_proxy\")                 end             }         }          location @wait_for_upstream_proxy {             proxy_pass http:\/\/127.0.0.1:8081$is_args$args;             proxy_http_version 1.1;             proxy_set_header Upgrade $http_upgrade;             proxy_set_header Connection $connection_upgrade;             proxy_set_header Host \"localhost\";             proxy_set_header X-Real-IP \"\";             proxy_set_header X-Forwarded-For \"\";             proxy_set_header X-Forwarded-Proto \"\";             proxy_hide_header Via;             proxy_hide_header Server;              proxy_next_upstream off;             proxy_intercept_errors on;             error_page 502 503 504 = @wait_for_upstream;             proxy_buffering off;         }     } } <\/code><\/pre>\n<h2>\u0428\u0438\u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0441 \u0431\u0435\u0441\u0448\u043e\u0432\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u0440\u0435\u043f\u043b\u0438\u043a<\/h2>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440 \u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u043c\u0435\u043b \u0441\u043c\u044b\u0441\u043b, \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u0442\u0432\u0430\u043b\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439. \u0415\u0441\u043b\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0435 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0445\u043e\u0442\u044f \u0431\u044b \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u044d\u0442\u043e \u043f\u043e\u0440\u0430\u0436\u0434\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043a\u043e\u0433\u0434\u0430 \u0444\u043e\u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e.<\/p>\n<figure class=\"full-width\">\n<div><figcaption><a href=\"https:\/\/bun.sh\/guides\/http\/cluster\" rel=\"noopener noreferrer nofollow\">https:\/\/bun.sh\/guides\/http\/cluster<\/a><\/figcaption><\/div>\n<\/figure>\n<p>\u0412 Linux<a href=\"https:\/\/blog.flipkart.tech\/linux-tcp-so-reuseport-usage-and-implementation-6bfbf642885a\" rel=\"noopener noreferrer nofollow\"> \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043f\u043e\u0440\u0442. <\/a>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <code>nginx_upstream<\/code>, \u043d\u0435\u0442 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u0440\u0430\u0442\u0438\u0442 \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u043c\u0435\u0440\u0442\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 event loop \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d, \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u044c\u043c\u0435\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0440\u0435\u043f\u043b\u0438\u043a\u0430. \u041e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u0432\u0435\u0449\u0435\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 \u043c\u0435\u0434\u0438\u0430 \u0444\u0430\u0439\u043b\u044b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 base64<\/p>\n<figure class=\"full-width\">\n<div><figcaption><a href=\"https:\/\/bun.sh\/guides\/process\/ipc\" rel=\"noopener noreferrer nofollow\">https:\/\/bun.sh\/guides\/process\/ipc<\/a><\/figcaption><\/div>\n<\/figure>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0432 Linux \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u0441\u0435\u0442\u044c, \u0430 \u0444\u0430\u0439\u043b\u044b. \u042d\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0444\u0430\u0439\u043b \u043c\u043e\u0436\u043d\u043e \u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a\u0430\u044f \u0448\u0438\u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/geth.ethereum.org\/\" rel=\"noopener noreferrer nofollow\">GETH <\/a>&#8212; \u043d\u043e\u0434\u0435 \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d\u0430 Ethereum, \u0434\u043b\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f GUI \u0441 \u043a\u043e\u0448\u0435\u043b\u044c\u043a\u043e\u043c<\/p>\n<p><strong>ecosystem.config.js<\/strong><\/p>\n<p>\u041d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0440\u0435\u043f\u043b\u0438\u043a\u0443 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u043f\u043e\u0440\u0442. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0443\u043f\u0430\u0434\u0435\u0442. \u0412\u043d\u0443\u0442\u0440\u0438 \u0432\u0435\u0431 \u0441 \u041f\u0440\u043e\u043f\u0438\u0441\u0430\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0440\u0442\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u043f\u044f\u0442\u0443\u044e, \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u044b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u043f\u043b\u0438\u043a\u0438<\/p>\n<pre><code class=\"javascript\">const path = require(\"path\"); const os = require(\"os\"); const dotenv = require(\"dotenv\");  const readConfig = () =&gt; dotenv.parse(\".\/.env\");  const getPath = (unixPath) =&gt; {   return path.resolve(unixPath.replace(\"~\", os.homedir())); };  const apps = [   {     name: \"bun-ws-1\",     exec_mode: \"fork\",     instances: \"1\",     autorestart: true,     cron_restart: \"0 0 * * *\",     max_memory_restart: \"1250M\",     script: \".\/packages\/backend\/src\/index.ts\",     interpreter: getPath(\"~\/.bun\/bin\/bun\"),     env: readConfig(),     args: [\"--bootstrap=8081,8082,8083,8084,8085\"],     out_file: \".\/logs\/pm2\/bun-ws-1-out.log\",     error_file: \".\/logs\/pm2\/bun-ws-1-error.log\",     log_date_format: \"YYYY-MM-DD HH:mm:ss\",     merge_logs: true,   }, ];  module.exports = {   apps, }; <\/code><\/pre>\n<p><strong>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong><\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u043c\u0435\u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f bootstrapService. \u0422\u0430\u043a \u043a\u0430\u043a \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 websocket \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u044d\u0442\u043e \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0439\u0441\u044f HTTP \u0437\u0430\u043f\u0440\u043e\u0441, \u043e\u043d \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u043e\u0434\u043d\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0435 \u0438 \u043d\u0435 \u0448\u0430\u0440\u0438\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. <\/p>\n<pre><code class=\"typescript\">import { errorData, getErrorMessage } from \"functools-kit\"; import type { NotifyRequest } from \"..\/model\/NotifyRequest.model\"; import { app } from \"..\/config\/app\"; import { ioc } from \"..\/lib\";  const { port } = ioc.bootstrapService.getArgs();  app.post(\"\/api\/v1\/notify\", async (ctx) =&gt; {   const request = await ctx.req.json&lt;NotifyRequest&gt;();   ioc.bootstrapService.broadcast(\"broadcast\", {     clientId: request.clientId,     requestId: request.requestId,     port,   }); });<\/code><\/pre>\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 <code>broadcast<\/code>. \u041f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u0440\u0435\u043f\u043b\u0438\u043a\u0435 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 <code>listen<\/code><\/p>\n<pre><code class=\"typescript\">  ioc.bootstrapService.listen(({ topic, data }) =&gt; {     if (server.subscriberCount(topic)) {       console.log(\"Publishing\", { topic, data });       server.publish(topic, JSON.stringify(data));     }   });<\/code><\/pre>\n<p><strong>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0439 WebSocket<\/strong><\/p>\n<p>\u0423 bun \u0435\u0441\u0442\u044c pubsub \u0432\u0435\u0449\u0430\u043d\u0438\u0435 \u0434\u043b\u044f ws \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439. \u042d\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440<\/p>\n<figure class=\"full-width\">\n<div><figcaption><a href=\"https:\/\/bun.sh\/guides\/websocket\/pubsub\" rel=\"noopener noreferrer nofollow\">https:\/\/bun.sh\/guides\/websocket\/pubsub<\/a><\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0440\u0435\u043f\u043b\u0438\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0430 ws \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0438<\/p>\n<pre><code class=\"typescript\">app.get(   \"\/api\/v1\/listen\",   upgradeWebSocket((c) =&gt; {     return {       onOpen: (_, ws) =&gt; {         const bunWs = ws.raw!;         bunWs.subscribe(\"broadcast\");         ws.send(JSON.stringify({ port }))       },       onClose: (_, ws) =&gt; {         const bunWs = ws.raw!;         bunWs.unsubscribe(\"broadcast\");       },     };   }) ); <\/code><\/pre>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u044d\u0442\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0435\u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043a\u043e\u0433\u0434\u0430 \u0448\u0438\u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430. \u0414\u043b\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0449\u0435 \u0432\u0435\u0441\u0442\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0443 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0437\u0430\u043f\u0440\u043e\u0441-\u043e\u0442\u0432\u0435\u0442.<\/p>\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\/903222\/\"> https:\/\/habr.com\/ru\/articles\/903222\/<\/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-456955","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/456955","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=456955"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/456955\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=456955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=456955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=456955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}