我想做 proxy_pass
从https://foo.bar/api/v1/users/{userId}/store/{storeCode}/status
到https://bar.foo/api/v1/users/{userId}/store/{storeCode}/status
并且
从https://foo.bar/api/v1/users/{userId}/opendate
到https://bar.foo/api/v1/users/{userId}/opendate
这两个链接的不同之处在于使用 http 方法进行访问,稍后我们将使用 limit_except 来限制访问,但现在我想先通过 proxy_pass 来传递请求。
我做了这样的配置
location /api/v1/users/[0-9a-z]+/store {
proxy_pass https://bar.foo/api/v1/users/[0-9a-z]+/store;
proxy_set_header Host $proxy_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_buffering off;
proxy_ssl_protocols TLSv1.2;
proxy_ssl_server_name on;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass_request_headers on;
}
location /api/v1/users/[0-9a-z]+/opendate {
proxy_pass https://bar.foo/api/v1/users/[0-9a-z]+/opendate;
proxy_set_header Host $proxy_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_buffering off;
proxy_ssl_protocols TLSv1.2;
proxy_ssl_server_name on;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass_request_headers on;
}
但是我仍然没有让我的服务器代理请求。有谁知道如何在 nginx 中使用一些正则表达式来 proxy_pass 长指令位置?