-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReverseProxy to another ReverseProxy server #837
Comments
This has worked for me previously var http = require('http'),
httpProxy = require('http-proxy');
var url = args.url || process.env.PROXY_HOST || 'http://my.proxyed.domain';
var host = args.host || 'localhost';
var proxy = httpProxy.createProxyServer({
target: url,
xfwd: false,
hostRewrite: host,
autoRewrite: true,
headers: {
Host: url.substring(url.indexOf('//') +2),
Origin: url
}
});
http.createServer(function(req, res) {
var newReferer = req.headers.referer ? req.headers.referer.replace(new RegExp("http://"+host), url) : undefined;
proxy.web(req, res, {
Referer: newReferer
});
}).listen(80); |
Real sorry for not posting a response before, and thanks for your help! I've been dealing with all sorts of craziness this past couple of weeks in other areas of my API, will try your solution today and report back. Cheers! |
@alfonso-presa worked like a charm, thanks so much for your help! FYI, I removed the args.url and args.host, nonetheless, works perfectly. Closing! |
I'm glad it helped :-). |
The situation
Hi everyone, I have an app running on heroku and I made the HUGE mistake of hardcoding the heroku URL to the app. Now I'm migrating my API to another server with another URL.
What I'd like to do
Since I can't be sure that all of my users WILL actually update their up when I roll out the update, I'd like to use
node-http-proxy
to do a reverse proxy so all traffic goes to my new server.What I've got so far
I've got to the point where I can actually redirect traffic to the new server, but that server is in a cluster with a bunch of other apps hosted in it, and the URL it resolves to, has a Varnish VirtualHost which uses the URL to resolve to my hosted API. So I'm getting an
Error 503 Service Unavailable
because the URL that the Varnish Server is getting (presumably) is the one from heroku (or localhost on my testing machine) which doesn't resolve to any valid existing VirtualHost inside Varnish.This is what I'm using.
IMO what I need is a way to preserve the host URL, but not sure if there's a way to do that with node-http-proxy.
Thanks!
The text was updated successfully, but these errors were encountered: