# Nginx does not Cache Google Adsense and Some other widgets - help

**URL:** <https://www.ruby-forum.com/t/nginx-does-not-cache-google-adsense-and-some-other-widgets-help/212506>\
**Category:** NGINX\
**Created:** [October 5, 2011, 2:26am UTC](https://www.ruby-forum.com/t/nginx-does-not-cache-google-adsense-and-some-other-widgets-help/212506 "2011-10-05T02:26:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [October 5, 2011, 2:26am UTC](https://www.ruby-forum.com/t/nginx-does-not-cache-google-adsense-and-some-other-widgets-help/212506/1 "2011-10-05T02:26:49Z")

</div>

Nginx 1.0.x

I have set up my cache like this:

proxy\_cache\_key $host$uri$is\_args$args;  
proxy\_cache\_methods POST;  
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;

The URLs that are not being cached are of this form:

URI?id=parameter&h=parameter or URI?  
id=parameter&h=parameter&w=parameter

Any ideas how I can configure the cache key so that uris with those  
parameters get cached too?

Thanks,

Alex

---

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [October 5, 2011, 1:05pm UTC](https://www.ruby-forum.com/t/nginx-does-not-cache-google-adsense-and-some-other-widgets-help/212506/2 "2011-10-05T13:05:58Z")

</div>

> Nginx does not Cache Google Adsense

To understand this correctly - theese requests aren’t coming directly  
from  
google servers (otherways unleast you put nginx as a proxy above google  
it  
won’t be able to cache anything)?

> The URLs that are not being cached are of this form:  
> URI?id=parameter&h=parameter or URI?  
> id=parameter&h=parameter&w=parameter

Can you show what the full request headers look like (for example with:  
wget -S url)?

You have: proxy\_cache\_valid 200 1d;

which means that only 200 responses are cached and not for example 301  
or  
302 .. (you can try to remove ‘200’ and see if the response is cached  
then).

rr

---

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [October 5, 2011, 4:15pm UTC](https://www.ruby-forum.com/t/nginx-does-not-cache-google-adsense-and-some-other-widgets-help/212506/3 "2011-10-05T16:15:05Z")

</div>

Dear RR:

Thank you for your insights. In regards to the wget -S url, this is  
what I get:

–2011-10-05 18:09:32–  
[http://myWebDomain.com/contentAsset/resize-image/7e061df4-0fc3-481f-b75d-7ce3ff2e8cac/?w=175](http://myWebDomain.com/contentAsset/resize-image/7e061df4-0fc3-481f-b75d-7ce3ff2e8cac/?w=175)  
Resolving [myWebDomain.com](http://myWebDomain.com)… IP ADDRESS  
Connecting to myWebDomain.com|IP ADDRESS|:80… connected.  
HTTP request sent, awaiting response…  
HTTP/1.1 404 Not Found  
Server: nginx  
Date: Wed, 05 Oct 2011 14:09:32 GMT  
Content-Type: text/html;charset=UTF-8  
Connection: close  
Vary: Accept-Encoding  
Set-Cookie: JSESSIONID=5AB2FF5CF72E237DCEC48FAE19AE09F4; Path=/  
Set-Cookie: SHARED\_SESSION\_ID=GZ3W4CP2F07E; Expires=Thu, 06-  
Oct-2011 14:09:32 GMT; Path=/  
2011-10-05 18:09:32 ERROR 404: Not Found.

Note the address “contentAsset/resize-image/7e061df4-0fc3-481f-  
b75d-7ce3ff2e8cac/?w=175” is inside an image tag. If I disable the  
cache, it works fine.

I tried to set proxy\_cache\_valid any 1d; and proxy\_cache\_valid 200  
404 1d; Then, clear the cache, and restarted nginx and it still stays  
the same.

---

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [October 5, 2011, 7:15pm UTC](https://www.ruby-forum.com/t/nginx-does-not-cache-google-adsense-and-some-other-widgets-help/212506/4 "2011-10-05T19:15:27Z")

</div>

> –2011-10-05 18:09:32–  
> [http://myWebDomain.com/contentAsset/resize-image/7e061df4-0fc3-481f-b75d-7ce3ff2e8cac/?w=175](http://myWebDomain.com/contentAsset/resize-image/7e061df4-0fc3-481f-b75d-7ce3ff2e8cac/?w=175)  
> HTTP/1.1 404 Not Found  
> Server: nginx  
> Content-Type: text/html;charset=UTF-8  
> Vary: Accept-Encoding  
> Set-Cookie: JSESSIONID=5AB2FF5CF72E237DCEC48FAE19AE09F4; Path=/  
> Set-Cookie: SHARED\_SESSION\_ID=GZ3W4CP2F07E; Expires=Thu, 06- Oct-2011 14:09:32  
> GMT; Path=/  
> 2011-10-05 18:09:32 ERROR 404: Not Found.

Without the full nginx config (and the application specifics (looks like  
some java app/tomcat?) you are trying to proxy/cache) it is  
hard to understand what is going wrong.

While you are getting a 404 response nginx cache should not influence if  
the object exists or not on the backend (unless the backend  
is using something dynamic (like active sessionid/cookie) for the  
embedded object/image serving).

Is it possible to get the request/headers for the object directly from  
the backend (without nginx)?

Also can you show the proxy\_cache\_path for STATIC zone and/or check if  
nginx actually creates any cache file there?

In the end you could also enable/check the nginx error\_log in more  
verbose mode.

But if it was intended to cache the 404 responses it is clear why nginx  
didn’t it before since proxy\_cache\_valid didn’t have 404  
specified.

rr

---

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [October 6, 2011, 4:10pm UTC](https://www.ruby-forum.com/t/nginx-does-not-cache-google-adsense-and-some-other-widgets-help/212506/5 "2011-10-06T16:10:25Z")

</div>

Dear RR:

The application uses tomcat. It is a java 2EE cms called dotCMS. Here  
are the headers without NGINX:

HTTP request sent, awaiting response…  
HTTP/1.1 200 OK  
Date: Wed, 05 Oct 2011 17:53:05 GMT  
Server: Apache/2.0.63 (Unix) mod\_ssl/2.0.63 OpenSSL/0.9.8e-fips-  
rhel5 mod\_bwlimited/1.4 mod\_jk/1.2.31  
Set-Cookie: JSESSIONID=0B54F628C20BD330D58B871703A27128; Path=/  
Expires: Thu, 04 Oct 2012 17:53:05 +0000  
Cache-Control: public, max-age=31536000  
Last-Modified: Wed, 05 Oct 2011 13:38:53 GMT  
ETag: dot:null:1317821933000:64442  
Content-Length: 64442  
Keep-Alive: timeout=15, max=100  
Connection: Keep-Alive  
Content-Type: image/png  
Length: 64442 (63K) [image/png]

My config file is here [http://pastebin.com/Ubi0pjyq](http://pastebin.com/Ubi0pjyq)

Yes, the CACHE is created. This is what I see in the cache directory.

0 1 2 3 4 5 6 7 8 9 a b c d e f tmp

I appreciate your help!

Alex
