This shows you the differences between two versions of the page.
— | blog:2022:06:04:2022-06-04_-_caching_proxy_in_nginx [2022/06/04 20:29] (current) – created basz | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== 2022-06-04 - caching proxy in nginx ====== | ||
+ | in one of the previous projects we had an issue on CI. TL;DR -- we needed a cache, to minimize network traffic between different locations. case was simple: there were build artifacts, stored on site A and these were needed '' | ||
+ | |||
+ | after some digging it turned out that [[wp> | ||
+ | |||
+ | < | ||
+ | user www-data; | ||
+ | worker_processes auto; | ||
+ | pid / | ||
+ | include / | ||
+ | |||
+ | events { | ||
+ | worker_connections 1024; | ||
+ | # multi_accept on; | ||
+ | } | ||
+ | |||
+ | |||
+ | http { | ||
+ | access_log / | ||
+ | error_log / | ||
+ | |||
+ | client_max_body_size 2048M; | ||
+ | gzip off; | ||
+ | |||
+ | server { | ||
+ | listen 80 default_server; | ||
+ | listen [::]:80 default_server; | ||
+ | proxy_cookie_path / "/; HttpOnly; Secure"; | ||
+ | server_name _; | ||
+ | return 301 https:// | ||
+ | } | ||
+ | |||
+ | proxy_cache_path | ||
+ | server { | ||
+ | listen 443 ssl default_server; | ||
+ | listen [::]:443 ssl default_server; | ||
+ | proxy_cookie_path / "/; HttpOnly; Secure"; | ||
+ | server_name _; | ||
+ | |||
+ | ssl_protocols TLSv1.2 TLSv1.3; | ||
+ | ssl_certificate | ||
+ | ssl_certificate_key / | ||
+ | |||
+ | location / { | ||
+ | proxy_pass | ||
+ | proxy_cache_methods | ||
+ | proxy_set_header | ||
+ | proxy_buffering | ||
+ | proxy_cache | ||
+ | proxy_cache_valid | ||
+ | proxy_cache_use_stale | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | this coveres: caching, cache lifetime management, HTTPS and HTTP to HTTPS redirection. all in 49 lines of config, including formatting. :D once deployed, there were no further issues observed. XXI century magic! ;) |