How to Deal with Redirect Errors When Using a Cache Server ②

3 min

language: ja bn en es hi pt ru zh-cn zh-tw

error.png

Hello, this is Munou.

I thought it was fixed in the previous article, but it wasn't fixed at all.

And when I thought about it carefully, it felt strange, so I changed the syntax again.

server {
    listen 443 ssl;
    server_name xxx.xxxx;
    
    location / {     
                if ($uri ~* "\.(jpg|jpeg|png|webp|gif|mp4|css|js|ico|woff2)$") {
                    set $do_not_cache 0;
                }

                proxy_no_cache          $do_not_cache;
                proxy_cache_bypass      $do_not_cache;

                proxy_cache             zone1;
                proxy_cache_key         $scheme$proxy_host$uri$is_args$args;
                proxy_cache_valid       200 201 6h;
                proxy_cache_valid       302 3h;
                proxy_cache_valid       301 1d;
                proxy_cache_valid       404 5m;
                proxy_cache_lock        on;
                
                proxy_pass http://192.168.10.101/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;   
    }
    ssl_certificate xxxx.pem;  
    ssl_certificate_key xxxx.pem; 
}

How to deal with redirect errors when using a cache server

Compared to the article above, the syntax is much shorter, but I removed unnecessary parts to make it easier to read.
Previously, the red text part was placed immediately after `location`, but in that case, I thought that the reverse proxy would operate before deciding whether to cache or not, and the situation where the SSL-certified page itself was cached hadn't changed, so I moved it to the end.

I can't quite grasp when this redirect error occurs, so I'll observe it with this setup.

That's all for now.

Related Posts