Created
July 13, 2021 07:54
-
-
Save bjesuiter/e2ffa3fcf1878846ae295bd80066999b to your computer and use it in GitHub Desktop.
Multi-SPA Nginx Config
This file contains 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
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