4

Does anyone know if there is something strange going on? It seems that my reverse proxy setup, doesn't preserve the correct caching headers from the original virtualhost.

Let me explain...

I am currently using PHP Slim to create an API for my web app. It has its own caching mechanisms, which are setup and running fine. So, when visiting the resource api.example.com/info for example, I have a Last-Modified that is set, which allows it to be cached (it doesn't change very often).

As such, the headers looks something like:

Request URL:http://api.example.com/info Request Method:GET Status Code:304 Not Modified 

Request Headers

Accept:text/html,application/xhtml xml,application/xml;q=0.9,*/*;q=0.8 Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3 Accept-Encoding:gzip,deflate,sdch Accept-Language:en-GB,en-US;q=0.8,en;q=0.6 Cache-Control:max-age=0 Connection:keep-alive Host:api.example.com If-Modified-Since:Mon, 04 Oct 2010 08:00:52 1100 User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5 

Response Headers

Connection:Keep-Alive Date:Tue, 19 Jun 2012 22:34:45 GMT Keep-Alive:timeout=5, max=100 Server:Apache/2.2.21 (Win64) PHP/5.3.8 Vary:Accept-Encoding 

Which shows that the resource returns with a 304 - it's been retrieved from cache. Great!

However, the web app accesses this from a reverse proxy (cross domain issues). When accessing the exact same resource, this time from app.example.com/api/info, it returns with a 200 code. Its also noteably slower to load, which makes me think something isn't working.

This time, the headers are

Request URL:http://app.example.com/api/info Request Method:GET Status Code:200 OK 

Request Headers

Accept:text/html,application/xhtml xml,application/xml;q=0.9,*/*;q=0.8 Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3 Accept-Encoding:gzip,deflate,sdch Accept-Language:en-GB,en-US;q=0.8,en;q=0.6 Cache-Control:max-age=0 Connection:keep-alive Host:app.example.com If-Modified-Since:Mon, 04 Oct 2010 08:00:52 GMT User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5 

Response Headers

Connection:Keep-Alive Content-Encoding:gzip Content-Length:1959 Content-Type:application/json Date:Tue, 19 Jun 2012 22:41:01 GMT Keep-Alive:timeout=5, max=100 Last-Modified:Mon, 04 Oct 2010 08:00:52 GMT Server:Apache/2.2.21 (Win64) PHP/5.3.8 Vary:Accept-Encoding X-API-Version:v1.0 X-Powered-By:PHP/5.3.8, Slim 

Any ideas? Sorry about the mass of header info above - didn't want to leave out any information.

6
  • Which If-Modified-Since header is right? One or the other has a borked time zone. Commented Jun 20, 2012 at 2:02
  • Well picked up! The If-Modified-Since:Mon, 04 Oct 2010 08:00:52 +1100 is the correct one (AEST). Would that make a difference? Commented Jun 20, 2012 at 2:08
  • I would check to make sure the time (and time zone) is correctly set on the reverse proxy machine. Commented Jun 20, 2012 at 2:43
  • It's actually the same physical server, so i'm unsure about how to check that...Besides, they're both the same time, just differing timezone, which has to be fixed, but unfortunately doesn't seem to whats causing the issue... Commented Jun 20, 2012 at 2:45
  • @crawf if the content was modified in the 11 hours between +1100 and GMT, then yes one of those would have a stale cache. The same day an hour in +1100 and +0000 are not the same time. What are the response headers from api.domain.com the first time (before the client has the resource in its cache)? I do notice the If-Modified-Since and Last-Modified headers have the same time. Maybe that is significant? Commented Aug 5, 2012 at 2:19

1 Answer 1

2

When i compare your both example request, I see some more differeneces between them.

e.g. the second response (throught the proxy) includes an

Content-Encoding:gzip 

Line. Maybe your reverse proxy adds an gzip compression filter before delivering the results. What could mean: you primary resource did not change and but the proxy changes the content by compressing it, and so it labels this as "new content".

Another difference is in your request: in your first request you send:

If-Modified-Since:Mon, 04 Oct 2010 08:00:52 +1100 

but in your second request the timeoffset +1100 is missing, so you`re sending another modification time.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.