All Products
Search
Document Center

Elastic Compute Service:Configure multiple websites with Nginx

Last Updated:May 15, 2026

Host multiple websites on a single Linux ECS instance with Nginx to reduce costs and centralize management.

Prerequisites

An ECS instance with a public IP address is created and an LNMP stack is deployed. See Deploy an LNMP stack or (To be determined) Deploy an LNMP stack using Docker.

Note

This tutorial provides a one-click deployment solution for configuring multiple websites with Nginx. Run with one click

Create test websites

  1. Connect to the ECS instance on which the LNMP stack is deployed. See Connect to a Linux instance using Workbench.

  2. Navigate to the website root directory:

    cd /usr/share/nginx/html
  3. Create two test folders to store the project code for the test websites:

    sudo mkdir Testpage-1
    sudo mkdir Testpage-2
  4. Configure the Testpage-1 website.

    1. Navigate to the Testpage-1 folder:

      cd /usr/share/nginx/html/Testpage-1/
    2. Create and edit the index.html file:

      sudo vim index.html
    3. Press i to enter edit mode and add the following content:

      Test page 1

      Press Esc, enter :wq, and press Enter to save and exit.

  5. Configure the Testpage-2 website.

    1. Navigate to the Testpage-2 folder:

      cd /usr/share/nginx/html/Testpage-2/
    2. Create and edit the index.html file:

      sudo vim index.html
    3. Press i to enter edit mode and add the following content:

      Test page 2

      Press Esc, enter :wq, and press Enter to save and exit.

Configure Nginx

  1. View the nginx.conf configuration file:

    cat /etc/nginx/nginx.conf

    In the http{} module, check the include configuration.

    In this example, the configuration is shown in the following figure. include /etc/nginx/conf.d/*.conf; means Nginx loads site configurations from all .conf files in this path.nginx.conf

  2. Navigate to the /etc/nginx/conf.d directory:

    cd /etc/nginx/conf.d
  3. Create and configure the Nginx configuration file for the Testpage-1 website.

    1. Create and edit the configuration file:

      sudo vim Testpage1.conf
    2. Press i to enter edit mode and add the following content:

      Replace the server domain name and project path as indicated in the comments.

      server {
          listen       80;
          server_name  testpage1.com;    # This is a test domain name. Replace it with your actual server domain name.
      
          #charset koi8-r;
          access_log  /var/log/nginx/b.access.log  main;
      
          location / {
              root   /usr/share/nginx/html;    # This is the test website path. Replace it with your actual project code path.
              index  index.html index.htm;
          }
      
          #error_page  404              /404.html;
      
          error_page   500 502 503 504  /50x.html;
          location = /50x.html {
              root   /usr/share/nginx/html;
          }
      }

      Press Esc, enter :wq, and press Enter to save and exit.

  4. Create and configure the Nginx configuration file for the Testpage-2 website.

    1. Create and edit the configuration file:

      sudo vim Testpage2.conf
    2. Press i to enter edit mode and add the following content:

      Replace the server domain name and project path as indicated in the comments.

      server {
          listen       80;
          server_name  testpage2.com;    # This is a test domain name. Replace it with your actual server domain name.
      
          #charset koi8-r;
          access_log  /var/log/nginx/b.access.log  main;
      
          location / {
              root   /usr/share/nginx/html;    # This is the test website path. Replace it with your actual project code path.
              index  index.html index.htm;
          }
      
          #error_page  404              /404.html;
      
          error_page   500 502 503 504  /50x.html;
          location = /50x.html {
              root   /usr/share/nginx/html;
          }
      }

      Press Esc, enter :wq, and press Enter to save and exit.

  5. Restart the Nginx service:

    sudo systemctl restart nginx

Verify the results

On your local host, open a browser and access the two test websites.

  • Access http://<Public IP address of the ECS instance>/Testpage-1. The Testpage-1 website appears as shown in the following figure.

    image

  • Access http://<Public IP address of the ECS instance>/Testpage-2. The Testpage-2 website appears as shown in the following figure.

    image

The websites are now set up. In a production environment, ensure the project paths in the configuration files are correct.

Next steps

To make your website publicly accessible with a domain name, complete the following steps.

  1. Register a domain name.

  2. Complete the ICP filing.

    If your domain name points to a website hosted on an Alibaba Cloud server in the Chinese mainland, you must complete an ICP filing. See ICP filing process.

  3. Resolve the domain name.

    To point a domain name to the public IP address of an instance, see Add a website resolution record.

References

To deploy multiple websites on a Windows instance, see Use IIS to configure multiple websites.