caching - How to cache a multipart POST request with NGINX reverse proxy -
we have nginx reverse proxy in front of our web server, , need cache responses based on request body (for detailed explanation of why see this other question).
the problem have though post data same, multipart boundary different every time (the boundaries created web browser).
here's simplified example of request looks (notice browser-generated webkitformboundaryv2blneaih1rggo0w):
post http://my-server/some-path http/1.1 content-length: 383 accept: application/json content-type: multipart/form-data; boundary=---- webkitformboundaryv2blneaih1rggo0w ------webkitformboundaryv2blneaih1rggo0w content-disposition: form-data; name="some-key"; filename="some-pseudo-file.json" content-type: application/json { "values": ["value1", "value2", "value3"] } ------webkitformboundaryv2blneaih1rggo0w--
if it's useful someone, here's simplified example of nginx config use
proxy_cache_path /path/to/nginx/cache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off; location /path/to/post/request { proxy_pass http://remote-server; proxy_cache my_cache; 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; proxy_set_header proxy_http_version 1.1; proxy_set_header connection ""; proxy_cache_lock on; proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; proxy_cache_methods post; proxy_cache_key "$scheme$proxy_host$uri$is_args$args|$request_body"; proxy_cache_valid 5m; client_max_body_size 1500k; proxy_hide_header cache-control; }
i have seen lua nginx module looks work, don't see how use parse request data build cache key, still pass original request, or if there's can use "stock" nginx.
thanks!
Comments
Post a Comment