Created
February 13, 2014 13:35
-
-
Save perusio/8975110 to your computer and use it in GitHub Desktop.
How to run Piwik in a subdirectory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: nginx; mode: flyspell-prog; mode: autopair; ispell-local-dictionary: "american" -*- | |
## Try all locations and relay to index.php as a fallback. | |
location /piwik/ { | |
## Disallow any usage of piwik assets if referer is non valid. | |
location ~* ^.+\.(?:css|gif|jpe?g|js|png|swf)$ { | |
## Defining the valid referers. | |
valid_referers none blocked *.mysite.com othersite.com; | |
if ($invalid_referer) { | |
return 444; | |
} | |
expires max; | |
## No need to bleed constant updates. Send the all shebang in one | |
## fell swoop. | |
tcp_nodelay off; | |
## Set the OS file cache. | |
open_file_cache max=500 inactive=120s; | |
open_file_cache_valid 45s; | |
open_file_cache_min_uses 2; | |
open_file_cache_errors off; | |
} | |
## Redirect to the root if attempting to access a txt file. | |
location ~* (?:DESIGN|(?:gpl|README|LICENSE)[^.]*|LEGALNOTICE)(?:\.txt)*$ { | |
return 404; | |
} | |
## Disallow access to several helper files. | |
location ~* \.(?:bat|html?|git|ini|sh|svn[^.]*|txt|tpl|xml)$ { | |
return 404; | |
} | |
try_files $uri /piwik/index.php?$query_string; | |
} | |
## Support for favicon. Return a 1x1 transparent GIF it it doesn't | |
## exist. doesn't exist. | |
location = /piwik/favicon.ico { | |
try_files /piwik/favicon.ico @empty; | |
} | |
location @empty { | |
empty_gif; | |
} | |
## Relay all index.php requests to fastcgi. | |
location = /piwik/index.php { | |
fastcgi_pass phpcgi; | |
## FastCGI cache. | |
## cache ui for 5m (set the same interval of your crontab) | |
include apps/piwik/fcgi_piwik_cache.conf; | |
## To use Apache for serving PHP uncomment the line bellow and | |
## comment out the above. | |
#proxy_pass http://phpapache; | |
### Use the proxy cache if proxying to Apache. | |
include apps/piwik/proxy_piwik_cache.conf; | |
} | |
## Relay all piwik.php requests to fastcgi. | |
location = /piwik/piwik.php { | |
fastcgi_pass phpcgi; | |
include apps/piwik/fcgi_piwik_long_cache.conf; | |
## To use Apache for serving PHP uncomment the line bellow and | |
## comment out the above. | |
#proxy_pass http://phpapache; | |
## Proxy cache. | |
#include apps/piwik/proxy_piwik_long_cache.conf; | |
} | |
## Any other attempt to access PHP files returns a 404. | |
location ~* ^.+\.php$ { | |
return 404; | |
} | |
## No crawling of this site for bots that obey robots.txt. | |
location = /piwik/robots.txt { | |
return 200 "User-agent: *\nDisallow: /\n"; | |
} | |
## Including the php-fpm status and ping pages config. | |
## Uncomment to enable if you're running php-fpm. | |
#include php_fpm_status_vhost.conf; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!
Do you have any updates to this configuration?
I added some stuff, e.g. blocking access to ./tmp/ and *.md files.
Thanks,
Raoul