一、准备
WEB2 http://127.0.0.1:82/01/a/0.txt (即:此web没有1.txt)
二、最终意义:
1.用户请求http://www.c.com/a/1.txt
2.nginx先对a/1.txt路么进行重定向http://www.c.com/01/a/1.txt (访问http://127.0.0.1:83/01/a/1.txt)
3.发现http://www.c.com/01/a/1.txt没有资源
4.重新定向至http://www.c.com/a/1.txt ; (访问http://127.0.0.1:81/a/1.txt)
5.成功
三、Nginx配置
http {
server_names_hash_bucket_size 64;
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
fastcgi_intercept_errors on;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
upstream www.c.com {
server 127.0.0.1:83; # 请求公有云地址
server 127.0.0.1:81; # 请求源地址
}
server {
# proxy_set_header Host $http_host;
# proxy_set_header X-Forward-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header REMOTE_ADD $remote_addr;
listen 83;
server_name 127.0.0.1;
charset utf-8;
#access_log logs/host.access.log main;
location /a {
proxy_pass http://127.0.0.1:82/01/a; ; #实现目录重定向
}
}
server {
# proxy_set_header Host $http_host;
# proxy_set_header X-Forward-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header REMOTE_ADD $remote_addr;
listen 80;
server_name www.c.com;
charset utf-8;
proxy_next_upstream http_404 error timeout invalid_header;
#实现故障转移
#access_log logs/host.access.log main;
location /a {
proxy_pass http://www.c.com;
}
}
}