【问题标题】:How to configure nginx.conf so that I can use nginx as proxy to visit other sites?如何配置 nginx.conf 以便我可以使用 nginx 作为代理访问其他站点?
【发布时间】:2011-06-28 13:55:31
【问题描述】:

我是这样做的,但总是得到 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>

【问题讨论】:

标签: proxy nginx


【解决方案1】:
location / {
    proxy_pass http://$http_host$request_uri;
}

resolver 8.8.8.8;

【讨论】:

    猜你喜欢
    • 2018-07-25
    • 1970-01-01
    • 2013-08-21
    • 2021-01-08
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多