Coder Social home page Coder Social logo

steebchen / nginx-spa Goto Github PK

View Code? Open in Web Editor NEW
30.0 3.0 14.0 5 KB

An alpine-based nginx image for single page applications (SPA)

Home Page: https://hub.docker.com/r/steebchen/nginx-spa/

License: MIT License

Dockerfile 100.00%
docker nginx spa alpine html5-history vue react angular svelte deployment docker-image spas history-api dockerfile single-page-applications routing hash reactjs vuejs angularjs

nginx-spa's Introduction

NGINX Docker image for SPAs

docker pull steebchen/nginx-spa

This docker image can be used for single page apps (SPAs) in history mode. It serves your index.html if no other file matches.

Quickstart

To create your own dockerfile, simply copy your distribution folder (often dist/ or build/) to /app into the image.

# append the following in your existing dockerfile
# this will create a multi-stage docker build for minimizing size and security vulnerabilities
# ...

FROM steebchen/nginx-spa:stable

# adapt the `dist/` folder to the output directory your build tool uses (such as `dist/`, `build/` or `www/`).
COPY dist/ /app

EXPOSE 80

CMD ["nginx"]

Simply run your container as follows:

docker build -t your-app .
docker run -p 8000:80 your-app

Now you can visit http://localhost:8000/ in your browser or run curl -v http://localhost:8000/ to check if it's working.

What it does

Single page applications (SPAs) often use the HTML5 history API. This results in neat urls like /user/john, but will result in a 404 when accessed directly in the browser.

This means you have to configure your webserver to serve your entrypoint (index.html) on all routes per default, which es exactly what this docker image does.

Additionally, routes containing a dot will default to a 404 to prevent sending the index.html for routes like /static/asset.js. This is super useful, but may break your app if you have app urls with dots in it (which I doubt).

Files including a dot will also have a Cache-Control header set to instruct browsers to cache content for 30 days. This is perfect if you're using webpack or similar frameworks which usually makes use of creating files with hashes in their names, but if your static files will be just named "bundle.js" or "0.css" (index.html is fine of course) you should avoid this image.

Supported tags and dockerfile links

Notes

  • Gzip is enabled for html, xml, js and css
  • A default public caching header is set
  • The nginx daemon is turned off in the settings

nginx-spa's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.