I am running into slightly annoying issues setting up Cloudflare's custom error page functionality, so I would like to figure out how I can proxy_pass to cloudflare only when my server does not return an error code as I really only want to use these in order to show a custom page I create as opposed to Cloudflare's default ones.
Here is the nginx sites-available config:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream app {
server 127.0.0.1:8000;
# server CLOUDLFARE_ADDRESS_FOR_PROXY
}
server {
listen 443 ssl;
server_name example.com www.example.com;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_headers_hash_max_size 512;
proxy_headers_hash_bucket_size 128;
# can this work somehow?
# proxy_next_upstream [non-error] CLOUDLFARE_ADDRESS_FOR_PROXY
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js|pdf)$ {
expires 1d;
}
error_page 500 502 503 504 /custom_50x.html;
location = /custom_50x.html {
root /usr/share/nginx/html;
internal;
}
ssl_certificate /etc/letsencrypt/live/exactestate.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/exactestate.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
What I want is to use Cloudflare as a proxy only if my server throws no error codes, how can I accomplish this?
DNS settings using the cloudlfare interface are more powerful than server blocks I suppose so I would like a way to do this using Nginx's server block as opposed to a full DNS Proxy.