title: Why doesn't my Nginx configuration cache the response?
body: <p>I have the following Nginx configuration, which we can see from the output of <code>nginx -T</code> is syntactically correct. I <strong>bolded</strong> some relevant parts of the output below:</p>
  <pre>
  $ sudo nginx -T
  nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  nginx: configuration file /etc/nginx/nginx.conf test is successful
  # configuration file /etc/nginx/nginx.conf:
  events {}
  
  http {
      proxy_cache_path <b>/tmp/cache</b> keys_zone=one:10m levels=1:2 inactive=2M max_size=100g;
  
      access_log /var/log/nginx/access.log;
      error_log /var/log/nginx/error.log;
  
      # Static file server
      server {
          listen 127.0.0.1:8080;
  
          root <b>/opt/nginx-test-data</b>;
  
          location / {
          }
      }
  
      # Reverse proxy that talks to server defined above
      server {
          listen 127.0.0.1:<b>8081</b>;
          proxy_cache_min_uses 1;
  
          location / {
              proxy_pass http://127.0.0.1:8080;
              proxy_cache one;
          }
      }
  }
  </pre>
  <p>I know in normal practice that the server and proxy server are on different hosts. At the moment I am just trying to learn how to configure an Nginx proxy server with content caching, since Nginx is new to me.</p>
  <p>I have the following 2MB file of random bytes:</p>
  <pre><code>$ ls -lh /opt/nginx-test-data/random.bin 
  -rw-rw-r-- 1 shane shane 2.0M Jun 21 11:39 /opt/nginx-test-data/random.bin
  </code></pre>
  <p>When I curl the reverse proxy server, I get a 200 response:</p>
  <pre>
  $ curl --no-progress-meter -D - http://localhost:<b>8081</b>/random.bin --output local-random.bin
  HTTP/1.1 200 OK
  Server: nginx/1.18.0 (Ubuntu)
  Date: Mon, 21 Jun 2021 15:50:07 GMT
  Content-Type: text/plain
  Content-Length: 2000000
  Connection: keep-alive
  Last-Modified: Mon, 21 Jun 2021 15:39:54 GMT
  ETag: "60d0b2ca-1e8480"
  Accept-Ranges: bytes
  </pre>
  <p>However, my cache directory is empty:</p>
  <pre><code>$ sudo ls -a /tmp/cache/
  .  ..
  </code></pre>
  <p>I checked both <code>/var/log/nginx/access.log</code> and <code>/var/log/nginx/error.log</code>, and there were no errors logged.</p>
  <p>What have I done wrong so that there are no entries in my cache directory after making a request to the reverse proxy server?</p>