简体   繁体   English

如何使用节点js设置代理服务器?

[英]How setup a proxy server using node js ?

i setup a proxy using node js my script is like this 我使用节点js设置代理我的脚本是这样的

var http = require('http'),
 httpProxy = require('http-proxy');
var options = {
  pathnameOnly: true,
  router: {
    '/wamp_application/': '127.0.0.1:80/',
    '/node_application': '127.0.0.1:1331',

  }
};


var proxyServer = httpProxy.createServer(options);
proxyServer.listen(8888);

now its working like this when i access 127.0.0.1:8888/wamp_application, i get 127.0.0.1:80 But i want like this 现在它的工作方式是这样的,当我访问127.0.0.1:8888/wamp_application时,我得到127.0.0.1:80但我想这样

127.0.0.1:8888/wamp_application/app1 -> 127.0.0.1:80/app1 127.0.0.1:8888/wamp_application/app2 -> 127.0.0.1:80/app2 127.0.0.1:8888/wamp_application/app3 -> 127.0.0.1:80/app3 and so on 127.0.0.1:8888/wamp_application/app1 - > 127.0.0.1:80/app1 127.0.0.1:8888/wamp_application/app2 - > 127.0.0.1:80/app2 127.0.0.1:8888/wamp_application/app3 - > 127.0.0.1 :80 / app3等等

i tried like this 我试过这样的

  router: {
        '/wamp_application/*': '127.0.0.1:80/*',
        '/node_application/*': '127.0.0.1:1331/*',
       };

it is not working. 它不起作用。 actually i want both php and node application access from same port. 实际上我想从同一个端口访问php和节点应用程序。 How can i do this ? 我怎样才能做到这一点 ?

If you just want to forward to ports other than 80 (a reverse proxy), nginX is a better choice. 如果您只想转发到80以外的端口(反向代理),nginX是更好的选择。 Use nginx.conf to bind your applications. 使用nginx.conf绑定您的应用程序。

See: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass 请参阅: http//nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM