'How can I conditionally display an error page in nginx?
How can I configure nginx to return an error_page if the URI does not contain ajax but if it does contain ajax don't send an error page and just return the response? Something like the following but I can't figure out how to access $status. I want to do this for all statuses that are 4xx or 5xx
Essentially, I want to be able to receive a JSON response when there is an AJAX request error and an error page when the request failed to render HTML
# If the location contains ajax
location ~ ajax {
# Return the error status code
return $status;
}
# Location did not contain ajax so send an error page
error_page $status error.html;
Thank you!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
