Nginx how to show IP blocked page?
You can not use the =
equals prefix in named locations (indicated by the @
at sign). Those are always exact matches anyway - and are not prefixed like regular URIs, as shown in the two distinct syntax descriptions for location
:
location [ = | ~ | ~* | ^~ ] uri { ... }
location @name { ... }
You can then force the path passed to your upstream to be the one you want:
location @unavailable.html {
rewrite ^ /unavailable.html break;
proxy_pass https://myapp.ondigitalocean.app;
}
The Nginx docs actually recommend not putting the URI into the proxy_pass
directive here; emphasis mine:
In some cases, the part of a request URI to be replaced cannot be determined: When location is specified using a regular expression, and also inside named locations. In these cases, proxy_pass should be specified without a URI.
Side note: You should not use return 444
unless you want the special behaviour Nginx assigns to that value. You should also not return a status code 200
unless you successfully return the requested resource.
If you have made the resource unavailable for your sites visitor based on the country you suspect him browsing from, return a code specific to the reason you made that so (typically 403 Forbidden
or 451 Unavailable For Legal Reasons)
)