Nginx的代理caching(proxy_pass $ request_uri;)

我需要使用nginx创build代理网页。 如果我访问http://myweb.com/http://www.target.com/,则proxy_pass应为http://www.target.com/

这是我的configuration:

location / { proxy_pass $request_uri; proxy_cache_methods GET; proxy_set_header Referer "$request_uri"; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_ignore_headers Cache-Control; proxy_hide_header Pragma; proxy_hide_header Set-Cookie; proxy_set_header Cache-Control Public; proxy_cache cache; proxy_cache_valid 200 10h; proxy_cache_valid 301 302 1h; proxy_cache_valid any 1h; } 

这是日志错误

 2013/02/05 12:58:51 [error] 2118#0: *8 invalid URL prefix in "/http://www.target.com/", client: 108.59.8.83, server: myweb.com, request: "HEAD /http://www.target.com/ HTTP/1.1", host: "myweb.com" 

尝试使用nginx的map-Module来以您想要的方式定义variables:

 map $request_uri $proxy_pass_target { default "http://myweb.com"; ~^/(.+)$ $key; } 

然后你可以在你的proxy_pass指令中使用$proxy_pass_target而不是$request_uri

请注意,我没有testing它是否工作。 也许你需要调整正则expression式。 更多的文档可以在这里find: http : //wiki.nginx.org/HttpMapModule