'Add language prefix to localhost base url using nginx server

I would like to add /fr to my base url in order to test language switch of my Angular application

I set my nginx.conf as bellow:

server {
    listen       4000;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        rewrite ^/$ /fr/;
        root   html;
        index  index.html index.htm;
    }

When I navigate to localhost:4000 I get redirected to /localhost:4000/fr but I get 404 error page instead of my index page.

When I omit the line rewrite ^/$ /fr/; I get my index page working.

Here's the error on console

The character encoding of the HTML document has not been declared. The document will be displayed with incorrect characters for some browser configurations if the document contains characters outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source