NGINX의 해결 프로그램이 DNS 확인 캐시를 자동으로 업데이트하려고하므로 변수를 proxy_pass
값으로 사용하여이를 달성하려고합니다. 그러나 변수를 사용하면 모든 요청이 요청의 루트 끝점으로 이동하고 URL의 추가 경로는 모두 차단됩니다. 내 설정은 다음과 같습니다.NGINX - proxy_pass에서 변수를 사용하면 라우팅이 깨집니다.
resolver 10.0.0.2 valid=10s;
server {
listen 80;
server_name localhost;
location /api/test-service/ {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# If these 2 lines are uncommented, 'http://example.com/api/test-service/test' goes to 'http://example.com/api/test-service/'
set $pass_url http://test-microservice.example.com:80/;
proxy_pass $pass_url;
# If this line is uncommented, things work as expected. 'http://example.com/api/test-service/test' goes to 'http://example.com/api/test-service/test'
# proxy_pass http://test-microservice.example.com:80/;
}
하드 코드 된 URL과 변수 값이 동일하기 때문에이 사실이 저에게 의미가 없습니다. 내가 빠진 것이 있습니까?
편집 : 아, 문제를 발견했습니다. 그러나 나는 그것을 어떻게 다룰 지 완전히 모릅니다. 이것은 역방향 프록시이기 때문에 프록시에 전달하기 전에 URI에서 /api/test-service/
을 제거하려면 proxy_pass
이 필요합니다. 그래서 ..
이이에
http://example.com/api/test-service/test
해야 프록시 : 이것에
http://test-microservice.example.com:80/test
하지만 그 대신 프록시 :
http://test-microservice.example.com:80/api/test-service/test
내가 변수를 사용하지 않는, 그것은 아무런 문제가 없습니다. 그러나 변수는 그것을 추가합니다. 그것은 본질적으로 변수를 사용하는 것이 무엇입니까?