javascript - Create proxy according URL path -


i need create proxy according url coming browser, since new topic im not sure how test it...:( need way test , see working use following code blog

http://blog.nodejitsu.com/node-http-proxy-1dot0/

var httpproxy = require('http-proxy')  var proxy = httpproxy.createproxy();  var options = {     'foo.com': 'http://website.com:8001',     'bar.com': 'http://website2.com:8002' }  require('http').createserver(function(req, res) {     proxy.web(req, res, {         target: options[req.headers.host]     }); }).listen(8000); 

what need when put in browser localhost:8000 route(proxy) new server diffrent path described in options.

if want user typing foo.com go http://website.com:8001 need setup virtual host foo.com example nginx.

nginx host virtual host foo.com , bar.com, "proxy pass" node.js app.

when user go foo.com nginx server pass request node app proxy request relative url setup in options.

if need can give nginx config needed.

nginx virtual host config:

server {     listen 80;      server_name foo.com bar.com;      location / {         proxy_pass http://127.0.0.1:8000;         proxy_http_version 1.1;         proxy_set_header upgrade $http_upgrade;         proxy_set_header connection 'upgrade';         proxy_set_header host $host;         proxy_cache_bypass $http_upgrade;     } } 

of course need point foo.com , bar.com dns nginx/node server. node app good. don't need more. start nginx , node , done.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -