В прошлом материале мы установили qBittorrent.
В данной статье рассмотрим убирание qBittorrent за NGINX и получение сертификатов от Let’s Encrypt в UBUNTU 24.10.Данное решение рекомендую для публикации сервиса qBittorrent в сети Интернет для получение постоянного доступа к нему.Так же NGINX позволит на мой взгляд гибче управлять доступом и возможность использовать такие решения как fail2ban и т.п.Данный материал предполагает наличие активного домена и доступ из сети интернет к хосту на котором будет установлен NGINX.
Наш план:
- Создание A записи в DNS зоне
- Установка NGINX и Certbot
- Создание конфигурации NGINX
- Получение сертификата
- Тестирование
Создание А записи в DNS:
Создаем DNS запись, для теста я создал test.marvins.ru
Устанавливаем Certbot и NGINX:
sudo apt install python3-certbot-nginx Installing: python3-certbot-nginx Installing dependencies: certbot python3-certbot python3-parsedatetime nginx python3-configargparse python3-rfc3339 nginx-common python3-icu python3-tz python3-acme python3-josepy Suggested packages: python-certbot-doc nginx-doc python-certbot-nginx-doc python3-certbot-apache ssl-cert fcgiwrap python-acme-doc Summary: Upgrading: 0, Installing: 12, Removing: 0, Not Upgrading: 0 Download size: 1775 kB Space needed: 7684 kB / 5090 MB available Continue? [Y/n]
Создание конфигурации NGINX:
Создаем пару директорий и навешиваем на них владельцем www-data:
sudo mkdir /var/log/nginx/test /var/www/test sudo chown www-data:www-data /var/log/nginx/test /var/www/test
Создаем конфигурацию NGINX:
sudo vi /etc/nginx/conf.d/test.marvins.ru.conf
server { listen 80; root /var/www/test/; server_name test.marvins.ru; access_log /var/log/nginx/test/access.log; error_log /var/log/nginx/test/error.log error; add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;"; location / { proxy_pass http://10.210.210.147:8080; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location /.well-known/ { root /var/www/test/; } }
Проверяем корректность конфигурации NGINX:
sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Перечитываем конфигурацию NGINX:
sudo nginx -s reload
Запускаем запрос сертификата:
sudo certbot --nginx -d test.marvins.ru
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for test.marvins.ru
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/test.marvins.ru/fullchain.pem
Key is saved at: /etc/letsencrypt/live/test.marvins.ru/privkey.pem
This certificate expires on 2025-05-17.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
Deploying certificate
Successfully deployed certificate for test.marvins.ru to /etc/nginx/conf.d/test.marvins.ru.conf
Congratulations! You have successfully enabled HTTPS on https://test.marvins.ru
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let’s Encrypt: https://letsencrypt.org/donate
* Donating to EFF: https://eff.org/donate-le
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
server {
root /var/www/test/;
server_name test.marvins.ru;
access_log /var/log/nginx/test/access.log;
error_log /var/log/nginx/test/error.log error;
add_header Strict-Transport-Security «max-age=15768000; includeSubDomains; preload;»;
location / {
proxy_pass http://10.210.210.147:8080;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection «upgrade»;
}
location /.well-known/ {
root /var/www/test/;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/test.marvins.ru/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/test.marvins.ru/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = test.marvins.ru) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name test.marvins.ru;
return 404; # managed by Certbot
}
Приводим в порядок /etc/nginx/conf.d/test.marvins.ru.conf
server { if ($host = test.marvins.ru) { return 301 https://$host$request_uri; } } server { root /var/www/test/; server_name test.marvins.ru; access_log /var/log/nginx/test/access.log; error_log /var/log/nginx/test/error.log error; listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/test.marvins.ru/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/test.marvins.ru/privkey.pem; include /etc/letsencrypt/options-ssl-nginx.conf; ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;"; location / { proxy_pass http://10.210.210.147:8080; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location /.well-known/ { root /var/www/test/; } }
Проверяем корректность конфигурации NGINX:
sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Перечитываем конфигурацию NGINX:
sudo nginx -s reload
Открываем в браузере (в моем случае — https://test.marvins.ru/)
На этом все)