如何在一个VPS上托管具有3个不同域的3个节点应用程序? [英] How to host 3 node apps with 3 different domains on one VPS?

查看:137
本文介绍了如何在一个VPS上托管具有3个不同域的3个节点应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在一个Digital Ocean Droplet的不同域上设置多个Node应用程序.我遵循了

I'm stuck trying to setup up several Node apps on different domains on one Digital Ocean droplet. I followed the Host Multiple Node.js Applications On a Single VPS with nginx, forever, and crontab article exactly.

我所有的域都正确指向并设置了一个记录.

I have the domains all pointed correctly and A records set.

除了默认的express 3000,我似乎无法让应用程序(永远)在任何其他端口上运行.

I can't seem to get apps to run (with forever) on any other port besides the default express 3000.

我按要求更改了Nginx设置:

I changed the Nginx settings like it asked:

我取消注释server_names_hash_bucket_size 64; (就像它说的那样)

I uncommented the server_names_hash_bucket_size 64; (like it says)

我为应用创建了/etc/nginx/conf.d/example.com.conf文件(它们是不同的域.我在端口3000上放置了1个,在端口4000上放置了另一个).

I created /etc/nginx/conf.d/example.com.conf files for the apps (they are different domains. I put 1 on port 3000 and the other on 4000).

示例:

server {
listen 80;

server_name your-domain.com;

location / {
    proxy_pass http://localhost:{YOUR_PORT};
    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;
}

}

我不明白Nginx何时运行该应用程序以及何时永远运行该应用程序之间的区别? "npm start"在哪里起作用?同时有多少台潜在的服务器在工作?

I don't understand the difference between when Nginx is running the app and when forever is? Where does "npm start" come into play? How many potential servers are working at the same time?

我似乎无法一次运行多个应用程序.我可以弄清楚如何正确地将Node应用程序文件夹分配给端口,并使其永久永久保存.

I can't seem to get more than 1 app running at once. I can figure out how to properly assign a Node app folder to a port and keep it alive forever with forever.

推荐答案

查看您要做的是: 假设您有3个节点实例在3000,5000,7000上运行. 现在,您必须将3个子域指向相同的ip,例如,如果您有一个example.com域,则ex1,ex2,ex3这三个将指向相同的ip. 现在在/etc/nginx/sites-enabled/中创建3个单独的文件 假设ex1.example.com,ex2.example.com,ex3.example.com 现在,将这些文件中的服务器块配置为指向相应的节点应用程序并重新启动nginx. 现在,您在同一服务器上具有三个具有三个不同访问链接的节点应用程序.

See what you have to do is: Lets say you have 3 node instances running on 3000,5000,7000. Now you have to point 3 sub domains to same ip lets say ig you have a domain example.com then ex1,ex2,ex3 these three will point to same ip. Now create 3 seperate files in /etc/nginx/sites-enabled/ lets say ex1.example.com, ex2.example.com, ex3.example.com now configure the server blocks in these files to oint to respective node application and restart nginx. Now you have three node applications on same server with three different access links..

这篇关于如何在一个VPS上托管具有3个不同域的3个节点应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