Skip to content

Instantly share code, notes, and snippets.

@amimaro
Last active May 11, 2021 23:42
Show Gist options
  • Save amimaro/c2a23153794850a8c6c4ccc78539ddd2 to your computer and use it in GitHub Desktop.
Save amimaro/c2a23153794850a8c6c4ccc78539ddd2 to your computer and use it in GitHub Desktop.
NGINX configuration to deploy (Angular application) on docker
events {}
http {
# Browser preferred language detection (does NOT require AcceptLanguageModule)
map $http_accept_language $accept_language {
~*^pt pt;
~*^en en;
}
server {
listen 80;
root /usr/share/nginx/html;
# Fallback to default language if no preference defined by browser
if ($accept_language ~ "^$") {
set $accept_language "en";
}
# Redirect "/" to Angular app in browser's preferred language
rewrite ^/$ /$accept_language permanent;
# Everything under the Angular app is always redirected to Angular in the correct language
location ~ ^/(pt|en) {
try_files $uri /$1/index.html?$args;
}
# ...
}
}
"node_modules"
FROM node:14.16.0 as build
WORKDIR /app
COPY . /app
RUN yarn
RUN yarn build-prod
FROM nginx
WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY --from=build /app/dist/PROJECT_NAME /usr/share/nginx/html
EXPOSE 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment