我的環境中有 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;
}
}
}