proxy_pass
기본적으로 원격 API를 호출하기 위해 지시문을 사용하려고 합니다 .
지금까지 내가 얻은 것은 다음과 같습니다.
server {
location /a {
proxy_pass https://a.com;
rewrite ^/a(.*)$ $1 break; # no trailing slash, defined in application code
}
location /b {
proxy_pass https://b.com;
rewrite ^/b(.*)$ $1 break; # no trailing slash, defined in application code
}
location / {
# Rest of configuration
}
}
location /a
나는 잘 작동하지만 location /b
어떤 이유로든 작동하지 않는다는 사실에 갇혀 있습니다 ( HTTP/404
).
location /b
이런 식 으로 후행 슬래시를 사용해 보았습니다.
location /b/ {
proxy_pass https://b.com/;
rewrite ^/b/(.*)$ $1 break;
}
하지만 이것도 작동하지 않습니다.
어떤 도움이라도 환영합니다.
답변1
내 특정 문제에 대한 답을 찾았습니다.
두 개의 API 서버는 동일한 방식으로 구성되지 않았으므로 nginx 구성을 약간 조정해야 했습니다.
- 서버에 지시문
b.com
이 필요proxy_set_header Host $host
하고rewrite
지시문이 필요하지 않습니다. - 서버에는 지시어
a.com
가 필요했지만rewrite
지시어는 필요하지 않았습니다.proxy_set_header Host $host
이로 인해 다음과 같은 (나를 위해 일하는) 구성이 남습니다.
server {
location /a {
proxy_pass https://a.com;
rewrite ^/a(.*)$ $1 break;
}
location /b {
proxy_set_header Host $host;
proxy_pass https://b.com;
}
}