如何配置nginx.conf以便我可以使用nginx作为代理访问其他网站?

时间:2011-05-25 06:14:47

标签: proxy nginx

我这样做,但总是得到404页面:

location / {
                proxy_pass        http://localhost:81;
                proxy_set_header  X-Real-IP  $remote_addr;
        }

请求尝试:

telnet localhost 81

GET http://stackoverflow.com/ HTTP/1.1
Host: stackoverflow.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.17) Gecko/20110420 AlexaToolbar/alxf-2.11 Firefox/3.6.17
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Cookie: A=t;
Cache-Control: max-age=0

结果得到:

HTTP/1.1 404 Not Found
Server: nginx/1.0.2
Date: Tue, 24 May 2011 00:30:51 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive

<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.0.2</center>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

location / {
    proxy_pass http://$http_host$request_uri;
}

resolver 8.8.8.8;