├── Dockerfile ├── README.md ├── default.conf └── LICENSE /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:mainline-alpine 2 | 3 | COPY default.conf /etc/nginx/conf.d/ 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## docker-nginx-static-spa 2 | 3 | A simple nginx container that serves Single Page Applications: 4 | - Redirects all requests to the `index.html` file 5 | - Assets compression using `gzip` in stylesheets and javascript files. 6 | 7 | [Docker Hub](https://hub.docker.com/r/iamfreee/docker-nginx-static-spa/) 8 | 9 | Very small size: ~7 MB (alpine based). Uses about 2 MB RAM when running. 10 | 11 | ## Instructions 12 | 13 | **Dockerfile:** 14 | ``` 15 | FROM iamfreee/docker-nginx-static-spa:latest 16 | COPY /dist /var/www/html 17 | ``` 18 | 19 | In the example above, the production build of the app is in the local `dist` folder and is moved to the default nginx serve path to be served. 20 | 21 | ## License 22 | MIT 23 | -------------------------------------------------------------------------------- /default.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; ## listen for ipv4; this line is default and implied 3 | listen [::]:80 default ipv6only=on; ## listen for ipv6 4 | 5 | root /var/www/html; 6 | index index.html; 7 | 8 | server_tokens off; # disable the Server nginx header 9 | 10 | server_name _; # all hostnames 11 | 12 | # enable gzip 13 | gzip on; 14 | gzip_disable "msie6"; 15 | 16 | gzip_comp_level 6; 17 | gzip_min_length 1100; 18 | gzip_buffers 16 8k; 19 | gzip_proxied any; 20 | gzip_types 21 | text/plain 22 | text/css 23 | text/js 24 | text/xml 25 | text/javascript 26 | application/javascript 27 | application/x-javascript 28 | application/json 29 | application/xml 30 | application/rss+xml 31 | image/svg+xml; 32 | 33 | location / { 34 | try_files $uri /index.html; # redirect all request to index.html 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Carlos Florêncio 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | --------------------------------------------------------------------------------