Nginx는 업스트림 서버에 따라 헤더를 변경합니다.

Nginx는 업스트림 서버에 따라 헤더를 변경합니다.

내 환경에는 nginx 프록시와 2개의 업스트림(주 업스트림 서버 및 백업 업스트림 서버) 서버가 있습니다. 목표는 선택한 업스트림에 따라 "proxy_set_header 호스트 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;
        }
}

}

관련 정보