How to run more than one app on one instance of EC2

后端 未结 2 1079
陌清茗
陌清茗 2021-01-30 18:46

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.

Can I install node.js

相关标签:
2条回答
  • 2021-01-30 19:02

    Already answered @ https://stackoverflow.com/a/50528580/3477353 but mentioning it again.

    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.

    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.

    Thank you.

    0 讨论(0)
  • 2021-01-30 19:22

    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.

    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.

    On the flip side, any domain using SSL needs it's own IP address.

    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.

    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.

    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.

    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.

    With Nginx acting as a reverse proxy you could also host different application servers under the same domain, but serving different paths.

    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.

    0 讨论(0)
提交回复
热议问题