手把手教你从如何从公司内网访问外网(非翻墙)
Posted 如何在3年拿到50K
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了手把手教你从如何从公司内网访问外网(非翻墙)相关的知识,希望对你有一定的参考价值。
背景
不能上外网?是可忍孰不可忍。
根据公司安全要求,在办公网络是无法访问外网的,甚至打开百度都只能靠页面快照。作为一名程序员,不能百度是一件无法忍受的事情。幸好不是完全的网络隔离,而是屏蔽了几乎所有能上传文件的网站。如果你也遇到类似的情况,请参考下面文档,给你将如何突破这种限制。
友情提示:技术无罪,方便自己同时,不要故意违反公司规定,损害公司利益。
技术选型
- 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 务必所有都sucess
patching file src/http/ngx_http_core_module.c
patching file src/http/ngx_http_parse.c
patching file src/http/ngx_http_request.c
Hunk #1 succeeded at 959 (offset -9 lines).
Hunk #2 succeeded at 1565 (offset -8 lines).
patching file src/http/ngx_http_request.h
Hunk #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_module
make && 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更好用一些
以上是关于手把手教你从如何从公司内网访问外网(非翻墙)的主要内容,如果未能解决你的问题,请参考以下文章