Skip to content
Snippets Groups Projects
nginx.conf.template 1.31 KiB
server {
    # staging server is listening on the port 8080
    listen 8080;
    server_name _;
    root /usr/share/nginx/html/;

    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>";

    # rule serving the fr build
    location / {
        try_files $uri$args /index.html;
        sub_filter '</head>' '$matomo_script</head>'; 
        sub_filter '<html lang="en">' '<html lang="fr">'; 
    }

    # Rule serving the en build
    location /en {
        try_files $uri$args /en/index.html;
        sub_filter '</head>' '$matomo_script</head>'; 
    }

    # redirecting the /fr url to the new location of the fr build
    location ~ ^/fr(.*)$ {
        return 301 $scheme://$http_host$1$is_args$args;      
    }

    #location /robots.txt {
    #    rewrite ^ /fr/robots.txt;
    #}

}