1. server {
  2. listen 8001;
  3. server_name localhost;
  4. access_log /var/log/nginx/piwik.access.log;
  5. error_log /var/log/nginx/piwik.error.log;
  6. # Disable all methods besides HEAD, GET and POST.
  7. if ($request_method !~ ^(GET|HEAD|POST)$ ) {return 444;}
  8. root /home/tohuw/www/piwik/;
  9. include global/indexes.conf;
  10. # Disallow any usage of piwik assets if referer is non valid.
  11. location ~* ^.+\.(?:jpg|png|css|gif|jpeg|js|swf)$ {
  12. # Defining the valid referers.
  13. valid_referers none blocked *.mysite.com othersite.com;
  14. if ($invalid_referer) {return 444;}
  15. expires max;
  16. break;
  17. }
  18. # Support for favicon. Return a 204 (No Content) if the favicon
  19. # doesn't exist.
  20. location = /favicon.ico {try_files /favicon.ico =204;}
  21. # Try all locations and relay to index.php as a fallback.
  22. location / {try_files $uri /index.php;}
  23. # Relay all index.php requests to fastcgi.
  24. location ~* ^/(?:index|piwik)\.php$ {
  25. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  26. fastcgi_pass unix:/var/run/php5-fpm.sock;
  27. fastcgi_index index.php;
  28. include fastcgi_params;
  29. try_files $uri =404;
  30. }
  31. # Any other attempt to access PHP files returns a 404.
  32. location ~* ^.+\.php$ {return 404;}
  33. # Return a 404 for all text files.
  34. location ~* ^/(?:README|LICENSE[^.]*|LEGALNOTICE)(?:\.txt)*$ {return 404;}
  35. # # The 404 is signaled through a static page.
  36. # error_page 404 /404.html;
  37. # ## All server error pages go to 50x.html at the document root.
  38. # error_page 500 502 503 504 /50x.html;
  39. # location = /50x.html {
  40. # root /var/www/nginx-default;
  41. # }
  42. }