Last active
January 14, 2021 17:03
-
-
Save umairhm/6df409a63c3ab438f3340f9597672116 to your computer and use it in GitHub Desktop.
Bundling multiple SPAs in one Docker image and using nginx to serve them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM nginx:alpine | |
COPY nginx.conf /etc/nginx/nginx.conf | |
## Remove default nginx index page | |
RUN rm -rf /usr/share/nginx/html/* | |
COPY dist/apps usr/share/nginx/html | |
EXPOSE 80 | |
ENTRYPOINT ["nginx", "-g", "daemon off;"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
events { worker_connections 1024; } | |
http { | |
server { | |
listen 80; | |
root /usr/share/nginx/html; | |
include /etc/nginx/mime.types; | |
location /app-one { | |
try_files $uri /app-one/index.html; | |
} | |
# This is to serve static assets | |
location ~* ^/app-one(/.+\.(js|css|jpe?g|ttf|ico|svg|txt|json|png|gif|woff))$ { | |
alias /usr/share/nginx/html/app-one$1; | |
} | |
location /app-two { | |
try_files $uri /app-two/index.html; | |
} | |
location ~* ^/app-two(/.+\.(js|css|jpe?g|ttf|ico|svg|txt|json|png|gif|woff))$ { | |
alias /usr/share/nginx/html/app-two$1; | |
} | |
# Anything below is for optimization of static assets. I found it somewhere on SO, but unfortunately lost the reference. | |
gzip on; | |
gzip_vary on; | |
gzip_http_version 1.0; | |
gzip_comp_level 5; | |
gzip_types | |
application/atom+xml | |
application/javascript | |
application/json | |
application/rss+xml | |
application/vnd.ms-fontobject | |
application/x-font-ttf | |
application/x-web-app-manifest+json | |
application/xhtml+xml | |
application/xml | |
font/opentype | |
image/svg+xml | |
image/x-icon | |
text/css | |
text/plain | |
text/x-component; | |
gzip_proxied no-cache no-store private expired auth; | |
gzip_min_length 256; | |
gunzip on; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment