Cache POST requests

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Cache POST requests

Lahiru Prasad
Hi,
    What is the best way to cache POST requests in Nginx. I'm familiar with using redis module to cache GET requests. But is it possible to use the same for POST ?

Search showed that Nginx POST caching possible via disk cache. I'm thinking whether it would be a good idea to use a RAM disk for this.

Regards,
Lahiru Prasad.

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Cache POST requests

nginx mailing list
Hi,

On 2018-09-25 20:32, Lahiru Prasad wrote:
>     What is the best way to cache POST requests in Nginx. I'm familiar
> with using redis module to cache GET requests. But is it possible to
> use the same for POST ?
It's possible to cache POST-requests, but it's generally not something
you want to do. POST-data is in most cases more sensitive than GET-data,
for, for instance, login-details. Use it with care.
It needs to be specifically enabled.

> Search showed that Nginx POST caching possible via disk cache. I'm
> thinking whether it would be a good idea to use a RAM disk for this.
This is certainly possible. I'm doing precisely this for my
DNS-over-HTTPS setup. It required me, however, to be a bit inventful to
get a populated $request_body to use as part of the cache key, but this
was the result (open to suggestions as to avoid "mirror" here, but
haven't really found any other proper solution):

http {
    proxy_cache_path        /dev/shm/dns
                            levels=1:2
                            keys_zone=dns:5m
                            max_size=20m
                            inactive=1d
                            use_temp_path=off; # leave this to off for
performance reasons!

    server {
        ...
                # DNS over HTTPS
                location = /dns-query {
            expires off;
                        mirror =; # Don't touch, this is necessary to
populate $request_body!

                        ## Begin - FastCGI caching.
                        proxy_cache             dns;
                        proxy_cache_methods     GET HEAD POST;
                        proxy_cache_key        
"$scheme$request_method$host$request_uri$request_body";
                        proxy_cache_valid       200 1m; # this is the
only valid response of the proxy.

                        proxy_ignore_headers    "Cache-Control"
                                                "Expires"
                                                "Set-Cookie";

                        proxy_cache_use_stale   error
                                                timeout
                                                updating
                                                http_429
                                                http_500
                                                http_503;

                        proxy_cache_background_update   on;
                        ## End - FastCGI caching

                        proxy_pass http://[::1]:8553;
                }

    }
}

Kind regards,

Daniël Mostertman

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

smime.p7s (5K) Download Attachment