Skip to main content

Part 1: Build websites on a single domain

The following tutorial demonstrates how to set up two website services: create VCS instances, host websites using Nginx, and open port 80 on the instance.

Step 1. Create a VCS instance

  • Go to the VCS Instance Management page, and create a VCS instance named virtualhost.

info
  • For detailed steps of creating VCS instance, see VCS for more information.
  • In this tutorial, we select Ubuntu 20.04 image and use default values to create instances (this tutorial is not applicable to Ubuntu 16.04). Please enable associating public IPs for website maintenance.

Step 2. Host websites using Nginx

Connect to the instance using the public IP, and enter the following 3 commands to install Nginx:

info
  • For detailed steps of connecting your instance, see Connect to a VCS instance for more information.
  • We use Nginx to set up websites in this tutorial, you may install different tools according to your needs.
sudo su
apt update
apt install -y nginx

  • Create two root folders for different websites.
cd /var/www/html
mkdir service1
mkdir service2

  • Execute the following command to edit the content on the website.
vim /var/www/html/index.nginx-debian.html
  • Press i key to enter Edit mode, and replace the strings between <h1> and </h1> to Hi, this is VCS Service 1!.

  • Press Esc key to exit Edit mode, and enter:wq! then pressing Enter key to save the file and exit.

  • Enter the following command to move the web file under service1 folder > Enter the service1 folder > Copy the web file to service2 folder > Edit the service2 web file.
mv index.nginx-debian.html service1
cd service1
cp index.nginx-debian.html /var/www/html/service2/
vim /var/www/html/service2/index.nginx-debian.html
  • Press i key to enter Edit mode, and replace the strings between <h1> and </h1> to Hi, this is VCS Service 2!.

  • Press Esc key to exit Edit mode, and enter:wq! then pressing Enter key to save the file and exit.

  • Modify the Nginx config file and append the folder name (service1) to the root path (root /var/www/html).
vim /etc/nginx/sites-available/default

  • Press Esc key to exit Edit mode, and enter:wq! then pressing Enter key to save the file and exit.

  • Restart Nginx
systemctl restart nginx

Step 3. Set up the instance's Security Group and open the port 80

Open the port 80 by setting the Security Group to make the websites accessible.

  • Click the Network & Security > Security Group on the left panel

  • Select virtualhost instance.

  • Click to enter Security Group Rules Management page and click +CREATE.

  • Basic Settings
    1. Direction: Select Ingress (Allow users from external to access the websites.)
    2. Port Range(Min), Port Range(Max): Setting as 80 (only port 80 is opened to provide HTTP website service, the application will automatically direct the connections to port 443 to provide HTTPS web service).
    3. Protocol: Select TCP.
    4. CIDR: Insert CIDR. Here we take 0.0.0.0/0 as an example. Set a specific network segment range when needed.

Step 4. Check if port 80 is open

  • Copy the Public IP address of the VCS instance

  • Enter the Public IP address on the browser address bar to check the port 80 is open.