vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

add nginx config example

Open Alexufo opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe.

Hard to understand how netllify example should be rewritten for nginx

/*  /es/:splat  302  Language=es
/*  /fr/:splat  302  Language=fr
/*  /en/:splat  302

Describe the solution you'd like

nginx config wll be nice to present in doc

Describe alternatives you've considered

No response

Additional context

No response

Validations

Alexufo avatar Nov 22 '23 16:11 Alexufo

Try the solutions mentioned in this threads - https://stackoverflow.com/a/9983986/11613622 -- you can also search online for similar solutions (make a web search on something like "nginx redirect based on language header"). Please let us know whichever solution works for you. We will add that to docs.

brc-dd avatar Nov 22 '23 17:11 brc-dd

О... that's my misunderstanding. I thought that vitepress would add the language prefix to all urls in the sidebar automatically, and that this required setting a parameter in the cookie that would redirect the server to the correct language prefix.

There is no information in the documentation that you need to add the language prefix yourself. After that I didn't need any redirect. A redirect is needed to redirect to the desired language from the browser language. Of course, there are plenty of examples for this in your links.

Alexufo avatar Dec 06 '23 22:12 Alexufo

cleanUrls: true

with nginx conf

root /viteproject/.vitepress/dist;

location / {
    try_files $uri $uri/ $uri.html =404;
}

I used this nginx settings. it is worked

pclokcer avatar Dec 26 '23 16:12 pclokcer

I use the following code snippet, and it works well:

map $http_accept_language $lang {
    default "";
    ~*^zh zh;
}


server {
    ...
    location = / {
        rewrite (.*) $1/$lang;
        root    html/my-docs;
        index   index.html;
    }
    location / {
        root    html/my-docs;
        index   index.html;
    }
}

TerryYoung518 avatar Mar 31 '24 08:03 TerryYoung518