我在设置 Cloudflare 的自定义错误页面功能时遇到了一些烦人的问题,所以我想弄清楚如何仅当我的服务器未返回错误代码时才将 proxy_pass 到 cloudflare,因为我真的只想使用这些来显示我创建的自定义页面,而不是 Cloudflare 的默认页面。
以下是 nginx 站点可用配置:
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
}
我想要的是仅当我的服务器没有抛出错误代码时才使用 Cloudflare 作为代理,我该如何实现呢?
我认为使用 cloudlfare 接口的 DNS 设置比服务器块更强大,因此我希望使用 Nginx 的服务器块而不是完整的 DNS 代理来做到这一点。