Skip to content

Instantly share code, notes, and snippets.

@bjesuiter
Created July 13, 2021 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjesuiter/e2ffa3fcf1878846ae295bd80066999b to your computer and use it in GitHub Desktop.
Save bjesuiter/e2ffa3fcf1878846ae295bd80066999b to your computer and use it in GitHub Desktop.
Multi-SPA Nginx Config
server {
listen 8080;
server_name localhost;
# Logging Settings
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /usr/share/nginx/www/;
index index.html;
# Shows the folder index of www folder (includes all things from /dist after angular compilation)
# The try_files directive probes subfolders for index.html files & also supports
# client side routing from the index.html in the subfolder (only 10 levels of redirection)
location / {
autoindex on;
try_files $uri $uri/ @rewrite;
}
# Probes every folder above the currently loaded document for an index.html
# Src: https://stackoverflow.com/questions/62058405/nginx-serving-multiple-spa-s-on-a-single-server
# > The index and try_files directives handle looking for index.html,
# > and the rewrite statement truncates the URI by removing one or more characters following a /.
location @rewrite {
rewrite ^/(.+/)?. /$1 last;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment