[Yandex Cloud documentation](../../index.md) > [Yandex Application Load Balancer](../index.md) > [Step-by-step guides](index.md) > HTTP routers > Managing virtual hosts

# Managing virtual hosts

[Virtual hosts](../concepts/http-router.md#virtual-host) within [HTTP routers](../concepts/http-router.md) consolidate [routes](../concepts/http-router.md#routes) belonging to the same set of domains, i.e., the `Host` (`:authority`) header values of an HTTP request. On an incoming request, the [load balancer](../concepts/application-load-balancer.md) checks route predicates one by one and selects the first one matching the request.

## Creating a virtual host {#create-vh}

To create a virtual host:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) where you are going to create a virtual host.
  1. Navigate to **Application Load Balancer**.
  1. In the left-hand panel, click ![route](../../_assets/console-icons/route.svg) **HTTP routers** and select the [HTTP router](../concepts/http-router.md) you are going to create a virtual host in.
  
      [Create](http-router-create.md) a new HTTP router if needed.
  1. In the top panel, click ![cube](../../_assets/console-icons/cube.svg) **Create virtual host** and in the window that opens:

      1. In the **Name** field, enter a name for the new virtual host. Follow these naming requirements:
         
         * Length: between 3 and 63 characters.
         * It can only contain lowercase Latin letters, numbers, and hyphens.
         * It must start with a letter and cannot end with a hyphen.
      1. In the **Authority** field, specify:

          * For HTTP traffic, the value of the `Host` header for HTTP/1.1 or the `:authority` pseudo-header for HTTP/2 that will be used to select this virtual host.
          * For gRPC traffic, `*` or the [IP address](../../vpc/concepts/address.md) of the load balancer.

          If needed, use the **Add host** button to assign additional **Authority** values to the virtual host.

          If **Authority** is not specified, all traffic will be routed to this virtual host (same as `*`).

      1. Optionally, in the **Security profile** field, select a [Yandex Smart Web Security](../../smartwebsecurity/index.md) [security profile](../../smartwebsecurity/concepts/profiles.md). A security profile allows you to filter incoming requests and enable [WAF](../../smartwebsecurity/concepts/waf.md) for protection against malicious activities. For more information, see [Security profiles](../../smartwebsecurity/concepts/profiles.md).
      1. Optionally, enable **Limit on all requests** and/or **Limit on requests from one IP** and set the limits for the number of requests the virtual host will be processing per unit of time.
      1. Optionally, expand **DNS settings for internal addresses** and click **Add record**.
         
         * In the **Type** field, select where you want to modify the header:
             * `Request`: To modify incoming request headers, from client to load balancer.
             * `Response`: To modify outgoing response headers, from backend to external client.
         * In the **Header name** field, give the header a name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
         * In the **Operation** field, select an action:
             * `append`: To add a string to the header value. Specify the string in the field on the right.
             * `replace`: To completely replace the header value. Specify the new header value in the field on the right.
             * `remove`: To delete the header. Both the header value and the header itself will be removed.
             * `rename`: To change the header name. Specify the new header name in the field on the right. The header value will not change.
         
         If required, click **Change header** to add new rows if you need to modify multiple headers at once.
      1. Optionally, [create](manage-routes.md#create-route) the necessary routes for your new virtual host's traffic.
      1. Click **Create**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. See the description of the CLI command for creating a virtual host:
     
     ```bash
     yc alb virtual-host create --help
     ```
  1. View the list of HTTP routers in the default folder:
     
     ```bash
     yc alb http-router list
     ```
     
     Result:
     
     ```text
     +----------------------+--------------------+-------------+-------------+
     |          ID          |        NAME        | VHOST COUNT | ROUTE COUNT |
     +----------------------+--------------------+-------------+-------------+
     | ds76j5n6a39g******** | sample-http-router |           1 |           2 |
     | ds76jk27sdf3******** | new-http-router    |           2 |           7 |
     +----------------------+--------------------+-------------+-------------+
     ```
  1. Create a virtual host by specifying its name and these settings:
     
     ```bash
     yc alb virtual-host create <virtual_host_name> \
       --http-router-name <HTTP_router_name> \
       --authority <domain_1>,<domain_2>,...,<domain_n> \
       --modify-request-header name=Accept-Language,append=ru-RU \
       --modify-response-header name=Accept-Charset,replace=utf-8 \
       --rate-limit rps=100,all-requests \
       --security-profile-id <security_profile_ID>
     ```
     
     Where:
     * `--http-router-name`: HTTP router name.
     
         Instead of the HTTP router name, you can provide its ID in the `--http-router-id` parameter.
     * `--authority`: List of domains for the `Host` header (HTTP/1.1) or the `authority` pseudo-header (HTTP/2) associated with this virtual host, comma-separated. You can use wildcards, e.g., `*.foo.com` or `*-bar.foo.com`. For gRPC traffic, you may specify the load balancer's IP address.
     
         This is an optional parameter. If not specified, all traffic will be routed to this virtual host.
     * `--modify-request-header`: Request HTTP header modification settings in `<property>=<value>` format. Available properties:
     
         * `name`: Modified header name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
         * `append`: Add a row to the current header value.
         * `replace`: Completely replace the current header value.
         * `rename`: Change the header name. The header value will not change.
         * `remove`: Delete the header. Both the header value and the header itself will be removed.
     
         To modify multiple HTTP headers in a request, include `--modify-request-header` as many times as needed.
     
         This is an optional parameter; if omitted, request headers go to the backend unchanged.
     
     * `--modify-response-header`: Response HTTP header modification settings in `<property>=<value>` format. Available properties:
     
         * `name`: Modified header name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
         * `append`: Add a row to the current header value.
         * `replace`: Completely replace the current header value.
         * `rename`: Change the header name. The header value will not change.
         * `remove`: Delete the header. Both the header value and the header itself will be removed.
     
         To modify multiple HTTP headers in a response, include `--modify-response-header` as many times as needed.
     
         This is an optional parameter; if omitted, response headers go to the client unchanged.
     
     * `--rate-limit`: Request rate limit. Available properties:
         * `rps` or `rpm`: Number of incoming requests per second or per minute.
         * `all-requests`: Limits all incoming requests.
         * `requests-per-ip`: Applies the limit per client IP address.
     
         You can configure only one type of rate limit per virtual host, either `all-requests` or `requests-per-ip`.
     
         This is an optional parameter; if not specified, no rate limiting is applied.
     * `--security-profile-id`: [Yandex Smart Web Security](../../smartwebsecurity/index.md) [security profile](../../smartwebsecurity/concepts/profiles.md) ID. A security profile allows you to filter incoming requests, enable [WAF](../../smartwebsecurity/concepts/waf.md), and set limits on the number of requests for protection against malicious activity. Learn more [here](../../smartwebsecurity/concepts/profiles.md). This is an optional parameter.
     
     
     Result:
     
     ```text
     name: test-virtual-host
     authority:
       - example.com
       - example.org
     modify_request_headers:
       - name: Accept-Language
         append: ru-RU
       - name: Accept-Charset
         replace: utf-8
     route_options:
       security_profile_id: fevu5fnuk6vf********
     rate_limit:
       all_requests:
         per_second: "100"
     ```

  For more information about the `alb virtual-host create` command, see the [CLI reference](../../cli/cli-ref/application-load-balancer/cli-ref/virtual-host/create.md).

- Terraform {#tf}

  With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
  
  Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
  
  For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../terraform/index.md).

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

  1. Describe the virtual host parameters in the configuration file. With Terraform, you can create virtual hosts with different route [types](../concepts/http-router.md#routes-types):

      {% list tabs group=alb_route_type%}

      - HTTP {#http}

        ```hcl
        resource "yandex_alb_virtual_host" "my-virtual-host" {
          name           = "<virtual_host_name>"
          http_router_id = "<HTTP_router_ID>"
        
          rate_limit {
            all_requests {
              per_second = <requests_per_second>
              # or per_minute = <requests_per_minute>
            }
            requests_per_ip {
              per_second = <requests_per_second>
              # or per_minute = <requests_per_minute>
            }
          }
        
          route {
            name                      = "<route_name>"
            disable_security_profile  = true|false
        
            http_route {
              http_match {
                http_method = ["<HTTP_method_1>","<HTTP_method_2>",...,"<HTTP_method_n>"]
                path {
                  prefix = "/<request_path_prefix>/"
                  # or exact = "<request_path>"
                  # or regex = "<regular_expression>"
                }
              }
        
              http_route_action {
                backend_group_id  = "<backend_group_ID>"
                host_rewrite      = "<Host_header_value>"
                timeout           = "<connection_timeout>s"
                idle_timeout      = "<idle_timeout>s"
                prefix_rewrite    = "<new_request_path_prefix>/"
                rate_limit {
                  all_requests {
                    per_second = <requests_per_second>
                    # or per_minute = <requests_per_minute>
                  }
                  requests_per_ip {
                    per_second = <requests_per_second>
                    # or per_minute = <requests_per_minute>
                  }
                }
              }
            }
          }
        
          authority        = ["<domain_1>","<domain_2>",...,"<domain_n>"]
        
          modify_request_headers {
            name           = "<header_name>"
            append         = "<string_added_to_header_content>"
            # or replace  = "<new_header_content>"
            # or remove   = true|false
          }
        
          modify_response_headers {
            name           = "<header_name>"
            append         = "<string_added_to_header_content>"
            # or replace  = "<new_header_content>"
            # or remove   = true|false
          }
        
          route_options {
            security_profile_id = "<security_profile_ID>"
          }
        }
        ```

        Where:

        * `yandex_alb_virtual_host`: Virtual host description:

            * `name`: Virtual host name. Follow these naming requirements:
            
                * Length: between 3 and 63 characters.
                * It can only contain lowercase Latin letters, numbers, and hyphens.
                * It must start with a letter and cannot end with a hyphen.
            
            * `http_router_id`: HTTP router ID.
            * `rate_limit`: Request rate limit for the entire virtual host (optional).
                * `all_requests`: Limit on all requests per second or per minute (optional):
                    * `per_second`: Maximum number of incoming requests to the virtual host per second.
                    * `per_minute`: Maximum number of incoming requests to the virtual host per minute.
            
                    The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.
                * `requests_per_ip`: Additionally limits requests for each IP address per second or per minute (optional):
                    * `per_second`: Maximum number of incoming requests from a single IP address to the virtual host per second.
                    * `per_minute`: Maximum number of incoming requests from a single IP address to the virtual host per minute.
            
                    The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.

            * `route`: Virtual host route description:

                * `name`: Route name.
                * `disable_security_profile`: Disabling the [Yandex Smart Web Security](../../smartwebsecurity/index.md) [security profile](../../smartwebsecurity/concepts/profiles.md) (optional). The possible values are `true` (the profile is disabled) or `false` (the profile is enabled). The default value is `false`: the security profile is enabled.

                * `http_route`: Route description for HTTP traffic:
                
                    * `http_match`: Parameter for filtering incoming HTTP requests (optional):
                
                        * `http_method`: List of HTTP [methods](https://en.wikipedia.org/wiki/HTTP#Request_methods) for which requests will be routed (optional). By default, requests with any methods are routed.
                        * `path`: Optionally, parameters for filtering the path of an incoming request:
                
                            * `exact`: Route requests with the same path as the specified one. For example, to route all requests, specify the `/` path.
                            * `prefix`: Route requests whose path starts with the specified prefix.
                            * `regex`: Route requests whose path matches the specified [RE2](https://github.com/google/re2/wiki/Syntax) [regular expression](https://en.wikipedia.org/wiki/Regular_expression), e.g., `\/[a-z]{10}[0-9]{3}\/`.
                
                            The `exact`, `prefix`, and `regex` parameters are mutually exclusive: you can use only one of them.
                
                    * `http_route_action`: Action applied to HTTP traffic.
                
                        * `backend_group_id`: ID of the [backend group](../concepts/backend-group.md) located in the same folder as the [HTTP router](../concepts/http-router.md) and virtual host of the new route.
                        * `host_rewrite`: Replacing the Host header in the request with the specified value (optional). You specify the `auto_host_rewrite` parameter instead of the `host_rewrite` parameter; in this case the Host header in the request will be automatically replaced with the address of the target [VM](../../compute/concepts/vm.md).
                        * `timeout`: Maximum connection time in seconds (optional). The default value is 60 seconds.
                        * `idle_timeout`: Maximum connection idle timeout (keep-alive time) (optional). If not specified, the idle connection will be terminated immediately.
                        * `prefix_rewrite`: Value to replace the path or part of the path specified in the `path` parameter (optional).
                        * `rate_limit`: Limits the number of requests per unit of time (optional):
                          
                          * `all_requests`: Limits all incoming requests (optional):
                          
                              * `per_second`: Maximum number of incoming requests to a route per second.
                              * `per_minute`: Maximum number of incoming requests to a route per minute.
                          
                              The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.
                          * `requests_per_ip`: Limits incoming requests from a single IP address (optional):
                          
                              * `per_second`: Maximum number of incoming requests to a route from a single IP address per second.
                              * `per_minute`: Maximum number of incoming requests to a route from a single IP address per minute.
                          
                              The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.

            * `authority`: HTTP/1.1 `Host` (HTTP/2 `authority`) header domains associated with this virtual host. You can use wildcards, e.g., `*.foo.com` or `*-bar.foo.com`. For gRPC traffic, you may specify `*` or the the load balancer's IP address.
            
                This is an optional parameter. If not specified, all traffic will be routed to this virtual host.
            * `modify_request_headers`: HTTP request header modification settings. Possible parameters:
            
                * `name`: Modified header name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
                * `append`: Add a row to the current header value.
                * `replace`: Completely replace the current header value.
                * `remove`: Delete the header. Both the header value and the header itself will be removed. The possible values are `true` or `false`.
            
                This is an optional parameter; if omitted, request headers are provided to the backend unchanged.
            
            * `modify_response_headers`: HTTP response header modification settings. Possible parameters:
            
                * `name`: Modified header name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
                * `append`: Add a row to the current header value.
                * `replace`: Completely replace the current header value.
                * `remove`: Delete the header. Both the header value and the header itself will be removed. The possible values are `true` or `false`.
            
                This is an optional parameter; if omitted, response headers are provided to the client unchanged.
            * `route_options`: Additional virtual host parameters (optional):
                * `security_profile_id`: Security profile ID. A security profile allows you to filter incoming requests, enable [WAF](../../smartwebsecurity/concepts/waf.md), and set limits on the number of requests for protection against malicious activity. For more information, see [Security profiles](../../smartwebsecurity/concepts/profiles.md).

      - gRPC {#grpc}

        ```hcl
        resource "yandex_alb_virtual_host" "my-virtual-host" {
          name           = "<virtual_host_name>"
          http_router_id = "<HTTP_router_ID>"
        
          rate_limit {
            all_requests {
              per_second = <requests_per_second>
              # or per_minute = <requests_per_minute>
            }
            requests_per_ip {
              per_second = <requests_per_second>
              # or per_minute = <requests_per_minute>
            }
          }
        
          route {
            name                      = "<route_name>"
            disable_security_profile  = true|false
        
            grpc_route {
              grpc_match {
                fqmn {
                  prefix = "/<request_FQMN_prefix>"
                  # or exact = "<request_FQMN>"
                  # or regex = "<regular_expression>"
                }
              }
        
              grpc_route_action {
                backend_group_id  = "<backend_group_ID>"
                host_rewrite      = "<Host_header_value>"
                max_timeout       = "<connection_timeout>s"
                idle_timeout      = "<idle_timeout>s"
                rate_limit {
                  all_requests {
                    per_second = <requests_per_second>
                    # or per_minute = <requests_per_minute>
                  }
                  requests_per_ip {
                    per_second = <requests_per_second>
                    # or per_minute = <requests_per_minute>
                  }
                }
              }
            }
          }
        
          authority        = ["<domain_1>","<domain_2>",...,"<domain_n>"]
        
          modify_request_headers {
            name           = "<header_name>"
            append         = "<string_added_to_header_content>"
            # or replace  = "<new_header_content>"
            # or remove   = true|false
          }
        
          modify_response_headers {
            name           = "<header_name>"
            append         = "<string_added_to_header_content>"
            # or replace  = "<new_header_content>"
            # or remove   = true|false
          }
        
          route_options {
            security_profile_id = "<security_profile_ID>"
          }
        }
        ```

        Where:

        * `yandex_alb_virtual_host`: Virtual host description:

            * `name`: Virtual host name. Follow these naming requirements:
            
                * Length: between 3 and 63 characters.
                * It can only contain lowercase Latin letters, numbers, and hyphens.
                * It must start with a letter and cannot end with a hyphen.
            
            * `http_router_id`: HTTP router ID.
            * `rate_limit`: Request rate limit for the entire virtual host (optional).
                * `all_requests`: Limit on all requests per second or per minute (optional):
                    * `per_second`: Maximum number of incoming requests to the virtual host per second.
                    * `per_minute`: Maximum number of incoming requests to the virtual host per minute.
            
                    The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.
                * `requests_per_ip`: Additionally limits requests for each IP address per second or per minute (optional):
                    * `per_second`: Maximum number of incoming requests from a single IP address to the virtual host per second.
                    * `per_minute`: Maximum number of incoming requests from a single IP address to the virtual host per minute.
            
                    The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.

            * `route`: Virtual host route description:

                * `name`: Route name.
                * `disable_security_profile`: Disabling the [Yandex Smart Web Security](../../smartwebsecurity/index.md) [security profile](../../smartwebsecurity/concepts/profiles.md) (optional). The possible values are `true` (the profile is disabled) or `false` (the profile is enabled). The default value is `false`: the security profile is enabled.

                * `grpc_route`: Route description for gRPC traffic:
                
                    * `grpc_match.fqmn`: Parameter for filtering incoming gRPC requests by FQMN (optional):
                
                        * `exact`: Route requests with the same FQMN as the specified one.
                        * `prefix`: Route requests whose FQMN starts with the specified prefix. For example, you can specify the first word of the service name: `/helloworld`.
                        * `regex`: Route requests whose FQMN matches the specified [RE2](https://github.com/google/re2/wiki/Syntax) [regular expression](https://en.wikipedia.org/wiki/Regular_expression). For example: `\/[a-z]{10}[0-9]{3}`.
                
                        The `exact`, `prefix`, and `regex` parameters are mutually exclusive: you can use only one of them.
                        
                    * `grpc_route_action`: Action applied to gRPC traffic.
                
                        * `backend_group_id`: ID of the [backend group](../concepts/backend-group.md) located in the same folder as the new route's [HTTP router](../concepts/http-router.md) and virtual host.
                        * `host_rewrite`: Replacing the Host header in the request with the specified value (optional). You can specify `auto_host_rewrite` instead of `host_rewrite`, in which case the Host header in the request will be automatically replaced with the target [VM](../../compute/concepts/vm.md) address.
                        * `--request-max-timeout`: Maximum request timeout in seconds (optional). You can specify a shorter timeout in the `grpc-timeout` request HTTP header. The default value is 60 seconds.
                        * `idle_timeout`: Maximum connection idle timeout (keep-alive time) (optional). If not specified, the idle connection will be terminated immediately.
                        * `rate_limit`: Limits the number of requests per unit of time (optional):
                          
                          * `all_requests`: Limits all incoming requests (optional):
                          
                              * `per_second`: Maximum number of incoming requests to a route per second.
                              * `per_minute`: Maximum number of incoming requests to a route per minute.
                          
                              The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.
                          * `requests_per_ip`: Limits incoming requests from a single IP address (optional):
                          
                              * `per_second`: Maximum number of incoming requests to a route from a single IP address per second.
                              * `per_minute`: Maximum number of incoming requests to a route from a single IP address per minute.
                          
                              The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.

            * `authority`: HTTP/1.1 `Host` (HTTP/2 `authority`) header domains associated with this virtual host. You can use wildcards, e.g., `*.foo.com` or `*-bar.foo.com`. For gRPC traffic, you may specify `*` or the the load balancer's IP address.
            
                This is an optional parameter. If not specified, all traffic will be routed to this virtual host.
            * `modify_request_headers`: HTTP request header modification settings. Possible parameters:
            
                * `name`: Modified header name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
                * `append`: Add a row to the current header value.
                * `replace`: Completely replace the current header value.
                * `remove`: Delete the header. Both the header value and the header itself will be removed. The possible values are `true` or `false`.
            
                This is an optional parameter; if omitted, request headers are provided to the backend unchanged.
            
            * `modify_response_headers`: HTTP response header modification settings. Possible parameters:
            
                * `name`: Modified header name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
                * `append`: Add a row to the current header value.
                * `replace`: Completely replace the current header value.
                * `remove`: Delete the header. Both the header value and the header itself will be removed. The possible values are `true` or `false`.
            
                This is an optional parameter; if omitted, response headers are provided to the client unchanged.
            * `route_options`: Additional virtual host parameters (optional):
                * `security_profile_id`: Security profile ID. A security profile allows you to filter incoming requests, enable [WAF](../../smartwebsecurity/concepts/waf.md), and set limits on the number of requests for protection against malicious activity. For more information, see [Security profiles](../../smartwebsecurity/concepts/profiles.md).

      {% endlist %}

      Learn more about the properties of Terraform resources in the relevant provider guide: [yandex_alb_virtual_host](../../terraform/resources/alb_virtual_host.md).

  1. Create the resources:

      1. In the terminal, navigate to the configuration file directory.
      1. Make sure the configuration is correct using this command:
      
         ```bash
         terraform validate
         ```
      
         If the configuration is valid, you will get this message:
      
         ```bash
         Success! The configuration is valid.
         ```
      
      1. Run this command:
      
         ```bash
         terraform plan
         ```
      
         You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
      1. Apply the configuration changes:
      
         ```bash
         terraform apply
         ```
      
      1. Type `yes` and press **Enter** to confirm the changes.

      Terraform will create all the required resources. You can check the new resources and their settings using the [management console](https://console.yandex.cloud) or this [CLI](../../cli/index.md) command:

      ```bash
      yc alb virtual-host get <virtual_host_name> \
        --http-router-name <HTTP_router_name>
      ```

      {% note warning "Timeouts" %}
      
      The Terraform provider limits the execution time for operations with Application Load Balancer HTTP routers and virtual hosts to 10 minutes.
      
      Operations in excess of this time will be interrupted.
      
      {% cut "How do I modify these limits?" %}
      
      Add the `timeouts` section to the descriptions of the HTTP router and virtual host (the `yandex_alb_http_router` and `yandex_alb_virtual_host` resources, respectively).
      
      Here is an example:
      
      ```hcl
      resource "yandex_alb_http_router" "<router_name>" {
        ...
        timeouts {
          create = "60m"
          update = "60m"
          delete = "60m"
        }
      }
      ```
      
      {% endcut %}
      
      {% endnote %}

- API {#api}

  Use the [create](../api-ref/VirtualHost/create.md) REST API method for the [VirtualHost](../api-ref/VirtualHost/index.md) resource or the [VirtualHostService/Create](../api-ref/grpc/VirtualHost/create.md) gRPC API call.

{% endlist %}

## Updating a virtual host {#update-vh}

To update a virtual host:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) containing your virtual host.
  1. Navigate to **Application Load Balancer**.
  1. In the left-hand panel, click ![route](../../_assets/console-icons/route.svg) **HTTP routers** and select the [HTTP router](../concepts/http-router.md) that contains the virtual host.
  1. On the page that opens, under **Virtual hosts**, click ![ellipsis](../../_assets/console-icons/ellipsis.svg) next to the virtual host and select ![pencil](../../_assets/console-icons/pencil.svg) **Edit**. In the window that opens:

      1. Optionally, in the **Authority** field, update the settings and specify:

          * For HTTP traffic, the value of the `Host` header for HTTP/1.1 or the `:authority` pseudo-header for HTTP/2 that will be used to select this virtual host.
          * For gRPC traffic, `*` or the [IP address](../../vpc/concepts/address.md) of the load balancer.

          If needed, use the **Add host** button to assign additional **Authority** values to the virtual host.

          If **Authority** is not specified, all traffic will be routed to this virtual host (same as `*`).
      1. Optionally, in the **Security profile** field, select a [Yandex Smart Web Security](../../smartwebsecurity/index.md) [security profile](../../smartwebsecurity/concepts/profiles.md). A security profile allows you to filter incoming requests and enable [WAF](../../smartwebsecurity/concepts/waf.md) for protection against malicious activities. For more information, see [Security profiles](../../smartwebsecurity/concepts/profiles.md).
      1. Optionally, enable **Limit on all requests** and/or **Limit on requests from one IP** and set the limits for the number of requests the virtual host will be processing per unit of time.
      1. Optionally, expand the **Manage headers** section and configure a [HTTP header](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields) modification. If there are none yet, click **Change header** to add a new header modification:

          * In the **Type** field, select where you want to modify the header:
              * `Request`: To modify incoming request headers, from client to load balancer.
              * `Response`: To modify outgoing response headers, from backend to external client.
          * In the **Header name** field, give the header a name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
          * In the **Operation** field, select an action:
              * `append`: To add a string to the header value. Specify the string in the field on the right.
              * `replace`: To completely replace the header value. Specify the new header value in the field on the right.
              * `remove`: To delete the header. Both the header value and the header itself will be removed.
              * `rename`: To change the header name. Specify the new header name in the field on the right. The header value will not change.
          
          If required, click **Change header** to add new rows if you need to modify multiple headers at once.
      1. Optionally, [create](manage-routes.md#create-route) the necessary routes for your new virtual host's traffic.
      1. If you want to change the route order, click **Sort** and in the window that opens:
         
         1. Drag and drop routes to arrange them in desired order.
         1. Click **Save**.
         
         {% note info %}
         
         You will be able to [reorder](manage-routes.md#sort-routes) your virtual host routes at any later time.
         
         {% endnote %}
      1. Click **Save**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. View the description of the CLI command for updating a virtual host:

      ```bash
      yc alb virtual-host update --help
      ```
  1. View the list of HTTP routers in the default folder:
     
     ```bash
     yc alb http-router list
     ```
     
     Result:
     
     ```text
     +----------------------+--------------------+-------------+-------------+
     |          ID          |        NAME        | VHOST COUNT | ROUTE COUNT |
     +----------------------+--------------------+-------------+-------------+
     | ds76j5n6a39g******** | sample-http-router |           1 |           2 |
     | ds76jk27sdf3******** | new-http-router    |           2 |           7 |
     +----------------------+--------------------+-------------+-------------+
     ```
  1. View the list of virtual hosts in an HTTP router by specifying the router name or ID, respectively, in the `--http-router-name` or `--http-router-id` parameter:
     
     ```bash
     yc alb virtual-host list \
       --http-router-name <HTTP_router_name> \
       --http-router-id <HTTP_router_ID>
     ```
     
     Result:
     
     ```text
     +-------------------+-------------+-------------+----------------------+
     |        NAME       | AUTHORITIES | ROUTE COUNT | SECURITY PROFILE ID  |
     +-------------------+-------------+-------------+----------------------+
     | my-virtual-host   | *           |           1 | fevu5fnuk6vf******** |
     | test-virtual-host | example.com |           2 | fevug3d25bv6******** |
     +-------------------+-------------+-------------+----------------------+
     ```
  1. To update a virtual host, put in its name and run this command:

      ```bash
      yc alb virtual-host update <virtual_host_name> \
        --http-router-name <HTTP_router_name> \
        --authority <domain_1>,<domain_2>,...,<domain_n> \
        --modify-request-header name=Accept-Language,append=ru-RU \
        --modify-response-header name=Accept-Charset,replace=utf-8 \
        --rate-limit rps=100,all-requests \
        --security-profile-id <security_profile_ID> \
        --clear-routes
      ```

      Where:
      * `--http-router-name`: HTTP router name.

          Instead of the HTTP router name, you can provide its ID in the `--http-router-id` parameter.
      * `--authority`: List of domains for the `Host` header (HTTP/1.1) or the `authority` pseudo-header (HTTP/2) associated with this virtual host, comma-separated. You can use wildcards, e.g., `*.foo.com` or `*-bar.foo.com`. For gRPC traffic, you may specify the load balancer's IP address.

          This is an optional setting. If not specified, all traffic will be routed to this virtual host.

          To remove the current list of domains assigned to the virtual host, provide the `--clear-authorities` parameter in the command.
      * `--modify-request-header`: Request HTTP header modification settings in `<property>=<value>` format. Available properties:

          * `name`: Modified header name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
          * `append`: Add a row to the current header value.
          * `replace`: Completely replace the current header value.
          * `rename`: Change the header name. The header value will not change.
          * `remove`: Delete the header. Both the header value and the header itself will be removed.

          To modify multiple HTTP headers in a request, include `--modify-request-header` as many times as needed.

          This is an optional parameter; if omitted, request headers are provided to the backend unchanged.

          To clear all request header modification settings for the virtual host, provide the `--clear-request-header-modifications` parameter in the command.
      * `--modify-response-header`: Response HTTP header modification settings in `<property>=<value>` format. Available properties: 

          * `name`: Modified header name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
          * `append`: Add a row to the current header value.
          * `replace`: Completely replace the current header value.
          * `rename`: Change the header name. The header value will not change.
          * `remove`: Delete the header. Both the header value and the header itself will be removed.

          To modify multiple HTTP headers in a response, include `--modify-response-header` as many times as needed.

          This is an optional parameter; if omitted, response headers are provided to the client unchanged.

          To clear all response HTTP header modification settings for the virtual host, provide the `--clear-response-header-modifications` parameter in the command.
      * `--rate-limit`: Request rate limit. Available properties:
          * `rps` or `rpm`: Number of incoming requests per second or per minute.
          * `all-requests`: Limits all incoming requests.
          * `requests-per-ip` Applies the limit per client IP address.

          You can configure only one type of rate limit per virtual host, either `all-requests` or `requests-per-ip`.

          This is an optional parameter; if not specified, no rate limiting is applied.

          To clear all rate-limiting settings from the virtual host, provide the `--clear-rate-limit` parameter in the command.
      * `--security-profile-id`: [Yandex Smart Web Security](../../smartwebsecurity/index.md) [security profile](../../smartwebsecurity/concepts/profiles.md) ID. A security profile allows you to filter incoming requests, enable [WAF](../../smartwebsecurity/concepts/waf.md), and set limits on the number of requests for protection against malicious activities. For more information, see [Security profiles](../../smartwebsecurity/concepts/profiles.md). This is an optional setting.

          To detach a security profile from the virtual host, provide an empty value in the flag: `--security-profile-id ""`.

      * `--clear-routes`: Clears all routes from the virtual host. This is an optional setting.

      Result:

      ```text
      name: test-virtual-host
      authority:
        - example.com
      modify_request_headers:
        - name: Accept-Language
          replace: ru-RU
      modify_response_headers:
        - name: Accept-Charset
          append: utf-8
      route_options:
        security_profile_id: fevu5fnuk6vf********
      rate_limit:
        all_requests:
          per_second: "80"
      ```

  For more information about the `yc alb virtual-host update` command, see the [CLI reference](../../cli/cli-ref/application-load-balancer/cli-ref/virtual-host/update.md).

- Terraform {#tf}

  With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
  
  Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
  
  For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../terraform/index.md).

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

  1. Describe the updated virtual host parameters in the configuration file. With Terraform, you can create virtual hosts with different route [types](../concepts/http-router.md#routes-types):

      {% list tabs group=alb_route_type%}

      - HTTP {#http}

        ```hcl
        resource "yandex_alb_virtual_host" "my-virtual-host" {
          name           = "<virtual_host_name>"
          http_router_id = "<HTTP_router_ID>"
        
          rate_limit {
            all_requests {
              per_second = <requests_per_second>
              # or per_minute = <requests_per_minute>
            }
            requests_per_ip {
              per_second = <requests_per_second>
              # or per_minute = <requests_per_minute>
            }
          }
        
          route {
            name                      = "<route_name>"
            disable_security_profile  = true|false
        
            http_route {
              http_match {
                http_method = ["<HTTP_method_1>","<HTTP_method_2>",...,"<HTTP_method_n>"]
                path {
                  prefix = "/<request_path_prefix>/"
                  # or exact = "<request_path>"
                  # or regex = "<regular_expression>"
                }
              }
        
              http_route_action {
                backend_group_id  = "<backend_group_ID>"
                host_rewrite      = "<Host_header_value>"
                timeout           = "<connection_timeout>s"
                idle_timeout      = "<idle_timeout>s"
                prefix_rewrite    = "<new_request_path_prefix>/"
                rate_limit {
                  all_requests {
                    per_second = <requests_per_second>
                    # or per_minute = <requests_per_minute>
                  }
                  requests_per_ip {
                    per_second = <requests_per_second>
                    # or per_minute = <requests_per_minute>
                  }
                }
              }
            }
          }
        
          authority        = ["<domain_1>","<domain_2>",...,"<domain_n>"]
        
          modify_request_headers {
            name           = "<header_name>"
            append         = "<string_added_to_header_content>"
            # or replace  = "<new_header_content>"
            # or remove   = true|false
          }
        
          modify_response_headers {
            name           = "<header_name>"
            append         = "<string_added_to_header_content>"
            # or replace  = "<new_header_content>"
            # or remove   = true|false
          }
        
          route_options {
            security_profile_id = "<security_profile_ID>"
          }
        }
        ```

        Where:

        * `yandex_alb_virtual_host`: Virtual host description:

            * `name`: Virtual host name. Follow these naming requirements:
            
                * Length: between 3 and 63 characters.
                * It can only contain lowercase Latin letters, numbers, and hyphens.
                * It must start with a letter and cannot end with a hyphen.
            
            * `http_router_id`: HTTP router ID.
            * `rate_limit`: Request rate limit for the entire virtual host (optional).
                * `all_requests`: Limit on all requests per second or per minute (optional):
                    * `per_second`: Maximum number of incoming requests to the virtual host per second.
                    * `per_minute`: Maximum number of incoming requests to the virtual host per minute.
            
                    The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.
                * `requests_per_ip`: Additionally limits requests for each IP address per second or per minute (optional):
                    * `per_second`: Maximum number of incoming requests from a single IP address to the virtual host per second.
                    * `per_minute`: Maximum number of incoming requests from a single IP address to the virtual host per minute.
            
                    The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.

            * `route`: Virtual host route description:

                * `name`: Route name.
                * `disable_security_profile`: Disabling the [Yandex Smart Web Security](../../smartwebsecurity/index.md) [security profile](../../smartwebsecurity/concepts/profiles.md) (optional). The possible values are `true` (the profile is disabled) or `false` (the profile is enabled). The default value is `false`: the security profile is enabled.

                * `http_route`: Route description for HTTP traffic:
                
                    * `http_match`: Parameter for filtering incoming HTTP requests (optional):
                
                        * `http_method`: List of HTTP [methods](https://en.wikipedia.org/wiki/HTTP#Request_methods) for which requests will be routed (optional). By default, requests with any methods are routed.
                        * `path`: Optionally, parameters for filtering the path of an incoming request:
                
                            * `exact`: Route requests with the same path as the specified one. For example, to route all requests, specify the `/` path.
                            * `prefix`: Route requests whose path starts with the specified prefix.
                            * `regex`: Route requests whose path matches the specified [RE2](https://github.com/google/re2/wiki/Syntax) [regular expression](https://en.wikipedia.org/wiki/Regular_expression), e.g., `\/[a-z]{10}[0-9]{3}\/`.
                
                            The `exact`, `prefix`, and `regex` parameters are mutually exclusive: you can use only one of them.
                
                    * `http_route_action`: Action applied to HTTP traffic.
                
                        * `backend_group_id`: ID of the [backend group](../concepts/backend-group.md) located in the same folder as the [HTTP router](../concepts/http-router.md) and virtual host of the new route.
                        * `host_rewrite`: Replacing the Host header in the request with the specified value (optional). You specify the `auto_host_rewrite` parameter instead of the `host_rewrite` parameter; in this case the Host header in the request will be automatically replaced with the address of the target [VM](../../compute/concepts/vm.md).
                        * `timeout`: Maximum connection time in seconds (optional). The default value is 60 seconds.
                        * `idle_timeout`: Maximum connection idle timeout (keep-alive time) (optional). If not specified, the idle connection will be terminated immediately.
                        * `prefix_rewrite`: Value to replace the path or part of the path specified in the `path` parameter (optional).
                        * `rate_limit`: Limits the number of requests per unit of time (optional):
                          
                          * `all_requests`: Limits all incoming requests (optional):
                          
                              * `per_second`: Maximum number of incoming requests to a route per second.
                              * `per_minute`: Maximum number of incoming requests to a route per minute.
                          
                              The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.
                          * `requests_per_ip`: Limits incoming requests from a single IP address (optional):
                          
                              * `per_second`: Maximum number of incoming requests to a route from a single IP address per second.
                              * `per_minute`: Maximum number of incoming requests to a route from a single IP address per minute.
                          
                              The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.

            * `authority`: HTTP/1.1 `Host` (HTTP/2 `authority`) header domains associated with this virtual host. You can use wildcards, e.g., `*.foo.com` or `*-bar.foo.com`. For gRPC traffic, you may specify `*` or the the load balancer's IP address.
            
                This is an optional parameter. If not specified, all traffic will be routed to this virtual host.
            * `modify_request_headers`: HTTP request header modification settings. Possible parameters:
            
                * `name`: Modified header name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
                * `append`: Add a row to the current header value.
                * `replace`: Completely replace the current header value.
                * `remove`: Delete the header. Both the header value and the header itself will be removed. The possible values are `true` or `false`.
            
                This is an optional parameter; if omitted, request headers are provided to the backend unchanged.
            
            * `modify_response_headers`: HTTP response header modification settings. Possible parameters:
            
                * `name`: Modified header name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
                * `append`: Add a row to the current header value.
                * `replace`: Completely replace the current header value.
                * `remove`: Delete the header. Both the header value and the header itself will be removed. The possible values are `true` or `false`.
            
                This is an optional parameter; if omitted, response headers are provided to the client unchanged.
            * `route_options`: Additional virtual host parameters (optional):
                * `security_profile_id`: Security profile ID. A security profile allows you to filter incoming requests, enable [WAF](../../smartwebsecurity/concepts/waf.md), and set limits on the number of requests for protection against malicious activity. For more information, see [Security profiles](../../smartwebsecurity/concepts/profiles.md).

      - gRPC {#grpc}

        ```hcl
        resource "yandex_alb_virtual_host" "my-virtual-host" {
          name           = "<virtual_host_name>"
          http_router_id = "<HTTP_router_ID>"
        
          rate_limit {
            all_requests {
              per_second = <requests_per_second>
              # or per_minute = <requests_per_minute>
            }
            requests_per_ip {
              per_second = <requests_per_second>
              # or per_minute = <requests_per_minute>
            }
          }
        
          route {
            name                      = "<route_name>"
            disable_security_profile  = true|false
        
            grpc_route {
              grpc_match {
                fqmn {
                  prefix = "/<request_FQMN_prefix>"
                  # or exact = "<request_FQMN>"
                  # or regex = "<regular_expression>"
                }
              }
        
              grpc_route_action {
                backend_group_id  = "<backend_group_ID>"
                host_rewrite      = "<Host_header_value>"
                max_timeout       = "<connection_timeout>s"
                idle_timeout      = "<idle_timeout>s"
                rate_limit {
                  all_requests {
                    per_second = <requests_per_second>
                    # or per_minute = <requests_per_minute>
                  }
                  requests_per_ip {
                    per_second = <requests_per_second>
                    # or per_minute = <requests_per_minute>
                  }
                }
              }
            }
          }
        
          authority        = ["<domain_1>","<domain_2>",...,"<domain_n>"]
        
          modify_request_headers {
            name           = "<header_name>"
            append         = "<string_added_to_header_content>"
            # or replace  = "<new_header_content>"
            # or remove   = true|false
          }
        
          modify_response_headers {
            name           = "<header_name>"
            append         = "<string_added_to_header_content>"
            # or replace  = "<new_header_content>"
            # or remove   = true|false
          }
        
          route_options {
            security_profile_id = "<security_profile_ID>"
          }
        }
        ```

        Where:

        * `yandex_alb_virtual_host`: Virtual host description:

            * `name`: Virtual host name. Follow these naming requirements:
            
                * Length: between 3 and 63 characters.
                * It can only contain lowercase Latin letters, numbers, and hyphens.
                * It must start with a letter and cannot end with a hyphen.
            
            * `http_router_id`: HTTP router ID.
            * `rate_limit`: Request rate limit for the entire virtual host (optional).
                * `all_requests`: Limit on all requests per second or per minute (optional):
                    * `per_second`: Maximum number of incoming requests to the virtual host per second.
                    * `per_minute`: Maximum number of incoming requests to the virtual host per minute.
            
                    The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.
                * `requests_per_ip`: Additionally limits requests for each IP address per second or per minute (optional):
                    * `per_second`: Maximum number of incoming requests from a single IP address to the virtual host per second.
                    * `per_minute`: Maximum number of incoming requests from a single IP address to the virtual host per minute.
            
                    The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.

            * `route`: Virtual host route description:

                * `name`: Route name.
                * `disable_security_profile`: Disabling the [Yandex Smart Web Security](../../smartwebsecurity/index.md) [security profile](../../smartwebsecurity/concepts/profiles.md) (optional). The possible values are `true` (the profile is disabled) or `false` (the profile is enabled). The default value is `false`: the security profile is enabled.

                * `grpc_route`: Route description for gRPC traffic:
                
                    * `grpc_match.fqmn`: Parameter for filtering incoming gRPC requests by FQMN (optional):
                
                        * `exact`: Route requests with the same FQMN as the specified one.
                        * `prefix`: Route requests whose FQMN starts with the specified prefix. For example, you can specify the first word of the service name: `/helloworld`.
                        * `regex`: Route requests whose FQMN matches the specified [RE2](https://github.com/google/re2/wiki/Syntax) [regular expression](https://en.wikipedia.org/wiki/Regular_expression). For example: `\/[a-z]{10}[0-9]{3}`.
                
                        The `exact`, `prefix`, and `regex` parameters are mutually exclusive: you can use only one of them.
                        
                    * `grpc_route_action`: Action applied to gRPC traffic.
                
                        * `backend_group_id`: ID of the [backend group](../concepts/backend-group.md) located in the same folder as the new route's [HTTP router](../concepts/http-router.md) and virtual host.
                        * `host_rewrite`: Replacing the Host header in the request with the specified value (optional). You can specify `auto_host_rewrite` instead of `host_rewrite`, in which case the Host header in the request will be automatically replaced with the target [VM](../../compute/concepts/vm.md) address.
                        * `--request-max-timeout`: Maximum request timeout in seconds (optional). You can specify a shorter timeout in the `grpc-timeout` request HTTP header. The default value is 60 seconds.
                        * `idle_timeout`: Maximum connection idle timeout (keep-alive time) (optional). If not specified, the idle connection will be terminated immediately.
                        * `rate_limit`: Limits the number of requests per unit of time (optional):
                          
                          * `all_requests`: Limits all incoming requests (optional):
                          
                              * `per_second`: Maximum number of incoming requests to a route per second.
                              * `per_minute`: Maximum number of incoming requests to a route per minute.
                          
                              The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.
                          * `requests_per_ip`: Limits incoming requests from a single IP address (optional):
                          
                              * `per_second`: Maximum number of incoming requests to a route from a single IP address per second.
                              * `per_minute`: Maximum number of incoming requests to a route from a single IP address per minute.
                          
                              The `per_second`, and `per_minute` parameters are mutually exclusive: you can use only one of them.

            * `authority`: HTTP/1.1 `Host` (HTTP/2 `authority`) header domains associated with this virtual host. You can use wildcards, e.g., `*.foo.com` or `*-bar.foo.com`. For gRPC traffic, you may specify `*` or the the load balancer's IP address.
            
                This is an optional parameter. If not specified, all traffic will be routed to this virtual host.
            * `modify_request_headers`: HTTP request header modification settings. Possible parameters:
            
                * `name`: Modified header name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
                * `append`: Add a row to the current header value.
                * `replace`: Completely replace the current header value.
                * `remove`: Delete the header. Both the header value and the header itself will be removed. The possible values are `true` or `false`.
            
                This is an optional parameter; if omitted, request headers are provided to the backend unchanged.
            
            * `modify_response_headers`: HTTP response header modification settings. Possible parameters:
            
                * `name`: Modified header name, e.g., `Host`, `User-Agent`, `X-Forwarded-For`, `Strict-Transport-Security`, etc.
                * `append`: Add a row to the current header value.
                * `replace`: Completely replace the current header value.
                * `remove`: Delete the header. Both the header value and the header itself will be removed. The possible values are `true` or `false`.
            
                This is an optional parameter; if omitted, response headers are provided to the client unchanged.
            * `route_options`: Additional virtual host parameters (optional):
                * `security_profile_id`: Security profile ID. A security profile allows you to filter incoming requests, enable [WAF](../../smartwebsecurity/concepts/waf.md), and set limits on the number of requests for protection against malicious activity. For more information, see [Security profiles](../../smartwebsecurity/concepts/profiles.md).

      {% endlist %}

      Learn more about the properties of Terraform resources in the relevant provider guide: [yandex_alb_virtual_host](../../terraform/resources/alb_virtual_host.md).
  1. Update the resources:

      1. In the terminal, navigate to the configuration file directory.
      1. Make sure the configuration is correct using this command:
      
         ```bash
         terraform validate
         ```
      
         If the configuration is valid, you will get this message:
      
         ```bash
         Success! The configuration is valid.
         ```
      
      1. Run this command:
      
         ```bash
         terraform plan
         ```
      
         You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
      1. Apply the configuration changes:
      
         ```bash
         terraform apply
         ```
      
      1. Type `yes` and press **Enter** to confirm the changes.
      
      Terraform will update the required resources. You can check the new resources and their settings using the [management console](https://console.yandex.cloud) or this [CLI](../../cli/index.md) command:

      ```bash
      yc alb virtual-host get <virtual_host_name> \
        --http-router-name <HTTP_router_name>
      ```

      {% note warning "Timeouts" %}
      
      The Terraform provider limits the execution time for operations with Application Load Balancer HTTP routers and virtual hosts to 10 minutes.
      
      Operations in excess of this time will be interrupted.
      
      {% cut "How do I modify these limits?" %}
      
      Add the `timeouts` section to the descriptions of the HTTP router and virtual host (the `yandex_alb_http_router` and `yandex_alb_virtual_host` resources, respectively).
      
      Here is an example:
      
      ```hcl
      resource "yandex_alb_http_router" "<router_name>" {
        ...
        timeouts {
          create = "60m"
          update = "60m"
          delete = "60m"
        }
      }
      ```
      
      {% endcut %}
      
      {% endnote %}

- API {#api}

  Use the [update](../api-ref/VirtualHost/update.md) REST API method for the [VirtualHost](../api-ref/VirtualHost/index.md) resource or the [VirtualHostService/Update](../api-ref/grpc/VirtualHost/update.md) gRPC API call.

{% endlist %}

## Deleting a virtual host {#delete-vh}

To delete a virtual host:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) containing your virtual host.
  1. Navigate to **Application Load Balancer**.
  1. In the left-hand panel, click ![route](../../_assets/console-icons/route.svg) **HTTP routers** and select the [HTTP router](../concepts/http-router.md) that contains the virtual host.
  1. On the page that opens, under **Virtual hosts**, click ![ellipsis](../../_assets/console-icons/ellipsis.svg) next to the virtual host and select ![trash-bin](../../_assets/console-icons/trash-bin.svg) **Delete**.
  1. In the window that opens, confirm the deletion.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. See the description of the CLI command for deleting a virtual host:

      ```bash
      yc alb virtual-host delete --help
      ```
  1. View the list of HTTP routers in the default folder:
     
     ```bash
     yc alb http-router list
     ```
     
     Result:
     
     ```text
     +----------------------+--------------------+-------------+-------------+
     |          ID          |        NAME        | VHOST COUNT | ROUTE COUNT |
     +----------------------+--------------------+-------------+-------------+
     | ds76j5n6a39g******** | sample-http-router |           1 |           2 |
     | ds76jk27sdf3******** | new-http-router    |           2 |           7 |
     +----------------------+--------------------+-------------+-------------+
     ```
  1. View the list of virtual hosts in an HTTP router by specifying the router name or ID, respectively, in the `--http-router-name` or `--http-router-id` parameter:
     
     ```bash
     yc alb virtual-host list \
       --http-router-name <HTTP_router_name> \
       --http-router-id <HTTP_router_ID>
     ```
     
     Result:
     
     ```text
     +-------------------+-------------+-------------+----------------------+
     |        NAME       | AUTHORITIES | ROUTE COUNT | SECURITY PROFILE ID  |
     +-------------------+-------------+-------------+----------------------+
     | my-virtual-host   | *           |           1 | fevu5fnuk6vf******** |
     | test-virtual-host | example.com |           2 | fevug3d25bv6******** |
     +-------------------+-------------+-------------+----------------------+
     ```
  1. To delete a virtual host, put in its name and run this command:

      ```bash
      yc alb virtual-host delete <virtual_host_name> \
        --http-router-name <HTTP_router_name>
      ```

      Where `--http-router-name` is the HTTP router name. Instead of the HTTP router name, you can provide its ID in the `--http-router-id` parameter.

  For more information about the `yc alb virtual-host delete` command, see the [CLI reference](../../cli/cli-ref/application-load-balancer/cli-ref/virtual-host/delete.md).

- Terraform {#tf}

  With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
  
  Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
  
  For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../terraform/index.md).

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

  To delete a virtual host created with Terraform:

  1. Open the Terraform configuration file and remove the fragment describing the virtual host (the `yandex_alb_virtual_host` resource).

      {% cut "Example of a virtual host description in a Terraform configuration" %}

      ```hcl
      resource "yandex_alb_virtual_host" "my-virtual-host" {
        name           = "<virtual_host_name>"
        http_router_id = "<HTTP_router_ID>"
      
        rate_limit {
          all_requests {
            per_second = <requests_per_second>
            # or per_minute = <requests_per_minute>
          }
          requests_per_ip {
            per_second = <requests_per_second>
            # or per_minute = <requests_per_minute>
          }
        }
      
        route {
          name                      = "<route_name>"
          disable_security_profile  = true|false
      
          http_route {
            http_match {
              http_method = ["<HTTP_method_1>","<HTTP_method_2>",...,"<HTTP_method_n>"]
              path {
                prefix = "/<request_path_prefix>/"
                # or exact = "<request_path>"
                # or regex = "<regular_expression>"
              }
            }
      
            http_route_action {
              backend_group_id  = "<backend_group_ID>"
              host_rewrite      = "<Host_header_value>"
              timeout           = "<connection_timeout>s"
              idle_timeout      = "<idle_timeout>s"
              prefix_rewrite    = "<new_request_path_prefix>/"
              rate_limit {
                all_requests {
                  per_second = <requests_per_second>
                  # or per_minute = <requests_per_minute>
                }
                requests_per_ip {
                  per_second = <requests_per_second>
                  # or per_minute = <requests_per_minute>
                }
              }
            }
          }
        }
      
        authority        = ["<domain_1>","<domain_2>",...,"<domain_n>"]
      
        modify_request_headers {
          name           = "<header_name>"
          append         = "<string_added_to_header_content>"
          # or replace  = "<new_header_content>"
          # or remove   = true|false
        }
      
        modify_response_headers {
          name           = "<header_name>"
          append         = "<string_added_to_header_content>"
          # or replace  = "<new_header_content>"
          # or remove   = true|false
        }
      
        route_options {
          security_profile_id = "<security_profile_ID>"
        }
      }
      ```

      {% endcut %}

  1. Update the resources:

      1. In the terminal, navigate to the configuration file directory.
      1. Make sure the configuration is correct using this command:
      
         ```bash
         terraform validate
         ```
      
         If the configuration is valid, you will get this message:
      
         ```bash
         Success! The configuration is valid.
         ```
      
      1. Run this command:
      
         ```bash
         terraform plan
         ```
      
         You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
      1. Apply the configuration changes:
      
         ```bash
         terraform apply
         ```
      
      1. Type `yes` and press **Enter** to confirm the changes.

      Terraform will update the required resources. You can check for your resources and their settings using the [management console](https://console.yandex.cloud) or this [CLI](../../cli/index.md) command:

      ```bash
      yc alb virtual-host list \
        --http-router-name <HTTP_router_name>
      ```

      {% note warning "Timeouts" %}
      
      The Terraform provider limits the execution time for operations with Application Load Balancer HTTP routers and virtual hosts to 10 minutes.
      
      Operations in excess of this time will be interrupted.
      
      {% cut "How do I modify these limits?" %}
      
      Add the `timeouts` section to the descriptions of the HTTP router and virtual host (the `yandex_alb_http_router` and `yandex_alb_virtual_host` resources, respectively).
      
      Here is an example:
      
      ```hcl
      resource "yandex_alb_http_router" "<router_name>" {
        ...
        timeouts {
          create = "60m"
          update = "60m"
          delete = "60m"
        }
      }
      ```
      
      {% endcut %}
      
      {% endnote %}

- API {#api}

  Use the [delete](../api-ref/VirtualHost/delete.md) REST API method for the [VirtualHost](../api-ref/VirtualHost/index.md) resource or the [VirtualHostService/Delete](../api-ref/grpc/VirtualHost/delete.md) gRPC API call.

{% endlist %}