0

I am using the nodejitsu node-http-proxy module to implement a forward proxy. Here is my simplified code:

var httpApp   = require('express')(),
    http      = require('http'),
    httpProxy     = require('http-proxy');

httpServer = http.createServer(httpApp);
proxy = httpProxy.createProxyServer({xfwd:true,ws:true});

httpApp.use(function(req,res) {
 proxy.web(req,res, {xfwd: true, agent:http.globalAgent, 
       ws:true, target:req.originalUrl }, function(err){console.log(err);});
});
httpServer.listen(5000);

This very code worked for a couple of test sites but I knew that it was, like they say, too good to be true. When I tried some more URLs, it failed. I would get display as if I have poor band-width or an image or two would be missing from the display.

For simplicity, I have not included the code for ws, or https. In fact, I commented out that code to see if this works first. I have a reverse proxy working fine using this same proxy module. I noticed that all the examples in the documentation have hard-wired target URLs as used for reverse proxies.

Test cases: For example, cnbc.com works fine but when I click on a link, it returns a 404 not found.

I am testing on Firefox with proxy environment variables set in /etc/environment. That seems OK because it does go to the right proxy server on the right port. I try the same URLs on the same machine under chrome without the proxy option set and these URLs display just fine.

Question: WHat issues am I not addressing in my forward proxy code?

Sunny
  • 9,245
  • 10
  • 49
  • 79
  • 1
    You probably need to add `changeOrigin: true` to the options passed to `proxy.web()`. You may also need to add `hostRewrite` and `protocolRewrite` to make redirects work. – keithmo Dec 27 '15 at 06:56
  • @keithmo I will give it a try. Thanks – Sunny Dec 27 '15 at 21:02
  • @keithmo Sorry for the delay. I just got back to this issue. I tried but these options do not resolve my issues. Frankly, I do not fully understand these options. The node-http-proxy site gives a one-liner description only for each of the options and they are not all boolean either. Can you direct me to some source of additional info on these options. Could not find any though I understand the basic concepts there. – Sunny Jan 07 '16 at 18:18

0 Answers0