I have a couple of small production sites and a bunch of fun hobbyist/experimental apps and such. I'd like to run all of them on one EC2 instance.
我有几个小的制作网站,还有一堆有趣的爱好者/实验应用等等。我想在一个EC2实例上运行它们。
Can I install node.js, npm, express and couchdb once, and then run each app on a different port, and adjust the dns settings at my domain registry to point to the appropriate place?
我可以安装节点。js, npm, express和couchdb一次,然后在不同的端口上运行每个应用,调整我的域名注册中心的dns设置,指向合适的位置?
Update: Thanks Mike! For anyone else who's looking for multiple IP addresses on EC2: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html
更新:谢谢你迈克!对于在EC2上寻找多个IP地址的人来说:http://docs.aws.amazon.com/awsec2/latest/userguide/usinginstance -addressing.html。
2 个解决方案
#1
31
There are multiple ways to go about it.
有多种方法来实现它。
Different Ports
You could run each Node.js process on a different port and simply open the ports to the world. However, your URLs would need a port on the end of the hostname for each project. yoururl.com:8080/
would technically work, but probably not what you're looking for.
可以运行每个节点。js处理不同的端口,并简单地向世界开放端口。但是,您的url需要每个项目主机名末尾的一个端口。你的网站:8080/理论上可以,但可能不是你想要的。
Multiple IP Addresses
You could use multiple IP addresses on one EC2 instance, however, they come with an additional cost of about $3.65 a month each. So if you have 10 different domains you want to host on once instance then that's over $30 a month extra in hosting fees.
您可以在一个EC2实例上使用多个IP地址,但是每个月的额外开销大约是3.65美元。如果你有10个不同的域名你想在一个实例上托管,那么每月的托管费用就超过30美元。
On the flip side, any domain using SSL needs it's own IP address.
另一方面,任何使用SSL的域都需要自己的IP地址。
Also, there are limits to the number of IP addresses you can assign to an instance and the smaller the instance, the less IP addresses you get.
另外,你可以分配给一个实例的IP地址的数量是有限制的,实例越小,你得到的IP地址就越少。
The number of IP addresses that you can assign varies by instance type. Small instances can accommodate up to 8 IP addresses (across 2 elastic network interfaces) whereas High-Memory Quadruple Extra Large and Cluster Computer Eight Extra Large instances can be assigned up to 240 IP addresses (across 8 elastic network interfaces). For more information about IP address and elastic network interface limits, go to Instance Families and Types in the Amazon EC2 User Guide.
您可以分配的IP地址的数量因实例类型而异。小实例最多可容纳8个IP地址(跨越2个弹性网络接口),而高内存四倍的超大和集群计算机则可分配8个超大实例最多可分配240个IP地址(跨越8个弹性网络接口)。有关IP地址和弹性网络接口限制的更多信息,请参阅Amazon EC2用户指南中的实例族和类型。
Express Vhosts
Express comes with virtual host functionality. You can run multiple domains under one Node.js/Express server and setup routes based on domain name. vhost
under Express enables this.
Express附带了虚拟主机功能。您可以在一个节点下运行多个域。js/Express服务器和基于域名的设置路由。Express下的vhost支持这一点。
Reverse Proxy
You can setup Nginx in front of multiple application servers. This has the most flexibility. You can have one Node.js process per domain which allows you to do updates and restarts on one domain at a time. It also allows you to host applications servers such as Apache/PHP under the same EC2 instance along side your Node.js process.
您可以在多个应用服务器前设置Nginx。这是最灵活的。可以有一个节点。js处理每个域,允许您每次更新和重新启动一个域。它还允许您在节点旁边的同一个EC2实例下托管应用程序服务器,比如Apache/PHP。js的过程。
With Nginx acting as a reverse proxy you could also host different application servers under the same domain, but serving different paths.
使用Nginx作为反向代理,您还可以在相同的域中托管不同的应用服务器,但服务于不同的路径。
For instance, Node.js could serve the main root path of a domain but you could setup the /blog/
path to go to a Apache/PHP/Wordpress setup on the same EC2 instance.
例如,节点。js可以服务于域的主根路径,但是您可以在同一个EC2实例上设置/blog/路径到Apache/PHP/Wordpress设置。
#2
0
Already answered @ https://*.com/a/50528580/3477353 but mentioning it again.
已回复@ https://*.com/a/50528580/3477353,但再次提及。
Adding to the @Daniel answer, I would like to mention the configuration of my nginx for those who are looking for the exact syntax in implementing it.
除了@Daniel的答案之外,我还想介绍一下nginx的配置,以供那些正在寻找实现它的确切语法的人使用。
server {
listen 80;
server_name mysite.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:3000;
}
}
server {
listen 80;
server_name api.mysite.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:4500;
}
}
Just create two server objects with unique server name and the port address.
只需创建两个具有唯一服务器名和端口地址的服务器对象。
Mind proxy_pass in each object.
在每个对象中使用proxy_pass。
Thank you.
谢谢你!
#1
31
There are multiple ways to go about it.
有多种方法来实现它。
Different Ports
You could run each Node.js process on a different port and simply open the ports to the world. However, your URLs would need a port on the end of the hostname for each project. yoururl.com:8080/
would technically work, but probably not what you're looking for.
可以运行每个节点。js处理不同的端口,并简单地向世界开放端口。但是,您的url需要每个项目主机名末尾的一个端口。你的网站:8080/理论上可以,但可能不是你想要的。
Multiple IP Addresses
You could use multiple IP addresses on one EC2 instance, however, they come with an additional cost of about $3.65 a month each. So if you have 10 different domains you want to host on once instance then that's over $30 a month extra in hosting fees.
您可以在一个EC2实例上使用多个IP地址,但是每个月的额外开销大约是3.65美元。如果你有10个不同的域名你想在一个实例上托管,那么每月的托管费用就超过30美元。
On the flip side, any domain using SSL needs it's own IP address.
另一方面,任何使用SSL的域都需要自己的IP地址。
Also, there are limits to the number of IP addresses you can assign to an instance and the smaller the instance, the less IP addresses you get.
另外,你可以分配给一个实例的IP地址的数量是有限制的,实例越小,你得到的IP地址就越少。
The number of IP addresses that you can assign varies by instance type. Small instances can accommodate up to 8 IP addresses (across 2 elastic network interfaces) whereas High-Memory Quadruple Extra Large and Cluster Computer Eight Extra Large instances can be assigned up to 240 IP addresses (across 8 elastic network interfaces). For more information about IP address and elastic network interface limits, go to Instance Families and Types in the Amazon EC2 User Guide.
您可以分配的IP地址的数量因实例类型而异。小实例最多可容纳8个IP地址(跨越2个弹性网络接口),而高内存四倍的超大和集群计算机则可分配8个超大实例最多可分配240个IP地址(跨越8个弹性网络接口)。有关IP地址和弹性网络接口限制的更多信息,请参阅Amazon EC2用户指南中的实例族和类型。
Express Vhosts
Express comes with virtual host functionality. You can run multiple domains under one Node.js/Express server and setup routes based on domain name. vhost
under Express enables this.
Express附带了虚拟主机功能。您可以在一个节点下运行多个域。js/Express服务器和基于域名的设置路由。Express下的vhost支持这一点。
Reverse Proxy
You can setup Nginx in front of multiple application servers. This has the most flexibility. You can have one Node.js process per domain which allows you to do updates and restarts on one domain at a time. It also allows you to host applications servers such as Apache/PHP under the same EC2 instance along side your Node.js process.
您可以在多个应用服务器前设置Nginx。这是最灵活的。可以有一个节点。js处理每个域,允许您每次更新和重新启动一个域。它还允许您在节点旁边的同一个EC2实例下托管应用程序服务器,比如Apache/PHP。js的过程。
With Nginx acting as a reverse proxy you could also host different application servers under the same domain, but serving different paths.
使用Nginx作为反向代理,您还可以在相同的域中托管不同的应用服务器,但服务于不同的路径。
For instance, Node.js could serve the main root path of a domain but you could setup the /blog/
path to go to a Apache/PHP/Wordpress setup on the same EC2 instance.
例如,节点。js可以服务于域的主根路径,但是您可以在同一个EC2实例上设置/blog/路径到Apache/PHP/Wordpress设置。
#2
0
Already answered @ https://*.com/a/50528580/3477353 but mentioning it again.
已回复@ https://*.com/a/50528580/3477353,但再次提及。
Adding to the @Daniel answer, I would like to mention the configuration of my nginx for those who are looking for the exact syntax in implementing it.
除了@Daniel的答案之外,我还想介绍一下nginx的配置,以供那些正在寻找实现它的确切语法的人使用。
server {
listen 80;
server_name mysite.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:3000;
}
}
server {
listen 80;
server_name api.mysite.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:4500;
}
}
Just create two server objects with unique server name and the port address.
只需创建两个具有唯一服务器名和端口地址的服务器对象。
Mind proxy_pass in each object.
在每个对象中使用proxy_pass。
Thank you.
谢谢你!