Multilanguage Websites

Francis Daly francis at
Mon Dec 31 17:55:18 UTC 2012

On Mon, Dec 31, 2012 at 05:50:14PM +0100, Silvio Siefke wrote:

Hi there,

> Ok, but what ways have nginx? I'm looking for a way for days.

What, precisely, do you mean by "Multilanguage Websites"?

If you mean "separate content for each of language1, language2,
language3; all available at separate urls", then you need no
special web server cleverness after the user has chosen to go to or to
(depending on how you deploy it).

All you need is for the index page on the "main" web site to offer a
series of links to each of the known separate language index pages.

Have a look at (for example) or (as you've
previously linked to)

The former looks like it serves the same content to all; the latter tries
some guessing of preferred language which fails on some of my browsers.

If you want to implement some cleverness on the index page to avoid the
user having to manually choose language, you must decide what you want
the choice to be based on. Whatever you do choose, it may be worth your
while making clear to the user why you chose that one, and what the user
can do to get to the language version they actually prefer.

The HTTP Accept-Language header is probably a reasonable choice, if your
users know how to change it or to override it for your site.

You are unlikely to be able to write a correct interpreter for the
content of that header in the confines of the nginx.conf language.

So you are probably better off writing an application to do it --
maybe in one of the embedded languages, or maybe as external code
altogether. That application will need up-to-date information on which
languages are currently available, so I suggest that external code is
probably simpler to maintain.

> Accept Language looks good, but with Gentoo I can use the module only 
> without package manager. The websites in different languages ​​are done, 
> I needed a redirect and a default solution.

The only modules used in the nginx.conf versions that you have linked
to are core, map, and rewrite, as far as I can see. I suggest you use
one of the "other server" modules, such as fastcgi.

The only unusual part of nginx.conf would then be special handling for

  location = / {}

where you would cause your external code to return either a redirect to
the appropriate language index page, or the content (or a redirect to the
content) of the "here are the various links, click the one you like" page.

If you want to know how to properly interpret the content of the
Accept-Language header, read the RFC or examine (for example) apache's
mod_negotiation.c. You should compare "languages available" with "ordered
list of languages acceptable", being aware of how (for example) "de-DE",
"de-AT", and "de" compare within and between those lists.

It's complicated. That's why I suggest you do it outside of nginx.conf.

If, instead of all of that, you want "same url gives different content
to different clients based on their preferred language", then there's
probably a lot more work involved.

Francis Daly        francis at

More information about the nginx mailing list