nginx 正向代理实现上网

公司使用虚拟机(windows) 限制网络,但是 连接的 linux服务器是可以访问网络,试试可以通过在linux服务器上 安装nginx ,通过正向代理,实现上网呢?

最后的结果:可以访问http/https连接,虚拟机上可以通过一台连接外网的linux 实现,虚拟机上的windows主机上网功能!

 

 

过程:

 

1、下载nginx源码包,https模块

 

wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar -xf nginx-1.14.2.tar.gz
cd nginx-1.14.2/
 
yum install -y git
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git

 

2、打补丁,编译,编译安装

yum install -y patch pcre pcre-devel
 

patch -p1 < ngx_http_proxy_connect_module/patch/proxy_connect_1014.patch

 
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=ngx_http_proxy_connect_module
 
make && make install
 
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx

 

3、正向代理配置

vim /usr/local/nginx/conf/nginx.conf
http {
.....
include /usr/local/nginx/conf/conf.d/*.conf;
.....
 
}
 
mkdir /usr/local/nginx/conf/conf.d
cd /usr/local/nginx/conf/conf.d
 
[root@localhost conf.d]# vim forward.conf
 server {
     listen                         8099;
 
     # dns resolver used by forward proxying #代理服务器的DNS,linux查看命令为cat /etc/resolv.conf
     resolver                       10.1.2.1;
 
     # forward proxy for CONNECT request
     proxy_connect;
     proxy_connect_allow            443 563;
     proxy_connect_connect_timeout  10s;
     proxy_connect_read_timeout     10s;
     proxy_connect_send_timeout     10s;
 
     # forward proxy for non-CONNECT request
     location / {
         proxy_pass http://$host;
         proxy_set_header Host $host;
     }
 }

 

 

4、启动正向代理服务

/usr/local/nginx/sbin

./nginx #启动

 

5.windows浏览器配置代理地址指向这个正向代理服务器地址,以谷歌浏览器为例

 

 

参考来源:nginx正向代理http, https亲测可用

 

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

1.http代理协议的配置(可以不用看)

  您还在为您公司的网络限制摸不了鱼在苦恼难过吗?难受的话请您看完:解决公司内网限制 Nginx反向代理访问外网

 

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-threads


 

 


参考:

nginx正向代理配置(客户端是linux)

Nginx → make: *** No rule to make target `build‘, needed by `default‘. Stop.

nginx正向代理http, https亲测可用 

nginx 正向代理重新编译 ngx_http_proxy_connect_module

Nginx之ngx_http_proxy_connect_module模块

打补丁 安装的 改为:

patch -p1 < ngx_http_proxy_connect_module/patch/proxy_connect_1014.patch

  

#代理服务器的DNS,linux查看命令为cat /etc/resolv.conf

posted @ 2022-07-25 11:13  BBS_自律  阅读(2018)  评论(0编辑  收藏  举报