Newer
Older
Alessandro Cerioni
committed
server_name _;
Alessandro Cerioni
committed
set $matomo_script
"<script type='text/javascript'>
var _paq = _paq || [];
var siteId = <MATOMO_SITE_ID>;
window['siteId'] = siteId;
_paq.push(['enableLinkTracking']);
(function() {
var u='<MATOMO_SERVER_URL>/';
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', siteId]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>";
Alessandro Cerioni
committed
# rule redirecting to fr or en regarding the browser preferences
Alessandro Cerioni
committed
location / {
rewrite_by_lua '
for lang in (ngx.var.http_accept_language .. ","):gmatch("([^,]*),") do
if string.sub(lang, 0, 2) == "en" then
ngx.redirect("/en/")
end
if string.sub(lang, 0, 2) == "fr" then
ngx.redirect("/fr/")
end
end
ngx.redirect("/en/")
';
Alessandro Cerioni
committed
}
# This is needed to allow reloading in the app when not on the base url as our app is an SPA
Alessandro Cerioni
committed
location /en {
try_files $uri$args /en/index.html;
Alessandro Cerioni
committed
sub_filter '</head>' '$matomo_script</head>';
Alessandro Cerioni
committed
location /fr {
try_files $uri$args /fr/index.html;
Alessandro Cerioni
committed
sub_filter '</head>' '$matomo_script</head>';
sub_filter '<html lang="en">' '<html lang="fr">';
# Allow to access the app without the /fr or /en and will by default redirect to /en/{path}
Alessandro Cerioni
committed
#location / {
# try_files $uri$args /en/index.html;
#}