Last active
April 4, 2023 06:07
-
-
Save foru17/3aa05164e96f0f3da43bb81d101aefba to your computer and use it in GitHub Desktop.
Nginx 主从兜底配置
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
listen 443 ssl http2; | |
server_name demo.domain.com; | |
index index.php index.html index.htm default.php default.htm default.html; | |
root /www/wwwroot/demo.domain.com; | |
recursive_error_pages on; | |
proxy_intercept_errors on; | |
location / { | |
error_page 418 = @backend; | |
return 418; | |
} | |
location @backend { | |
# 优先请求 | |
proxy_pass http://proxy.domain.com:20220; # homelab 公网 | |
proxy_set_header Host demo.domain.com; | |
proxy_set_header X-Forwarded-For $remote_addr; | |
proxy_set_header X-NginX-Proxy true; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
error_page 404 500 502 = @handle_fallback; | |
} | |
location @handle_fallback { | |
# 兜底请求 | |
proxy_pass http://demo.frp.domain.com:4080; # homelab frpc 穿透 | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host demo.frp.domain.com:80; | |
proxy_set_header X-NginX-Proxy true; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
error_page 451 = @backend; # 重新请求 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment