Nginx 作为通用代理服务器

mb2*_*b21 1 proxy nginx

我正在尝试使用 nginx 作为代理服务器来访问一些不支持 CORS 的 API。我的配置的一部分:

server {

    listen       8000;
    server_name  localhost;

    merge_slashes off;
    resolver 8.8.8.8;

    location ~ ^/proxy/(.*) {
        proxy_pass $1;
    }
}
Run Code Online (Sandbox Code Playgroud)

但它似乎没有传递 GET 参数,因为我遇到了与提供 none 或无效 apikey 时相同的错误:

$ curl -i 'http://localhost:8000/proxy/http://api.rottentomatoes.com/api/public/v1.0/lists.json?apikey=myapikey'
HTTP/1.1 403 Forbidden
Server: nginx/1.6.0
Date: Thu, 15 May 2014 15:33:40 GMT
Content-Type: text/javascript
Content-Length: 28
Connection: keep-alive
X-Mashery-Error-Code: ERR_403_DEVELOPER_INACTIVE
X-Mashery-Responder: prod-j-worker-us-east-1c-31.mashery.com

{"error":"Account Inactive"}
Run Code Online (Sandbox Code Playgroud)

而且我不太了解proxy_pass 文档

mb2*_*b21 5

结果我必须手动传递 GET 参数$args

server {
    listen       8000;
    server_name  localhost;

    merge_slashes off;
    resolver 8.8.8.8;

    location ~ ^/proxy/(.*) {
        proxy_pass $1?$args;
    }
}
Run Code Online (Sandbox Code Playgroud)