I have FreeBSD server with nginx as reverse proxy.

When I test it with ab util, I see some strange things, such as:

  1. Internal pages aren't cached.
  2. Main page is cached, but sometimes the non-cached version is returned.

I don't know where I've made a mistake. Please, help.

Here's part of the config:

worker_processes  4;

events {
    worker_connections  4096;

http {

    proxy_connect_timeout      90;
    proxy_send_timeout         90;
    proxy_read_timeout         200;

    proxy_buffer_size          4m;
    proxy_buffers              24 1m;
    proxy_busy_buffers_size    8m;
    proxy_temp_file_write_size 4m;

    proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=all:512m;

    keepalive_timeout  65;
    reset_timedout_connection on;
    aio sendfile;
    directio 1M;
    output_buffers 64 256k;

    server {
        listen < hidden >;
        server_name < hidden >;

        error_page 412 = @fallback;

        proxy_cache_key "$host$request_uri";
        proxy_cache_valid 404 5m;
        proxy_cache_valid 500 501 502 503 504 1m;
        proxy_cache_valid any 10m;
        proxy_cache_use_stale http_502 http_503 http_504;
        proxy_cache_bypass $cookie_logined;
        proxy_no_cache $cookie_logined;

        location / {
            if ($cookie_logined) { return 412; }
            proxy_cache all;

            proxy_pass < hidden >;
            proxy_redirect < hidden > /;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;



1 Answer 1


I think you do not fully understand how the cache. Key parameters of the cache, such as:

  • proxy_cache_key
  • proxy_cache_lock
  • proxy_cache_lock_timeout
  • proxy_cache_methods
  • proxy_cache_bypass
  • proxy_cache_valid

I think that the default values ​​give this effect. Read this part of the documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.