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.

3
  • Turn on debugging and logging with error_log /var/log/nginx/error.log debug; and log_subrequest on; to see what does it say.
    – quanta
    Oct 17, 2011 at 10:58
  • There is nothing in the error log .
    – digitalPBK
    Oct 17, 2011 at 11:15
  • Nginx needs to be built with debug turned on in order to log debug level events.
    – ojrask
    Dec 19, 2014 at 11:21

2 Answers 2

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.

4
  • 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, 2011 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, 2011 at 5: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, 2011 at 11:13
  • Can you let me know the nginx version? and if possible share relevant parts of the conf
    – digitalPBK
    Oct 24, 2011 at 8: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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .