Nginx作为通用代理服务器

时间:2014-05-15 15:37:55

标签: nginx proxy

我试图使用nginx作为代理服务器来获取一些不支持CORS的API。部分配置:

server {

    listen       8000;
    server_name  localhost;

    merge_slashes off;
    resolver 8.8.8.8;

    location ~ ^/proxy/(.*) {
        proxy_pass $1;
    }
}

但它似乎没有传递GET参数,因为我得到了与提供无效或无效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"}

我还没有得到proxy_pass documentation

1 个答案:

答案 0 :(得分:1)

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

server {
    listen       8000;
    server_name  localhost;

    merge_slashes off;
    resolver 8.8.8.8;

    location ~ ^/proxy/(.*) {
        proxy_pass $1?$args;
    }
}