'Nginx Proxy_pass / redirect to fixed url
I created a simple react app to serve as an error page (might be a bit overkill). The idea is that we can easily customize the errors via query parameters or URL structure (using react router) with the goal to create cloudlfare style error pages as we need them.
For a forbidden route a config could look like this:
# Is needed as far as I know to serve react files at the root such as scripts and media
location / {
proxy_pass http://error-page:3000;
}
location /forbidden {
proxy_pass https://error-page:3000/error403/;
}
I have tried a lot of configs and so far I had the most success with try_files $uri /error403/index.html
. However what I do not like about this approach is that it seems like the URL is rewritten in the browser, meaning the user will see /error403 instead of /forbidden
What approach should we use to be able to serve specific react pages with a different path without overwriting the path, so that the user can see it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|