# Настройка доступа портов 80,443 (http/s)

{% hint style="danger" %}
**ВНИМАНИЕ:** Пожалуйста, убедитесь что вы добавили [SSH правила](/dlya-razrabotchikov/nastroika-firewall/nastroika-dostupa-porta-22-ssh.md) ранее&#x20;
{% endhint %}

<details>

<summary>Разрешаем доступ к HTTP(s) только для сетей CloudFlare</summary>

**Применить автоматически:**

1. Выполнить команду:

   ```bash
   wget -q -O - https://gitlab.com/BoxExchanger-public/ufw-cloudflare/-/raw/main/cf_install.sh | sudo sh
   ```
2. Включаем UFW.

   ```
   ufw enable
   ```

\
**Настраиваем вручную:**

1. Создаем папку для хранения скрипта:

   ```bash
   mkdir -p ~/.scripts/cf_ips
   ```
2. Создаем скрипт с следующим содержимым:

   <pre class="language-bash"><code class="lang-bash"><strong>nano ~/.scripts/cf_ips/cf_ips.sh
   </strong></code></pre>

   <pre class="language-bash" data-title="cf_ips.sh" data-line-numbers><code class="lang-bash">#!/bin/sh
   <strong>PATH=$PATH:/sbin
   </strong>wget https://www.cloudflare.com/ips-v4 -qO /tmp/cf_ips
   echo "" >> /tmp/cf_ips
   wget https://www.cloudflare.com/ips-v6 -qO ->> /tmp/cf_ips
   for cfip in `cat /tmp/cf_ips`; do ufw allow proto tcp from $cfip to any port 80,443 comment "Cloudflare IP"; done
   rm /tmp/cf_ips
   </code></pre>
3. Чистим служебный временный файл

   ```bash
   rm /tmp/cf_ips
   ```
4. Выставляем крон(таймер) что бы он обновлял адреса раз в сутки&#x20;

   ```bash
   echo "0 0 * * * ~/.scripts/cf_ips/cf_ips.sh" | crontab -
   ```
5. Включаем UFW.

   ```bash
   ufw enable
   ```

</details>

<details>

<summary>Разрешаем доступ к HTTP(s) для всех сетей</summary>

**ВНИМАНИЕ: эта инструкция для тех кто не использует Cloudflare если вы используете CloudFlare для вашего сайта используется инструкцию выше**

1. Разрешаем доступ 80 и 443

   <pre class="language-bash"><code class="lang-bash"><strong>ufw allow 80
   </strong></code></pre>

   ```bash
   ufw allow 443
   ```
2. Включаем UFW.

   ```bash
   ufw enable
   ```

</details>


---

# Agent Instructions: 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:

```
GET https://manual.boxexchanger.net/dlya-razrabotchikov/nastroika-firewall/nastroika-dostupa-portov-80-443-http-s.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
