http://localhost:8080/ delivers a 403 Forbidden
The Problem
Upon following the directions to the letter, when I go to http://localhost:8080/ I get a 403: Forbidden nginx error screen:
While it is non-trivial to figure it out, the problem is that Language Auto-Detection is not performed, seemingly anywhere, and thus the user is not redirected to the appropriate dist/{language}
folder (dist/en
by default).
The Solution
I implemented the industry-accepted way to redirect to the user's Accept-Language
header setting directly via nginx.
Assuming French and English are the only two supported languages:
- If the user has the header,
fr, en
, it will show the French page. - If the user has the header
es, en
, it will show the English page. - If the user does not set a header (some search engines, curl, etc.), it will show the English page.
It's not as detailed as the AcceptLanguages
nginx extension, but it also doesn't require you to custom-compile nginx and ensure it's continually uptodate, either. I've used this setting in my own sites and never had a problem.
This only applies to the /
route. It is assumed that any other route will be in the desired language. To implement a more detailed language check, it would require much more advanced JS sniffing that is beyond the scope of this issue.