Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#134) Added nginx-based auto-language negotiation for /. #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion containers/nginx/dev.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Dynamic language redirection.
# Ensure that "en" is last, or people with, for instance, "fr en" will always default to "en".
map $http_accept_language $lang {
default en;
~es es;
~fr fr;
~en en;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend adding at least one other language to the dev environment so proper testing can be done. Quizás español?

}

server {
listen 80;
listen [::]:80 default ipv6only=on;
Expand All @@ -24,6 +33,11 @@ server {
port_in_redirect off;
}

# Redirect to the language directory specified by the user's browser via the Accept-Language header.
location ~ ^/$ {
return 301 $scheme://$http_host$1/$lang/;
}

location ~ ^(/api|/fs|/icon|/carousel) {
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Credentials' 'true';
Expand Down Expand Up @@ -98,4 +112,4 @@ server {
log_not_found off;
deny all;
}
}
}
14 changes: 14 additions & 0 deletions containers/nginx/minds.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Dynamic language redirection.
# Ensure that "en" is last, or people with, for instance, "fr en" will always default to "en".
map $http_accept_language $lang {
default en;
~es es;
~fr fr;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list will need to be kept in sync with the languages supported by the application. There are methods to automatically sync this, particularly if you run Docker on production.

~en en;
}

server {
listen 80;
listen [::]:80 default ipv6only=on;
Expand Down Expand Up @@ -25,6 +34,11 @@ server {
port_in_redirect off;
}

# Redirect to the language directory specified by the user's browser via the Accept-Language header.
location ~ ^/$ {
return 301 $scheme://$http_host$1/$lang/;
}

location ~ ^(/api|/fs|/icon|/carousel) {
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
add_header 'Access-Control-Allow-Origin' "$http_origin";
Expand Down