'Nginx error page when error page does not exist
I would like to have custom error pages for each domain that is hosted on my server.
I have a directory structure like the following
data
defaults
error.html
example.com
misc
error.html
example.net
...
Now i would like to show misc/error.html if it is there for the domain name being accessed and else display default/error.html.
What i currently have what isn't working is the following. It doesn't work because it just displays the default nginx 404 page if the error page (misc/error.html) is not found (even when the error isn't even a 404 error).
server_name ~^(www\.)?(?<domain>.+)$;
location / {
root /data/$domain;
try_files $uri $uri/ =404;
index index.html index.htm index.php;
}
error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 421 422 423 424 425 426 428 429 431 451 500 501 502 503 504 505 506 507 508 510 511 @error;
location @error {
internal;
ssi on;
auth_basic off;
root /data;
try_files /$domain/misc/error.html /defaults/error.html;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
