Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy Cache not working on heroku #58

Open
sub2u opened this issue Aug 26, 2015 · 2 comments
Open

Proxy Cache not working on heroku #58

sub2u opened this issue Aug 26, 2015 · 2 comments

Comments

@sub2u
Copy link

sub2u commented Aug 26, 2015

I have a config which works on my local machine with proxy reverse cache. It bypass the hitting the box every time.

I used nginx-build pack with proxy cache but on nginx every time it hit the box i can observe heroku[router] on logs

providing the config for reference in bottom.

Sample config

daemon off; # Heroku dynos have at least 4 cores.

worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;

events {
use epoll;
accept_mutex on;
worker_connections 1024;
}

http {
gzip on;
gzip_comp_level 2;
gzip_min_length 512;

server_tokens off;

log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
access_log logs/nginx/access.log l2met;
error_log logs/nginx/error.log;

include mime.types;
default_type application/octet-stream;
sendfile on;

#Must read the body in 5 seconds.
client_body_timeout 5;

upstream app_server {
    server unix:/tmp/nginx.socket fail_timeout=0;
}

proxy_cache_path  /tmp/nginx  levels=1:2    keys_zone=STATIC:10m
                                 inactive=24h  max_size=1g;

server {
    listen <%= ENV["PORT"] %>;
    server_name _;
    keepalive_timeout 5;

    location  / {
        proxy_pass             http://app_server;
    }


    location  ~* ^/(.*)/(.*)/(.*).(jpe?g|png|[tg]iff?|svg) {
        proxy_pass             http://app_server;
        add_header Cache-Control public;
        add_header X-Cache-Status $upstream_cache_status
        proxy_set_header       Host $host;
        proxy_cache            STATIC;
        proxy_cache_valid      200  1d;
        proxy_cache_use_stale  error timeout invalid_header updating
                               http_500 http_502 http_503 http_504;
    }
}

}

@GertSallaerts
Copy link

Your NGINX server will run on every dyno and the Heroku Router is a layer in front of these dyno's, so when your app receives a request, it will always pass through the Heroku Router before hitting NGINX. This is why you see the router logs.

You can check the response header (X-Cache-Status from your example) to see if the NGINX cache is working.

@stran12
Copy link

stran12 commented Feb 12, 2017

Did anyone figure this out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants