1

Consider this configuration (given /foo doesn't exist):

server {
    set $x 1;

    location = / {
        set $x 0;
        try_files /foo @l;
    }

    location / {
        try_files /foo @l;
    }

    location @l {
        set_header X $x;
        proxy_pass http://localhost:1000/;
    }
}

The response header X is always 1 even when I navigate to /. Why is this and how can I make variables propagate through try_files?

4
  • 1
    What are you actually trying to do? This doesn't seem like the right way to go about...anything. Dec 23, 2014 at 15:34
  • @MichaelHampton I want to enable FastCGI caching on only one specific URL. The only documentation I can find on it uses if ($uri ~ ...) { set $x 0; } but using if is discouraged. All configuration other than whether caching is enabled or not is the same.
    – user42235
    Dec 23, 2014 at 15:35
  • Just use a map then. Dec 23, 2014 at 15:45
  • Sounds like a typical XY problem.
    – AD7six
    Dec 23, 2014 at 15:47

1 Answer 1

2

Based on your comment, the right way to do what you want is by using the fastcgi_no_cache directive combined with a map. An example to show what it looks like :

map $uri $cache {
    default      "1";
    "~^/myuri"   "0";
}

server {

    ...

    location / {
        fastcgi_no_cache $cache;
        fastcgi_pass ...
    }

}

You must log in to answer this question.