root /path/to/project/dist;
# For APIs
proxy /api/xxx {
without /api
upstream xxx_server
transparent
}
# For HTML5 history api
rewrite {
if {path} not_match ^\/api\/
to {path} {path}/ /index.html;
}
Problems:
Proxies work but it doesn’t seem that they will send GET params at together.
Not 100% sure what you mean, are you referring to your upstream server not receiving query parameters?
This can be solved by replacing {path} with either {uri} or {path}?{query} in the to subdirective.
Try ditching the ; on the end of /index.html. If that’s not the problem, it might be the regex, but it looks good to me. You could also try logging the rewrites by appending the {rewrite_uri} placeholder to a custom logging format (see below).
This middleware adds a placeholder that can be used in log formats: {upstream} - the name of the upstream host to which the request was proxied.
To define a custom logging format, you can take a look at the docs for the log directive. If you just want the default format, but with the upstream appended, you can use log / stdout "{common} {upstream}".