Skip to content

Instantly share code, notes, and snippets.

@alex-arriaga
Last active July 6, 2023 15:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-arriaga/da5cf14bd96dd070323b109f47714f98 to your computer and use it in GitHub Desktop.
Save alex-arriaga/da5cf14bd96dd070323b109f47714f98 to your computer and use it in GitHub Desktop.
Nginx sample configuration for an Angular Multilingual application
server {
listen 80;
root /var/www/html/my-app/dist;
index index.html index.htm;
server_name angular-i18n.example.com www.angular-i18n.example.com;
location /en/ {
autoindex on;
try_files $uri$args $uri$args/ /en/index.html;
}
location /es/ {
autoindex on;
try_files $uri$args $uri$args/ /es/index.html;
}
# Default to EN
location / {
# Autoindex is disabled here + the $uri$args/ is missing from try_files
try_files $uri$args /en/index.html;
}
# REALLY important for JavaScript modules (type="module") to work as expected!!!
location ~ \.js {
add_header Content-Type text/javascript;
}
}
@alex-arriaga
Copy link
Author

alex-arriaga commented Jun 25, 2019

This file should be linked into the "sites-enabled" directory in your Nginx installation:

sudo ln -s /etc/nginx/sites-available/angular-i18n.example.com /etc/nginx/sites-enabled/
sudo service nginx configtest
sudo service nginx reload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment