Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI Studio
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex Application Load Balancer
  • Getting started
    • All tutorials
    • Setting up virtual hosting
    • Creating an L7 load balancer with a Smart Web Security profile through an Application Load Balancer ingress controller
    • Integrating an L7 load balancer with CDN and Object Storage
    • Blue-green and canary deployment of service versions
    • Writing load balancer logs to PostgreSQL
    • Deploying and load testing a scalable gRPC service in Yandex Managed Service for Kubernetes
    • Setting up the Gateway API in Yandex Managed Service for Kubernetes
    • Configuring an L7 Application Load Balancer via an ingress controller
    • Configuring L7 Application Load Balancer logging via an ingress controller
    • Performing health checks on Managed Service for Kubernetes cluster applications via an L7 Application Load Balancer
    • Implementing a secure high-availability network infrastructure with a dedicated DMZ using the next-generation firewall
    • Creating an L7 Application Load Balancer with a Smart Web Security profile
    • Yandex Object Storage integration with Nextcloud
    • Deploying a web application on BareMetal servers with an L7 load balancer and Smart Web Security protection
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • L7 load balancer logs
  • Release notes

In this article:

  • Get your cloud ready
  • Required paid resources
  • Create a cloud network
  • Reserve a static public IP address
  • Create security groups
  • Import TLS certificates of the websites to Certificate Manager
  • Create instance groups for the websites
  • Upload the website files to the VMs
  • Create backend groups
  • Create and configure HTTP routers
  • Create HTTP routers for the websites
  • Create the default HTTP router
  • Create an L7 load balancer
  • Configure DNS for the websites
  • Test the hosting
  • Delete the resources you created
  1. Tutorials
  2. Setting up virtual hosting

Setting up virtual hosting

Written by
Yandex Cloud
Updated at July 14, 2025
  • Get your cloud ready
    • Required paid resources
  • Create a cloud network
  • Reserve a static public IP address
  • Create security groups
  • Import TLS certificates of the websites to Certificate Manager
  • Create instance groups for the websites
  • Upload the website files to the VMs
  • Create backend groups
  • Create and configure HTTP routers
    • Create HTTP routers for the websites
    • Create the default HTTP router
  • Create an L7 load balancer
  • Configure DNS for the websites
  • Test the hosting
  • Delete the resources you created

This tutorial describes how to set up virtual hosting: use Yandex Application Load Balancer to host multiple websites with different domain names at the same IP address.

As examples, we are going to use these three domain names: site-a.com, site-b.com, and default.com.

To set up virtual hosting:

  1. Get your cloud ready.
  2. Create a cloud network.
  3. Reserve a static public IP address.
  4. Create security groups.
  5. Import TLS certificates of the websites to Yandex Certificate Manager.
  6. Create instance groups for websites.
  7. Upload the website files to the VMs.
  8. Create backend groups.
  9. Create and configure HTTP routers.
  10. Create an L7 load balancer.
  11. Configure DNS for the websites.
  12. Test the hosting.

If you no longer need the resources you created, delete them.

Get your cloud readyGet your cloud ready

Sign up in Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or register a new account.
  2. On the Yandex Cloud Billing page, make sure you have a linked billing account with an ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can navigate to the cloud page to create or select a folder for your infrastructure to operate in.

Learn more about clouds and folders.

Required paid resourcesRequired paid resources

The cost of virtual hosting includes:

  • Fee for continuously running VMs (see Yandex Compute Cloud pricing).
  • Fee for using a public static IP address (see Yandex Virtual Private Cloud pricing).
  • Fee for using the computing resources of the L7 load balancer (see Application Load Balancer pricing).
  • Fee for public DNS queries and DNS zones if using Yandex Cloud DNS (see Cloud DNS pricing).

Create a cloud networkCreate a cloud network

All resources created in this tutorial will belong to the same cloud network.

To create a network:

Management console
  1. In the management console, select Virtual Private Cloud.
  2. Click Create network.
  3. Specify the network Name: vhosting-network.
  4. In the Advanced field, select Create subnets.
  5. Click Create network.

Reserve a static public IP addressReserve a static public IP address

For your virtual hosting to run, you need to assign a static public IP address to the L7 load balancer.

To reserve an IP address:

Management console
  1. In the management console, select Virtual Private Cloud.
  2. In the left-hand panel, select IP addresses. Click Reserve address.
  3. In the window that opens, select the ru-central1-d availability zone. Click ** Reserve**.

Create security groupsCreate security groups

