Skip to content
Snippets Groups Projects
nginx.conf.template 1.72 KiB
Newer Older
  • Learn to ignore specific revisions
  • FORESTIER Fabien's avatar
    FORESTIER Fabien committed
        # staging server is listening on the port 8080
    
    FORESTIER Fabien's avatar
    FORESTIER Fabien committed
        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 redirecting to fr or en regarding the browser preferences
    
    FORESTIER Fabien's avatar
    FORESTIER Fabien committed
            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/")
            ';
    
    FORESTIER Fabien's avatar
    FORESTIER Fabien committed
        # This is needed to allow reloading in the app when not on the base url as our app is an SPA
    
        location /en {
            try_files $uri$args /en/index.html;
    
        location /fr {
            try_files $uri$args /fr/index.html;
    
            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}