0

I've an Angular2 SPA, I've added the language as suffix to urls, like this:

www.mywebsite.com/en

If I load directly from nodejs webserver in this way -> www.mywebsite.com:4500/en the request is correctly handled by angular of course.

Now when I'm using nginx I don't know how to tell to nginx that urls with language suffix must be handled by index.html.

In the nginx config file I've setup some other location that are working fine. Only this configuration is needed.

With the following settings, nginx reply 404 and the nginx errorlog file report:

appfolder/dist/client/en (no such file or directory)

server {

    listen 80 default_server;
    listen [::]:80 default_server;
    root /appfolder/dist/client;
    index index.html;

    location ~ /(fr|en|es|it) {       
       root /appfolder/dist/client;
    }


    location /{      
      return 301 /en$uri;
    }

    other location's without conflict with this

} 

I've tried a lot of other configurations by search on google but without result.

How can I tell to nginx that I want that url with languages has to be handled by index file?

0

I've found one solution that seems to work, better solution are welcome

Set the location in this way

   location / {}

   location /it {
        alias /project/dronedesign/dist/client;
        index index.html;
        try_files $uri $uri/ /index.html;
    }


    location /en {
        alias /project/dronedesign/dist/client;
        index index.html;
        try_files $uri $uri/ /index.html;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.