Security groups include rules that allow the load balancer to receive inbound traffic and redirect it to the VMs so they can receive it. In this tutorial, we will create two security groups: one for the load balancer and another one for all VMs.

To create security groups:

Management console
  1. In the management console, select Virtual Private Cloud.

  2. In the left-hand panel, select Security groups.

  3. Create a security group for the load balancer:

    1. Click Create security group.

    2. Specify the group Name: vhosting-sg-balancer.

    3. Select Network: vhosting-network.

    4. Under Rules, create the following rules using the instructions below the table:

      Traffic
      direction
      Description Port range Protocol Source /
      destination
      CIDR blocks
      Outgoing any All Any CIDR 0.0.0.0/0
      Inbound ext-http 80 TCP CIDR 0.0.0.0/0
      Inbound ext-https 443 TCP CIDR 0.0.0.0/0
      Inbound healthchecks 30080 TCP Load balancer healthchecks —
    5. Select the Egress or Ingress tab.

    6. Click Add.

    7. In the Port range field of the window that opens, specify a single port or a range of ports open for inbound or outbound traffic.

    8. In the Protocol field, specify the appropriate protocol or leave Any to allow traffic transmission over any protocol.

    9. In the Destination name or Source field, select the rule purpose:

      • CIDR: Rule will apply to the range of IP addresses. In the CIDR blocks field, specify the CIDR and subnet masks traffic will come to or from. To add multiple CIDRs, click Add.
      • Security group: Rule will apply to the VMs from the current group or the selected security group.
      • Load balancer healthchecks: Rule allowing a load balancer to health-check VMs.
    10. Click Save. Repeat these steps to create all rules from the table.

    11. Click Save.

  4. Similarly, create a security group for the VM named vhosting-sg-vms with the same vhosting-network and the following rules:

    Traffic
    direction
    Description Port range Protocol Source CIDR blocks
    Inbound balancer 80 TCP Security group vhosting-sg-balancer
    Inbound ssh 22 TCP CIDR 0.0.0.0/0

Import TLS certificates of the websites to Certificate ManagerImport TLS certificates of the websites to Certificate Manager

To access the websites using the secure HTTPS protocol (HTTP over TLS), you must have TLS certificates issued for them. To use the certificates in the L7 load balancer, import them to Certificate Manager.

If your websites do not have certificates, you can use Certificate Manager to get them from Let's Encrypt®. You do not need to do anything else after creating certificates this way, because the certificates are imported automatically.

To import an existing certificate for site-a.com:

Management console
  1. In the management console, select Certificate Manager.
  2. Click Add certificate and select User certificate.
  3. Specify the certificate Name: vhosting-cert-a.
  4. In the Certificate field, click Add certificate. Upload the File with your certificate or enter its Content and click Add.
  5. If your certificate is issued by a third-party certificate authority, click Add chain in the Intermediate certificate chain field. Upload the File with the certificate chain or enter its Content and click Add.
  6. In the Private key field, click Add private key. Upload the File with the key or enter its Content and click Add.
  7. Click Create.

Similarly, import the certificates for site-b.com and default.com named vhosting-cert-b and vhosting-cert-default, respectively.

Create instance groups for the websitesCreate instance groups for the websites

Compute Cloud VMs will act as web servers for the two websites: one group of multiple identical instances for each website. In this tutorial, the LEMP stack (Linux, NGINX, MySQL®, PHP) will be installed on the servers. For more information, see LAMP or LEMP-based website.

To create an instance group for site-a.com:

Management console
  1. In the management console, select Compute Cloud.

  2. In the left-hand panel, select Instance groups. Click Create group of virtual machines.

  3. Enter the instance group name: vhosting-ig-a.

  4. Under Allocation, select multiple availability zones to ensure the fault tolerance of your hosting.

  5. Under Instance template, click Define.

  6. Under Boot disk image, open the Marketplace tab and click Show all Marketplace products. Select LEMP and click Use.

  7. Under Computing resources:

    • Choose a VM platform.
    • Specify the required number of vCPUs and the amount of RAM.

    This minimum configuration will do for functional website testing:

    • Platform: Intel Ice Lake
    • Guaranteed vCPU performance: 20%
    • vCPU: 2
    • RAM: 1 GB
  8. Under Network settings, select the Network named vhosting-network you created earlier and its subnets.

  9. In the Public address field, select Auto.

  10. Select the vhosting-sg-vms security group created earlier.

  11. Specify the VM access data:

    • In the Login field, enter the username.

    • In the SSH key field, paste the contents of the public key file.

      You need to create a key pair for the SSH connection on your own. To learn how, see Connecting to a VM over SSH.

    Alert

    Once created, the VM gets an IP address and a host name (FQDN) for connections. If you selected No address in the Public address field, you will not be able to access the VM from the internet.

  12. Click Save.

  13. Under Scaling, specify the instance group Size: 2.

  14. Under Integration with Application Load Balancer, select Create target group and enter vhosting-tg-a as the group name. Read more about target groups.

  15. Click Create.

