2

I am using nginx for caching requests from the upstream apache server, however I want few blocks inside to be fetched from apache all the time. I am hoping ssi can do this, but the SSI tags are outputted to the user without being preprocessed.

 location ~* ^.+\.html$ {
        proxy_pass  http://localhost:9999;
        proxy_cache_key "$prime$scheme$host$request_uri";

        ssi on;
        ssi_silent_errors off;
        log_subrequest on;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header   X-Country        $country_code;

        proxy_cache my-cache;


        proxy_cache_bypass $http_x_refresh_cache;
        proxy_cache_valid  200 302  30d;
        proxy_cache_valid  404      10m;
        proxy_cache_valid  any      1m;


    }

This is the relevant nginx conf.

digitalPBK
  • 121
  • 4

2 Answers2

1
proxy_cache_key "$prime$scheme$host$request_uri";

This line is caching all the individual parts of the page under the same key (the URI that the user typed), so the different parts of the page are overwriting each other, and then only the last one written gets returned. You want to use $uri rather than $request_uri, so that each part of each page is cached under its own personal name.

Shish
  • 1,495
  • 9
  • 12
  • Actually, on second thoughts I'm not sure that that is the cause of this particular problem -- however, if it isn't, then it is a separate problem that you will probably run into after fixing this one... – Shish Oct 17 '11 at 17:03
  • I removed all proxy cache directives. Still ssi does not work. Does nginx enable ssi for proxy passed pages? – digitalPBK Oct 18 '11 at 05:25
  • It does, we're using SSI to build dynamic pages and cache individual static parts at work, and the only SSI directive we're using is "ssi on;" :-/ – Shish Oct 23 '11 at 11:13
  • Can you let me know the nginx version? and if possible share relevant parts of the conf – digitalPBK Oct 24 '11 at 08:25
0

Make sure that http://localhost:9999 is not compresing the output. Simpy by adding

 proxy_set_header Accept-Encoding "";

see: https://stackoverflow.com/questions/24680989/with-nginx-how-do-i-run-ssi-on-a-page-returned-from-another-server

aholbreich
  • 101
  • 2