首页 > 编程知识 正文

手把手教你从如何从公司内网访问外网(非翻墙)

时间:2023-05-05 09:51:17 阅读:274099 作者:4463

背景

不能上外网?是可忍孰不可忍。

根据公司安全要求,在办公网络是无法访问外网的,甚至打开百度都只能靠页面快照。作为一名程序员,不能百度是一件无法忍受的事情。幸好不是完全的网络隔离,而是屏蔽了几乎所有能上传文件的网站。如果你也遇到类似的情况,请参考下面文档,给你将如何突破这种限制。

友情提示:技术无罪,方便自己同时,不要故意违反公司规定,损害公司利益。

技术选型 nginx,正向代理老牌squid,请参考我另外一篇博客。 说明

因为 Nginx 不支持 CONNECT,所以无法正向代理 Https 网站(网上银行,Gmail)。
如果访问 Https 网站,比如:https://www.google.com,Nginx access.log 日志如下:

"CONNECT www.google.com:443 HTTP/1.1" 400

所以nginx需要安装http_proxy_connect插件来实现https的代理,注意版本关联关系

https://github.com/chobits/ngx_http_proxy_connect_module/blob/master/README.md

资源准备 ## ngx_http_proxy_connect_git clone https://github.com/chobits/ngx_http_proxy_connect_module.git## nginx-1.9.2 wget http://nginx.org/download/nginx-1.9.2.tar.gz 安装nginx插件

把http_proxy_connect插件安装到nginx中

[root@server1 nginx-1.9.2]# patch -p1 < ../ngx_http_proxy_connect_module/patch/proxy_connect.patch## log 务必所有都sucesspatching file src/http/ngx_http_core_module.cpatching file src/http/ngx_http_parse.cpatching file src/http/ngx_http_request.cHunk #1 succeeded at 959 (offset -9 lines).Hunk #2 succeeded at 1565 (offset -8 lines).patching file src/http/ngx_http_request.hHunk #1 succeeded at 41 (offset -1 lines).Hunk #2 succeeded at 402 (offset -2 lines).patching file src/http/ngx_http_variables.c

安装nginx

./configure --add-module=../ngx_http_proxy_connect_modulemake && make install 修改配置

/usr/local/nginx/conf/nginx.conf

server { listen 1080; # dns resolver used by forward proxying resolver 8.8.8.8; # forward proxy for CONNECT request proxy_connect; proxy_connect_allow 443 563; #许可https和nntps协议通过 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; } }

验证配置文件

nginx -t

如果报错说明proxy_connect模块没有安装好

启动nginx并验证结果 # 启动nginx# 验证代理配置,端口号和listen保持一致curl https://www.baidu.com/ -v -x 127.0.0.1:1080 卸载

注:如果报错需要重装时考虑

rm -f -R /usr/local/nginx && rm -f /usr/local/sbin/nginx 设置浏览器代理

注意开启防火墙限制


可以打开百度搜索ip地址,如果外网地址就是代理服务器地址说明配置成功

后记

上述方法可以给工作带来不少便利,如果http不好用可以参考squid的博客。个人觉得squid更好用一些

快三大小单双位技巧准确率99 # dns resolver used by forward proxying resolver 8.8.8.8; # forward proxy for CONNECT request proxy_connect; proxy_connect_allow 443 563; #许可https和nntps协议通过 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; } }

验证配置文件

nginx -t

如果报错说明proxy_connect模块没有安装好

启动nginx并验证结果 # 启动nginx# 验证代理配置,端口号和listen保持一致curl https://www.baidu.com/ -v -x 127.0.0.1:1080 卸载

注:如果报错需要重装时考虑

rm -f -R /usr/local/nginx && rm -f /usr/local/sbin/nginx 设置浏览器代理

注意开启防火墙限制


可以打开百度搜索ip地址,如果外网地址就是代理服务器地址说明配置成功

后记

上述方法可以给工作带来不少便利,如果http不好用可以参考squid的博客。个人觉得squid更好用一些

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。