Follow the same steps to create a second instance group named vhosting-ig-b and a target group named vhosting-tg-b for site-b.com.

It may take a few minutes to create an instance group. As soon as the group changes its status to RUNNING, and all its VMs to RUNNING_ACTUAL, you can upload the website files to them.

ig-running

Upload the website files to the VMsUpload the website files to the VMs

To test your web servers, upload index.html files with different contents to the VMs: one content version for the vhosting-ig-a instance group VMs, and another for the vhosting-ig-b instance group VMs.

Example of the index.html file for the vhosting-ig-a group
<!DOCTYPE html>
<html>
  <head>
    <title>Site A</title>
  </head>
  <body>
    <p>This is site A</p>
  </body>
</html>
Example of the index.html file for the vhosting-ig-b group
<!DOCTYPE html>
<html>
  <head>
    <title>Site B</title>
  </head>
  <body>
    <p>This is site B</p>
  </body>
</html>

To upload a file to a VM:

  1. Go to the VM page in the management console. In the Network section, find the VM's public IP address.

  2. Connect to the VM over SSH.

  3. Grant your user write permissions for the /var/www/html directory:

    Ubuntu
    CentOS
    sudo chown -R "$USER":www-data /var/www/html
    
    sudo chown -R "$USER":apache /var/www/html
    
  4. Upload the website files to the VM via SCP.

    Linux/macOS
    Windows

    Use the scp command line utility:

    scp -r <path_to_directory_with_files> <VM_user_name>@<VM_IP_address>:/var/www/html
    

    Use WinSCP to copy the local file directory to /var/www/html on the VM.

Repeat the above steps for the files you want to upload to each VM in the vhosting-ig-a and vhosting-ig-b groups.

Create backend groupsCreate backend groups

Target groups created together with instance groups must be linked to the backend groups that define the traffic allocation settings.

For the backends, the groups will implement health checks: the load balancer will periodically send health check requests to the VMs and expect a response for a certain period.

To create a backend group for site-a.com:

  1. In the management console, select Application Load Balancer.
  2. In the left-hand panel, select Backend groups. Click Create backend group.
  3. Enter the backend group Name: vhosting-bg-a.
  4. Under Backends, click Add.
  5. Enter the backend Name: vhosting-backend-a.
  6. In the Target groups field, select the vhosting-tg-a group.
  7. Specify Port the backend VMs will use to receive incoming traffic from the load balancer: 80.
  8. Click Add health check.
  9. Specify Port the backend VMs will use to accept health check connections: 80.
  10. Specify the Path the load balancer will use for health checks: /.
  11. Click Create.

Follow the same steps to create a second backend group named vhosting-bg-b for site-b.com. In this group, create the vhosting-backend-b backend and link the vhosting-tg-b target group to it.

Create and configure HTTP routersCreate and configure HTTP routers

Backend groups must be linked to HTTP routers that define the HTTP request routing rules. In this tutorial, you will create two routers for the main sites (site-a.com and site-b.com) and the default router for default.com, which will respond to each request with the 404 Not Found HTTP status code.

Create HTTP routers for the websitesCreate HTTP routers for the websites

To create an HTTP router for site-a.com:

Management console
  1. In the management console, select Application Load Balancer.
  2. In the left-hand panel, select HTTP routers. Click Create HTTP router.
  3. Specify the HTTP router Name: vhosting-router-a.
  4. Click Add virtual host.
  5. Specify the virtual host Name: vhosting-host-a.
  6. In the Authority field, specify the website domain name: site-a.com.
  7. Click Add route.
  8. Specify the route Name: vhosting-route-a.
  9. In the Backend group field, select the vhosting-bg-a group.
  10. Click Create.

Follow the same steps to create the vhosting-router-b HTTP router for site-b.com and link the vhosting-bg-b backend group to it.

Create the default HTTP routerCreate the default HTTP router

To create an HTTP router for default.com:

