apache - Nginx 服务器重定向到错误服务器不起作用
问题描述
我一直在寻找解决这个问题的方法。这是我的设置。
服务器 A:192.168.1.99
Nginx 服务器最新版本:01-2020 版本。充当服务器 B 服务的所有站点的反向代理。
Apache 服务器(有两个用途):1. 服务站点,2. 如果“服务器 B 宕机”,则作为错误服务器
服务器 B:192.168.1.100
Apache 服务器:主站点服务器。
要求:
当服务器 B 关闭时,服务器 A 应作为具有相同域名的“错误页面”。例如:
如果服务器 B 服务于:example.com,并且如果它已关闭,则服务器 A 将提供如下错误页面:
example.com/error404.html 如果错误是 502 错误,它应该从服务器 A 提供 example.com/error502.html。
这是我的配置文件: 服务器 A: (Nginx Server) /etc/nginx/conf.d/example.com.conf
server {
listen 80;
if ($host = www.example.com ) {
return 301 https://example.com$request_uri;
# return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com ) {
return 301 https://example.com$request_uri;
# return 301 https://$host$request_uri;
} # managed by Certbot
}
server {
listen 443 ssl;
server_name www.example.com;
root /var/www/example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
proxy_intercept_errors on;
error_page 404 500 502 503 504 = @fallback;
proxy_pass https://192.168.1.100:9443/;
proxy_read_timeout 90;
#rewrite http://www.example.com/ https://www.example.com/ redirect;
proxy_redirect https://192.168.1.100:9443/ https://example.com;
}
index index.php index.html index.htm index.nginx-debian.html;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location @fallback {
root /var/www/example.com;
rewrite ^/(.*) https://example.com;
#proxy_pass https://192.168.1.99:6443/;
#proxy_redirect https://192.168.1.99:6443/ https://example.com;
#rewrite ^/(.*) https://192.168.1.99:6443/ permanent;
}
}
解决方案
推荐阅读
- excel - 从 Power Pivot 修改数据连接时出现 VBA 错误“1004”
- spring - 柑橘/黄瓜 MessageTracingTestListener 不起作用
- unity3d - 更改 RectTransform 的枢轴和锚点预设时如何保持游戏对象位置
- objective-c - AFNetworking ElfSundae UIWebView-Patch
- c++ - QuadTree的中序遍历
- jquery - jquery datepicker 排除除周二和周五以外的所有日期,并同时排除选定日期
- javascript - 如何优化 jQuery tag:contains() 选择器?
- python - 如何在 for 循环中强制执行多个 QComboBox 中的任何一个的最小索引?
- postgresql - Docker-compose:容器未运行
- android - Firebase 远程配置重叠条件组