Skip to content

Instantly share code, notes, and snippets.

@carhartl
carhartl / ingress.yaml
Created November 16, 2022 08:29
Kubernetes nginx-ingress rewriting for SPA
# The rewrite rule for nginx is to pick the first capture group’s match $1 from the path matcher.
#
# In the path matcher regex there are 2 capture groups (the inner groups are not captured):
# /(...)|(.*)
# ^$1 ^$2
#
# So when we match anything that starts with "/api/" or ends with one of "css"/"js"/"png" this will
# populate $1 and nginx passes the url unaltered upstream (-> /$1). If there is no such match, we match
# everything else through the alternation: (.*) to populate $2, but we throw $2 away (we don't make use
# of it in the rewrite target! An empty capture group, in this second scenario $1, will turn into an