Management console
  1. In the management console, select Application Load Balancer.

  2. In the left-hand panel, select HTTP routers. Click Create HTTP router.

  3. Specify the HTTP router Name: vhosting-router-default.

  4. Click Add virtual host.

  5. Specify the virtual host Name: vhosting-host-default.

  6. In the Authority field, specify the website domain name: default.com.

  7. Click Add route.

  8. Specify the route Name: vhosting-route-a.

  9. In the Action field, select Response.

  10. In the HTTP status code field, select 404 Not Found.

  11. In the Response body field, click Select. Select the Text method and enter the following in the Content field:

    404 Not Found
    
    This is the default site.
    

    Click Add.

  12. Click Create.

Create an L7 load balancerCreate an L7 load balancer

To create a load balancer:

Management console
  1. In the management console, select Application Load Balancer.
  2. Click Create L7 load balancer.
  3. Enter the load balancer Name: vhosting-alb.
  4. Under Network settings, select the vhosting-sg-balancer security group you created earlier.
  5. Create a listener to redirect HTTP requests to HTTPS:
    1. Under Listeners, click Add listener.
    2. Enter the listener Name: vhosting-listener-http.
    3. Under Public IP address, select List for the type and the IP address you reserved earlier.
    4. In the Protocol field, select Redirect to HTTPS.
  6. Create an HTTPS request listener:
    1. Click Add listener again.
    2. Enter the listener Name: vhosting-listener-https.
    3. Under Public IP address, select the List type and the IP address you reserved earlier.
    4. In the Protocol field, select HTTPS.
    5. Under Main listener, select vhosting-cert-default for the certificate and vhosting-router-default for the HTTP router.
    6. Add an SNI handler for site-a.com:
      1. Click Add SNI match.
      2. Specify the Name for the SNI handler: vhosting-sni-a.
      3. In the Server names field, specify site-a.com.
      4. Select vhosting-cert-a for the certificate and vhosting-router-a for the HTTP router.
    7. Follow the same steps to add an SNI handler for site-b.com with vhosting-sni-b as its name, site-b.com as the server name, the vhosting-cert-b certificate, and the vhosting-router-b HTTP router.
  7. Click Create.

Configure DNS for the websitesConfigure DNS for the websites

The site-a.com, site-b.com, and default.com domain names must be mapped to the L7 load balancer IP address using DNS records.

To configure DNS for site-a.com:

  1. In the management console, select Application Load Balancer.

  2. Copy the IP address of the load balancer that you created.

  3. On the website of your DNS hosting provider, navigate to the DNS settings.

  4. Create or edit the A record for site-a.com so that it points to the copied IP address:

    site-a.com. A <L7_load_balancer_IP_address>
    

    If you use Yandex Cloud DNS, follow this guide to configure the record:

    Configuring DNS records for Cloud DNS
    Management console
    1. In the management console, select Cloud DNS.
    2. If you do not have a public DNS zone, create one:
      1. Click Create zone.
      2. Specify the zone Name: vhosting-dns-a.
      3. In the Zone field, enter the website domain name with a trailing dot: site-a.com..
      4. Select a Type of the zone: Public.
      5. Click Create.
    3. Create a record in the zone:
      1. In the list of zones, click vhosting-dns-a.
      2. Click Create record.
      3. Leave the Name field empty for the record to match the site-a.com domain name (rather than a name with a subdomain, e.g., www.site-a.com).
      4. Select the record Type: A.
      5. In the Data field, paste the the load balancer’s IP address you copied.
      6. Click Create.

Follow the same steps to configure DNS for site-b.com and default.com using the same IP address.

You can test your websites 15-20 minutes after you have configured DNS.

Test the hostingTest the hosting

To test the hosting, open each of the three websites in your browser:

  • For https://site-a.com and https://site-b.com, you should see the pages you uploaded to the VMs.
  • For https://default.com, you should see the 404 Not Found error page configured when creating the HTTP router.

Delete the resources you createdDelete the resources you created

To shut down the hosting and stop paying for the resources you created:

  1. Delete the non-billable resources that block the deletion of billable resources:
    1. Delete the vhosting-alb L7 load balancer.
    2. Delete the vhosting-router-a, vhosting-router-b, and vhosting-router-default HTTP routers.
    3. Delete the vhosting-bg-a and vhosting-bg-b backend groups.
  2. Delete the vhosting-ig-a and vhosting-ig-b instance groups.
  3. Delete the static public IP address that you reserved.
  4. If you used Yandex Cloud DNS, delete the DNS records and delete the DNS zone.

Was the article helpful?

Previous
All tutorials
Next
Overview
© 2025 Direct Cursus Technology L.L.C.