惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Exploit Database - CXSecurity.com
A
Arctic Wolf
K
Kaspersky official blog
T
Threat Research - Cisco Blogs
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy & Cybersecurity Law Blog
O
OpenAI News
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cisco Blogs
AWS News Blog
AWS News Blog
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
美团技术团队
T
Threatpost
S
Schneier on Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Cyber Attacks, Cyber Crime and Cyber Security
Last Week in AI
Last Week in AI
C
CERT Recently Published Vulnerability Notes
Blog — PlanetScale
Blog — PlanetScale
C
Cybersecurity and Infrastructure Security Agency CISA
F
Full Disclosure
博客园_首页
N
Netflix TechBlog - Medium
Security Latest
Security Latest
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Register - Security
The Register - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Recent Announcements
Recent Announcements
博客园 - Franky
P
Palo Alto Networks Blog
Project Zero
Project Zero
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
H
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Cisco Talos Blog
Cisco Talos Blog
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 【当耐特】
GbyAI
GbyAI

博客园 - kylindai

Spark installation for windows java cpu load - kylindai remove all .git files and directories use one command - kylindai Android adb not responsing putty ssh login linux mybatis 处理数组类型及使用Json格式保存数据 JsonTypeHandler and ArrayTypeHandler 一次PostgreSql数据迁移,使用nodejs来完成 nodejs 安装 postgresql module mongodb 安装为windows服务 memcached linux / win32 1.4.13 learning nodejs 2 - connect middleware learning nodejs 1 - stream.pipe javascript的变量、作用域和内存问题 javascript编程的最佳实践推荐 android download host jetty-distribution-7.6.x 部署 Quartz Cron 表达式 ImageMagick 批量处理图片脚本 常用 LINUX 命令
nodejs 实现 http proxy 透明转发
kylindai · 2014-02-26 · via 博客园 - kylindai

这两天需要安装一个Linux虚拟机,接下来要通过 yum 来安装需要的软件。

因单位的网络需要通过代理才能访问外网,公司代理服务器:proxy.xxxx.com,给yum增加了proxy设置:

# vi /etc/yum.conf

添加下面的内容:

proxy=http://user:password@proxy.xxxx.com:8080

发现linux无法访问代理服务器,Linux虚拟机只能访问宿主host所在的网段,添加了路由,网关等都没效果(知道方法的请回复下)

索性自己搭一个proxy,来做透明转发,用nodejs来写吧,用stream.pipe()透传就OK,关键是传递给proxy服务器的认证信息如何传过去。

var http = require('http');

var proxy = http.createServer(function(request, response) {
  
    var options = {
        host: 'proxy.xxxx.com', // 这里是代理服务器       
        port: 8080,             // 这里是代理服务器端口 
        path: request.url,       
        method: request.method,
        headers: {
// 如果代理服务器需要认证 'Proxy-Authentication': 'Base ' + new Buffer('user:password').toString('base64') // 替换为代理服务器用户名和密码 } }; var req = http.request(options, function(req, res) { res.pipe(response); // 这个pipe很喜欢
console.log(req.url);
}).end(); }).listen(8080);

这就写好了,启动 node proxy 后,用curl测试一下:

# curl -x localhost:8080 www.baidu.com

工作正常,虚拟机宿主:10.66.220.146,修改下 yum.conf

# vi yum.conf

proxy=http://10.66.220.146:8080/

我可以在Linux里面 yum install了,That's very good.