我的环境中有 nginx 代理和 2 个上游(主上游服务器和备份上游服务器)服务器,目标是根据所选的上游来更改“proxy_set_header Host X/Y”。
现在我只有一个想法,创建另一个 nginx 实例并将所有请求从我的代理发送到该实例,重写标头并进一步发送请求。
有谁知道更方便的解决方案吗?
这是我的简化配置:
http {
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
upstream images {
server backend.test.com:8080 ;
server backend-backup.test.com:8090 backup;
}
server {
listen 80 default_server;
server_name images-test.test.com;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
add_header Last-Modified "";
add_header Pragma "public";
add_header Access-Control-Allow-Origin $http_origin;
error_page 404 /404.html;
location = /404.html {}
error_page 500 502 503 504 /50x.html;
location = /50x.html {}
location / {
# some not related to the question lines deleted
proxy_set_header Host "backend.test.com";
proxy_pass http://images;
}
}
}