微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 如何安装多个域的多个nodejs应用程序?

在这个时候读的比以往任何时候都多,这将是我的第一个网页,所以我决定在nodejs上安装.我快速制作应用程序,并在localhost:9000中测试

所以我想在VPS上运行更多的应用程序,我搜索信息,我有两个选择

首先使用Nginx代理应用程序…

upstream example1.com {
    server 127.0.0.1:3000;
}

server {
listen   80;
server_name  www.example1.com;
rewrite ^/(.*) http://example1.com/$1 permanent;
}

# the Nginx server instance
server {
    listen 80;
    server_name example1.com;
    access_log /var/log/Nginx/example1.com/access.log;

    # pass the request to the node.js server with the correct headers and much more can be added, see Nginx config options
    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-Nginx-Proxy true;

      proxy_pass http://example1.com;
      proxy_redirect off;
    }
 }

我不明白这个配置文件因为我从不使用Nginx所以我搜索第二个选项

使用来自expressjs的vhost()

express()
.use(express.vhost('m.mysite.com', require('/path/to/m').app))
.use(express.vhost('sync.mysite.com', require('/path/to/sync').app))
.listen(80)

即时通讯使用expressjs,我了解如何配置,但有一些问题是最好的选择,因为使用快递()我有一个应用程序管理多个应用程序,所以我认为这不是一个好的做法和浪费资源.

this后,大卫埃利斯说

如果您不需要使用WebSockets(或任何HTTP 1.1功能),则可以使用Nginx作为代理.

优点是Nginx可以处理的总负载与Node相比更高(基本上静态编译并专门用于此类事情),但是您无法流式传输任何数据(一次发送较小的块).

对于较小的站点,或者如果您不确定将来需要哪些功能,最好坚持使用node-http-proxy,如果您可以证明代理是您服务器上的瓶颈,则只能切换到Nginx.幸运的是,如果你以后确实需要,Nginx并不难设置.

this发布后我读了一个例子来配置xginx与许多应用程序,但我不明白如何使用它为我

upstream example1.com {
    server 127.0.0.1:3000;
}

server {
listen   80;
server_name  www.example1.com;
rewrite ^/(.*) http://example1.com/$1 permanent;
}

# the Nginx server instance
server {
    listen 80;
    server_name example1.com;
    access_log /var/log/Nginx/example1.com/access.log;

    # pass the request to the node.js server with the correct headers and much more can be added, see Nginx config options
    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-Nginx-Proxy true;

      proxy_pass http://example1.com;
      proxy_redirect off;
    }
 }

upstream example2.com {
    server 127.0.0.1:1111;
}

server {
listen   80;
server_name  www.example2.com;
rewrite ^/(.*) http://example2.com/$1 permanent;
}

# the Nginx server instance
server {
    listen 80;
    server_name example2.com;
    access_log /var/log/Nginx/example2.com/access.log;

    # pass the request to the node.js server with the correct headers and much more can be added, see Nginx config options
    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-Nginx-Proxy true;

      proxy_pass http://example2.com;
      proxy_redirect off;
    }
 }

所以问题是最好的选择,使用Nginx或使用vhost ???

如果我必须使用Nginx,有任何教程如何配置Nginx以服务节点js上的许多应用程序???

tnx全部

解决方法:

您的Nginx配置示例似乎是您正在寻找的.您应该在/ etc / Nginx / sites-available下创建配置文件,然后为要启用/ etc / Nginx / sites-enabled的人创建符号链接

也许这会帮助你 – http://blog.dealspotapp.com/post/40184153657/node-js-production-deployment-with-nginx-varnish

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