我想使用 nginx 在 phusion guest 上执行一个简单的 node-http-proxy 示例。您可以在https://github.com/nodejitsu/node-http-proxy上找到此示例代码。
var http = require('http'),
httpProxy = require('http-proxy');
//
// Create your proxy server
//
httpProxy.createServer(9000, 'localhost').listen(8000);
//
// Create your target server
//
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
Run Code Online (Sandbox Code Playgroud)
如果我执行这段代码,我会收到以下错误。
App 28096 stderr: /usr/share/passenger/helper-scripts/node-loader.js:157
App 28096 stderr: throw new Error("http.Server.listen() was called more than once, which " +
App 28096 stderr: ^
App 28096 stderr: Error: …Run Code Online (Sandbox Code Playgroud) 我有一个 Java 应用程序正在尝试通过 http 代理访问 Web 服务。Java 应用程序是第三方应用程序,我们无法访问其源代码。
可以通过传递 Java 启动参数等来配置其启动。我想知道可以传递哪些 java 属性,以便应用程序可以使用登录用户的 NTLM 凭据来验证代理连接?
当我将 https.proxyHost 和 https.proxyPort (即 -Dhttps.proxyHost=abcd ... 传递给 jvm 命令行)时,我确实看到日志中存在差异。现在失败并显示以下消息。
[WrapperSimpleAppMain] [AuthChallengeProcessor] ntlm authentication scheme selected
INFO | jvm 5 | 2015/06/03 14:49:25 | 2015-06-03 14:49:25,380
INFO [WrapperSimpleAppMain] [HttpMethodDirector] No credentials available for NTLM <any realm>@proxy.ins.dell.com:80
INFO | jvm 5 | 2015/06/03 14:49:25 | Exiting due to fatal exception.
INFO | jvm 5 | 2015/06/03 14:49:25 | com.atlassian.bamboo.agent.bootstrap.RemoteAgentHttpException: HTTP status code 407 received in response …Run Code Online (Sandbox Code Playgroud) java bamboo http-proxy apache-httpcomponents apache-httpclient-4.x
我正在使用 proxy.web 转发客户端请求。当目标服务器启动时,我的代码将按预期工作。当目标服务器关闭时,ECONNREFUSED 错误将被捕获并打印到 console.log。我想将该错误发送回客户端,并尝试使用此处提供的示例。不幸的是,错误响应没有到达客户端(尝试了 chrome 和 firefox)。请找到下面的代码。为什么响应没有发送到客户端?
var proxyServer = http.createServer(function(req, res) {
if(req.path === 'forbidden') {
return res.end('nope');
}
var url_parts = url.parse(req.url);
var extname = path.extname(url_parts.pathname);
if (extname || url_parts.pathname.length <= 1){
proxy.web(req, res, {
target: 'http://localhost:'+config.fileServer.port
});
}
else{
proxy.web(req, res, {
target: config.recognitionServer.url
}, function(e) {
console.log(e.message);
if (!res.headersSent) {
res.writeHead(500, { 'content-type': 'application/json' });
}
res.end(JSON.stringify({ error: 'proxy_error',
reason: e.message
}));
});
}
}).listen(config.proxyServer.port, function () {
console.log('Proxy server is listening on port ' …Run Code Online (Sandbox Code Playgroud) 我有这个 REST API URL:
http://localhost:4000/api/v2/stocks/accounts/1162/tradings
Run Code Online (Sandbox Code Playgroud)
我希望它 proxy_pass 到 URL:
http://localhost:4001/api/v2/stocks/accounts/1162/tradings
Run Code Online (Sandbox Code Playgroud)
其中1162是URL参数,可以是其他值。
我有以下内容:
location ^~ /api/v2/stocks/accounts/([^/]+)/tradings {
proxy_pass http://localhost:4001/api/v2/stocks/accounts/$1/tradings;
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用(404 Not Found),我用谷歌搜索了类似的问题,但没有太多帮助:
像这个:获取参数 Nginx 和 proxy_pass 的路径或这个:trouble with location regex and redirection in nginx。
有什么办法可以使用 nginx 来实现我想要的吗?
预先感谢您的任何帮助。
添加:
我还添加了参数捕获:
location ~ /api/v2/stocks/accounts/([^/]+)/tradings/(.*) {
proxy_pass http://localhost:4001/api/v2/stocks/accounts/$1/tradings/$2$is_args$args;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 Express 4,并且正在使用中间件http-proxy-middleware(https://github.com/chimurai/http-proxy-middleware),并且遇到以下问题
通常,我可以在返回客户端之前执行以下操作来操作响应
app.get('/v1/users/:username', function(request, response, next) {
var username = request.params.username;
findUserByUsername(username, function(error, user) {
if (error) return next(error);
return response.render('user', user);
});
});
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用代理,我如何执行自定义逻辑,假设我想在响应客户端之前操作一些数据?有没有一个好的模式可以用这个中间件来做到这一点?
app.use('/api', proxy({target: 'http://www.example.org', changeOrigin: true}));
Run Code Online (Sandbox Code Playgroud)
这是我放在 github 中的问题的反向链接 - https://github.com/chimurai/http-proxy-middleware/issues/97
任何帮助,将不胜感激。
我刚刚购买了一个 VPS 并在其上安装了鱿鱼代理,一切都很好,代理可以工作,但不能在 youtube、instagram、facebook 等上使用。该怎么办?在squid.conf中要改变什么?
当我尝试安装 Burrow https://github.com/linkedin/Burrow#build-and-install时
go get github.com/linkedin/Burrow
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
package gopkg.in/gcfg.v1: unrecognized import path "gopkg.in/gcfg.v1"
(https fetch: Get https://gopkg.in/gcfg.v1?go-get=1: proxyconnect tcp: dial tcp :0: getsockopt: connection refused)
Run Code Online (Sandbox Code Playgroud)
我已经通过以下方式设置了代理:
export http_proxy=myproxy:port
export https_proxy=myproxy:port
Run Code Online (Sandbox Code Playgroud)
编辑:
go get -u gopkg.in/gcfg.v1
Run Code Online (Sandbox Code Playgroud)
也给出了同样的错误:
package gopkg.in/gcfg.v1: unrecognized import path "gopkg.in/gcfg.v1"
(https fetch: Get https://gopkg.in/gcfg.v1?go-get=1: proxyconnect tcp: dial tcp :0: getsockopt: connection refused)
Run Code Online (Sandbox Code Playgroud)
编辑1:
go get -v gopkg.in/gcfg.v1
Fetching https://gopkg.in/gcfg.v1?go-get=1
https fetch failed: Get https://gopkg.in/gcfg.v1?go-get=1: proxyconnect tcp: dial tcp :0: getsockopt: connection refused
package gopkg.in/gcfg.v1: unrecognized import path …Run Code Online (Sandbox Code Playgroud) 我的主机服务器需要代理才能与外界通信。它在 env 中定义为http_proxy=http://10.10.123.123:8080 https_proxy=http://10.10.123.123:8080. 我运行一个图像tensorflow/tensorflow,容器名为tf1.
在内部tf1(通过 exec 进入容器),我想使用 pip 安装一些包,例如 grpcio 和 tensorflow-serving-api,但因网络错误而失败。
如何在容器内使用主机的代理?我尝试过 exec with -eoption 但由于 docker 版本低而失败,所以我不知道它是否有效。
操作系统:CentOS 7.2,Docker:1.12.3
我试图了解 ProxySelector 类的工作原理。我当前的代码如下所示:
URI uri = new URI("http://google.com");
proxySelector.select(uri);
Run Code Online (Sandbox Code Playgroud)
据我了解,调用proxySelector.select(uri);此函数时应该返回相应 URI 的代理列表。但我不知道如何为每个 URI 设置代理。
我知道我可以使用该setDefault()方法设置默认代理,但据我了解,这将设置系统范围的代理,而不是特定URI.
我可能在这里遗漏了一些基本点,但如何为网址 A (例如http://google.com)设置一个代理并为网址 B (例如http://ebay.com)设置一个不同的代理,然后让系统每次连接到相应的url时都会自动选择正确的代理?
在http-proxy-middleware库中,文档指出您可以使用该target选项来指定要代理请求的位置。但是,它们还允许您使用该router选项来指定将用于在运行时从功能上解析目标的函数。
文档:https : //www.npmjs.com/package/http-proxy-middleware
我正在使用 TypeScript,如果我查看代理的声明文件,我可以看到:
您可以在此处看到router和target都可以为空。我的假设是,如果你使用一个,另一个可以省略,但你总是至少需要一个。
但是,如果我使用这样的router属性:
app.use("/pipe", proxy({
changeOrigin: true,
router: (req: IIncomingMessageWithCookies) => {
return "https://www.google.com";
}
}));
Run Code Online (Sandbox Code Playgroud)
并省略target,然后在运行时我收到此错误:
> node ./dist/app.js
C:\SkyKick\SkyKick.SEWR\src\node_modules\http-proxy-middleware\lib\config-factory.js:43
throw new Error(ERRORS.ERR_CONFIG_FACTORY_TARGET_MISSING)
^
Error: [HPM] Missing "target" option. Example: {target: "http://www.example.org"}
at Object.createConfig (C:\SkyKick\SkyKick.SEWR\src\node_modules\http-proxy-middleware\lib\config-factory.js:43:11)
at new HttpProxyMiddleware (C:\SkyKick\SkyKick.SEWR\src\node_modules\http-proxy-middleware\lib\index.js:17:30)
at module.exports (C:\SkyKick\SkyKick.SEWR\src\node_modules\http-proxy-middleware\index.js:4:10)
at Object.<anonymous> (C:\SkyKick\SkyKick.SEWR\src\dist\app.js:8:18)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load …Run Code Online (Sandbox Code Playgroud)