当前位置:首页 > 服务器技术 > nginx

CentOS 6下Nginx正向代理配置

CentOS 6下Nginx正向代理配置

By:老宁


一、环境介绍


技术分享650) this.width=650;" src="/upload/getfiles/default/2022/11/4/20221104121052441.jpg" title="P91F_$K(NJM5LSSE[2WG2)P.png" width="500" height="69" border="0" hspace="0" vspace="0" />

1、Client作为需访问访问互联网PC终端;

  • 网卡地址:192.168.1.200

2、Nginx Server作为互联网出口代理服务器;

  • 内网网卡:192.168.1.100

  • 外网网卡:10.10.16.186

二、配置介绍

1、Nginx Server端配置:

[root@localhost]# cat  /usr/local/nginx/nginx.conf

    server {

        listen       80;                  #监听80端口

        server_name  192.168.1.100;       #Server 的内容地址,与Client地址互通

        resolver  8.8.8.8;                #DNS

        location / {

        proxy_pass http://$http_host$request_uri;    #$http_host和$request_uri是nginx系统变量,不需要替换,保持原样

        } 

}

2、Client端配置:

[root@localhost ~]# export http_proxy=http://192.168.1.100:80   #设定变量环境,指定代理服务器IP地址及端口

测试:

[root@localhost ~]# wgetwww.baidu.com      #可以成功访问百度了

--2017-10-17 13:08:15--  http://www.baidu.com/

正在连接 192.168.1.100:80... 已连接。

已发出 Proxy 请求,正在等待回应... 200 OK

长度:未指定 [text/html]

正在保存至: “index.html.1”

 

    [<=>                                                 ] 99,762      --.-K/s   in 0.07s

 

2017-10-17 13:08:16(1.36 MB/s) - “index.html.1” 已保存 [99762]


原文:http://laoning.blog.51cto.com/7422740/1973279


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!