John F
John F

Reputation: 735

NGINX: Is it possible to disable cache and redirect request to another server for certain header?

We are trying to disable nginx cache for specific header, in "Modify Header" chrome extension (you may use other) I added header like: "X-Dev = 1" and want to catch this header in nginx.conf to disable nginx cache and proxy request to developer server, is it possible to do?

Upvotes: 2

Views: 1758

Answers (1)

John F
John F

Reputation: 735

Looks like I found solution, as Alexey recommended I added $http_x_dev header to proxy_cache_bypass directive and point requests to other server by condition:

proxy_cache_bypass $http_x_dev;

location / {
    if ( $http_x_dev = 1 ) {
        proxy_pass http://DEV_SERVER_IP:80;
        break;
    }

    ...
}

Upvotes: 1

Related Questions