web-server: add compression
In my mind, this could be solved via:
- adding a reverse proxy to the container (NGINX, Caddy) and enabling compression
- adding a compression middleware to axum
I assume axum is fine being exposed to the internet and doesn't need to be behind a reverse proxy (?).
Also in our current NGINX config: IP blocks, while it's unclear if we would handle this in AWS / CloudFront, or if we would have to handle this in our webserver (see https://github.com/rust-lang/simpleinfra/issues/353)
We'd also need to have TLS in the container if it is exposed to the internet, but I assume we're still having it only accessed by cloudfront over a private network so that shouldn't be necessary.
Yep, that's my thinking, our webservers would only be accessed through CloudFront, so we don't have to do TLS
And especially between the US & CF POPs in europe / asia compression definitely makes a difference
Hi! I'd like to take a stab at solving this by adding a compression layer to the middleware stack in the web server. If that's ok, I have a couple of questions:
- Can this compression middleware be applied to all routes served by the web server, or is there a reason to target specific routes?
- I'm planning on using
tower_http::compression, which supportsbrotli,deflate,gziporzstd. I don't know enough about this field to make a really educated decision on which one to choose. Does anyone have advice? I know thatgzipis widely supported/used, and performs reasonably well. Should we start there?
Very good question!
- yes, all routes is fine
- yep, that's the middleware I also had in mind.
gzipis fine, this will only compress between the webservers & the CDN. And adding more would probably add more dependencies to the project. You can just use thetower_httpdefault
When using tower-http compression, see the comments / change here : https://github.com/rust-lang/crates.io/pull/7330/
Having read a little more about it I would say we should enable brotli, when easily possible.
We first would add this to our webserver, and then probably need to change CloudFront config to support this, or use it between the browser and the CDN POP.