Deepak Kamat
Deepak Kamat

Reputation: 1980

Running 2 Websites on same ECS Instance Alibaba Cloud

I am looking for a way to run two websites on top level domain on the same ECS instance. I am new to Alibaba Cloud and looking for best options to achieve this

Upvotes: 0

Views: 529

Answers (2)

Samsul Hadi 夏豪迪
Samsul Hadi 夏豪迪

Reputation: 13

It depends on your OS (windows/linux) and web server (apache/nginx) that you need. For my experiences were using the NGINX web server with Ubuntu web server, here are the steps:

  1. Point every dns (example1.com, example2.com, etc.) to your IP public ECS instance by mapping the A record using each DNS Manager. Here is the example if you're using alibaba dns manager.
  2. Make sure you are openning the ports that will be used for your web apps (generally 80 or 443) by adding the rule in attached security group for your ECS
  3. Install your apps (there are so many variations whether you are using PHP, Django, Nodejs, etc.)
  4. Configure the first web in Nginx, here is the simple example using django apps with port 80, the apps are already installed and bounded to the socket file:

sudo nano /etc/nginx/site-enabled/example1

upstream example1 {
    server unix:/run/uwsgi/exampple1.sock;
}
server {
    listen 80;
    server_name example1.com;
    charset     utf-8;
    client_max_body_size 75M;

    access_log /var/log/example1/example1.nginx.access.log;
    error_log /var/log/example1/example1.nginx.error.log;

    location /media  {
            alias /opt/apps/example1/files/media;
    }

    location /static {
            alias /opt/apps/example1/files/static-collected;
    }

    location / {
            uwsgi_pass example1;
            include uwsgi_params;
    }
}
  1. Configure the second web in Nginx, here is the simple example using PHP apps with port 80:

sudo nano /etc/nginx/site-enabled/example2

server {
    listen 80;
    server_name example2.com;
    charset     utf-8;
    client_max_body_size 75M;

    access_log /var/log/example2/example2.nginx.access.log;
    error_log /var/log/example2/example2.nginx.error.log;

    root /opt/apps/example2; # YOUR LOCATION WEB RESOURCES
    index index.php index.html index.htm index.nginx-debian.html;

    location / {
       try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
       include snippets/fastcgi-php.conf;
       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
       deny all;
    }
}

Upvotes: 0

Sai Sarath C P
Sai Sarath C P

Reputation: 1622

There are different ways you can do that,

  1. Subfolders ("example.com/web1", "example.com/web2", "example.com/web3")
  2. Port-based Virtual Hosting ("example.com:80", "example.com:8080", "example.com:8181")
  3. Subdomains ("web1.example.com", "web2.example.com", "web3.example.com")
  4. Name-based Virtual Hosting ("web1.com", "web2.com", "web3.com")

Before you do this, you need to map your top-level domains DNS 'A' records to the ECS instance public Internet IP. Now you have two approaches to do this.

One way is to you create only one single site which has the content of both and serve the pages you want to by recognizing the host using the HTTP headers in the request, but this makes your information exposed to the user. This approach is not secure.

The other and better way would be to containerize the websites and use the reverse proxy to map the website.

More detailed steps mentioned here:

https://www.alibabacloud.com/blog/hosting-multiple-websites-on-a-single-alibaba-cloud-ecs-server-the-devops-way_593711

Thanks

Upvotes: 0

Related Questions