location regex

olat nginx-forum at forum.nginx.org
Tue Nov 1 22:49:04 UTC 2016


Looks like there is a bug in the forum. 2 the same topics and the response
ended up in the wrong thread, mixed up ;-)

Anyway, Thanks Igor for a quick response. Could you explain more why regex
is not a good idea? I am asking about regex in the context of caching some
of the requests on front-end proxy to speed up django app loading dynamic
content where session is involved. Does it mean each of the filtered out
requests we would like to cache, should duplicate the same location block? 


server {
   ...

    proxy_set_header Host myhost;
    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;

    # catch only /appfoo* and /appbar*
    location ~ /app(foo|bar)* {
        proxy_pass http://ip;
        proxy_redirect http://ip $scheme://$server_name;

        proxy_cache            $cache_zone_name;
        proxy_cache_key        "$request_uri";
        ...
        proxy_cache_methods    GET HEAD;
        proxy_cache_bypass     $cache_refresh;
        proxy_no_cache         $skip_cache;

        proxy_ignore_headers   "Set-Cookie" "Vary" "Expires";
        proxy_hide_header Set-Cookie;
    }
    # everything else goes here
    location / {
        proxy_pass http://ip;
        proxy_redirect http://ip $scheme://$server_name;
    }

Thanks in advance for help.

O.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,17473,270697#msg-270697



More information about the nginx mailing list