Update on nginx and Piwik
In my previous post I summoned some hackish magic to fix something that I didn’t really understand. That’s usually not good practice. Most experienced developers have a well-tuned b.s. detection system and will return to unnecessarily hackish code almost as a matter of necessity. That was the case here, and what I found was that the error was in my nginx conf file. For whatever reason I had nginx misconfigured and content JavaScript, CSS, and SWF files were being served up by fast-cgi instead of being handled by nginx directly. Here’s a relevant section of my updated conf file:
# Stop Image and Document Hijacking # Also have to handle these file types for piwik before they get processed by PHP below location ~* (\.jpg|\.png|\.css|\.gif|\.jpeg|\.js|\.swf)$ { if ($http_referer ~* ^(http://my.domain.com) ) { expires max; break; } return 444; } location / { root /home/public_html/my.domain.com/public/; index index.php index.html; # this serves static files that exist without running other rewrite tests if (-f $request_filename) { expires max; break; } fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include /usr/local/nginx/conf/fastcgi_params; fastcgi_param SCRIPT_FILENAME /home/public_html/my.domain.com/public/$fastcgi_script_name; include fastcgi_params; }
Everything got better after that. Not sure who I thought I was fooling with my first solution, but it didn’t even work on myself.
2 comments
Maybe
http://wiki.nginx.org/NginxHttpRefererModule#valid_referers
Thanks for the tip.