
경로의 ID를 다른 ID(도메인)로 다시 작성하기 위해 nginx 역방향 프록시를 설정하려고 합니다. 예를 들어
https://somewhere.com/user/123/setting -->https://somewhere.else.com/user/456/setting
하지만 부품을 다시 작성하는 데 어려움을 겪고 있습니다. 누군가 도와주실 수 있나요?
map $old_user_id $new_project_id {
123 456;
999 9876;
12 56;
}
server {
location ~ ^/api/(?<old_project_id>.+)/store {
rewrite ^/api/[^/]+(/.*)/store ....... # how to rewrite with the map?
proxy_pass http://somewhere.else.com/;
}
}
답변1
정규식이 예제의 ID와 일치하지 않습니다.
다음을 변경하면 문제를 해결할 수 있습니다.
location ~ ^/api/(?<project_id>.+)/store {
rewrite ^/user/(.*)/setting /user/$project_id_2/setting break;
proxy_pass http://host.docker.internal:8080;
}