Nginx with angular 4

I'm having trouble with my configuration, this is how I want mydomain.com to work -> redirect to correct language: mydomain.com/en/ or mydomain.com/fr/

I have two angular assemblies with i18n, one for each language. redirect using language but no direct links from angular 2: if i go to mydomain.com/fr/connect -> 404

Here is my nginx config

map $http_accept_language $lang {
   default en;
   ~*^fr fr;
}

server {
    listen 80;
    server_name domain.com www.domain.com;
    root /usr/share/nginx/html;
    index  index.html index.htm;
    location = / {
        rewrite "^.$" /$lang/ break;
    }
    location = /$lang/ {
        try_files $uri $uri/ /index.html;
    }
}

      

if some of you know this i just got stuck there i start nginx: /

+3


source to share


1 answer


The second location block is incorrect. You probably need everything to target index.html

(other than resource files). You can try something like this:



map $http_accept_language $lang {
    default en;
    ~*^fr fr;
}

server {
    listen 80;
    server_name domain.com www.domain.com;
    root /usr/share/nginx/html;
    index  index.html index.htm;
    location = / {
        return 302 /$lang/;
    }
    location / {
        try_files $uri $uri/ /index.html;
    }
}

      

+3


source







All Articles