> For the complete documentation index, see [llms.txt](https://kb.pvhostvm.ru/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kb.pvhostvm.ru/hostvm-vdi/hostvm-vdi-installation-guide/high-availability/optional-config/nginx-lb.md).

# Настройка nginx для балансировки подключений

Данная инструкция описывает альтернативную конфигурацию балансировки подключений к пользовательскому порталу с помощью nginx (без использования HAProxy).

В примере приведено содержание `/etc/nginx/nginx.conf` с балансировкой двух порталов пользователя, находящихся на брокерах.

## Пример конфигурации <a href="#config-example" id="config-example"></a>

{% code overflow="wrap" %}

```
upstream user_portal {
     #В случае, если пользовательский портал настроен на туннелере, нужно указать порт :1443
     server 10.1.99.18:443; #адрес портала №1
     server 10.1.99.19:443; #адрес портала №2
     least_conn; #пример метода балансировки, по умолчанию используется round-robin
}

map $http_x_forwarded_proto $thescheme {
    default $scheme;
    https https;
}

server {
    listen 443 ssl;

    #Сертификаты генерируются центром сертификации
    #Использование самоподписанных сертификатов в продуктовой среде не рекомендуется
	  ssl_certificate /etc/certs/server.pem; #путь до сертификата
    ssl_certificate_key /etc/certs/key.pem; #путь до ключа

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $thescheme;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass https://user_portal;
    }
}

```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://kb.pvhostvm.ru/hostvm-vdi/hostvm-vdi-installation-guide/high-availability/optional-config/nginx-lb.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
