开发者社区> 问答> 正文

Nginx的反向代理问题?报错

自己有一个境外的VPS,我都用这个VPS访问一些墙外网站,但是发现这个VPS无法访问百度,也不愿意去每次切换,所以想用自己的Windows Azure做一个对百度的反向代理。

 这个Windows Azure是国内的,使用的是Windows Server 2012 R2,反向代理软件是用Nginx For Windows 1.7.3版本。

结合网上找到的一些教程,自己对Nginx的配置文件做了如下设置:

1.把nginx.conf中的server{}移到vhosts.conf文件,并在nginx.conf中加上include vhosts.conf;

2.在vhosts.conf文件中有这些设置

upstream baidu {
        server 220.181.112.244:80;
}

server {
        listen       8090;
        server_name  127.0.0.1;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        
        location / {
            root   html;
            index  index.html index.htm;
        }

	location /baidu {
	    proxy_pass  http://baidu/;
	    
	    proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
	}

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #    root   html;
        #}
    }



除了这些就没有做任何更改,但是访问XXX.chinacloudapp.cn/baidu的时候,却出现502 Bad Gateway错误。查看错误日志,有以下报错信息

2014/07/16 21:45:40 [error] 22628#12216: *11 WSARecv() failed (10054: An existing connection was forcibly closed by the remote host) while reading response header from upstream, client: 59.52.146.143, server: 127.0.0.1, request: "GET /baidu HTTP/1.1", upstream: "http://220.181.112.244:80/", host: "XXX.chinacloudapp.cn:8090"

报错信息的*11经常变换,有时候*1、*6都有

请问有没有懂得大神帮我解决下这个问题 



展开
收起
爱吃鱼的程序员 2020-06-20 16:30:15 1134 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    报错说的是百度的服务器强制的断开了你的连接。应该是他发现了你的反向代理行为,然后干掉的。看一下你nginx发给220.181.112.244:80的请求头,该干掉的干掉,该加上的加上,伪装一下下。proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 把这个去掉,别加X-Forwarded-For 试试。<divclass="ref">

    引用来自“laichendong”的评论

    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 把这个去掉,别加 X-Forwarded-For 试试。<divclass='ref'>

    引用来自“laichendong”的评论

    报错说的是百度的服务器强制的断开了你的连接。应该是他发现了你的反向代理行为,然后干掉的。看一下你nginx发给220.181.112.244:80的请求头,该干掉的干掉,该加上的加上,伪装一下下。0.winX,汗!1.fq有Google,要度娘干毛!2.不建议全局代理,推荐foxyproxy3.网上有国内ip表,可以考虑用

    2020-06-20 16:30:33
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载