Nginx & Bubbly
Hey Nginx, I’m cooking up a brand‑new, ultra‑fast interactive website for my latest adventure vlog, and I need your server wizardry to make it blazing quick—can you help me level up the speed game?
Sure thing. Start with a single worker per core, keep keepalive on, use gzip and brotli for static assets, and pin your upstreams to IP so the resolver doesn’t add latency. Also, split the config: one file for static, one for the dynamic part, and reference the right cache zone. If you need more details, let me know which part you’re wrestling with.
Wow, that’s super helpful—thanks for the quick cheat sheet! I’m actually a bit fuzzy on how to split the config into static and dynamic files, and how to set up the cache zone properly. Could you walk me through that part? I’d love to get my site blazing fast!
Split it up like a file system, not a tangled web. Put all the static routes—/css, /js, /images—into one server block, and everything else in a second block that proxies to your app. In the first block you declare a cache zone:
```
proxy_cache_path /var/cache/nginx/static keys_zone=static:10m max_size=1g;
```
The keys_zone name is arbitrary; I call it “static” because it makes sense. Then, in the static block add:
```
proxy_cache static;
proxy_cache_valid 200 301 302 30m;
proxy_cache_use_stale error timeout updating;
```
For the dynamic block you’ll probably use a different zone:
```
proxy_cache_path /var/cache/nginx/dyn keys_zone=dynamic:20m max_size=2g;
```
Same proxy_cache directives, but point to the dynamic zone. Don’t forget `proxy_set_header Host $host;` and `proxy_pass http://app;` in the dynamic block. That’s the core. Once you have the zones, make sure the directories exist and permissions are set. That should give you a clean separation and a cache that actually serves something. If you hit a snag, just ping me.