Некоторые из моих проектов размещены на домашнем сервере с использованием Apache. У большинства из них есть служба, работающая в фоновом режиме — например, API-интерфейс flask или приложение nextjs — прослушивающее определенный порт для HTTP-соединений. Чтобы иметь доступ к ним извне, у меня был следующий файл конфигурации apache2:
Код: Выделить всё
# /etc/apache2/sites-available/mydomain.com.conf
# This one is a flask web page
ServerName mc.mydomain.com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
Require all granted
ProxyPass / http://127.0.0.1:8765/
ProxyPassReverse / http://127.0.0.1:8765/
# This one is a nextjs app
ServerName cocktail.mydomain.com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
Require all granted
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
# This one is a simple static website
ServerName london.mydomain.com
DocumentRoot /var/www/london
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
# You might know immich, if not I recommend it :)
ServerName immich.mydomain.com
ProxyRequests Off
ProxyVia Full
Require all granted
# Regular HTTP requests
ProxyPass / http://127.0.0.1:2283/ upgrade=websocket
ProxyPassReverse / http://127.0.0.1:2283/
ProxyPreserveHost On
требует https для некоторых незначительных функций.
ChatGPT – пожалуйста, не ненавидьте меня – посоветовал мне просто запустить certbot --apache, и это сотворило бы для меня волшебство. При этом мне казалось, что это должно сработать:
Код: Выделить всё
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: cocktail.mydomain.com
2: immich.mydomain.com
3: london.mydomain.com
4: mc.mydomain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel):
Requesting a certificate for cocktail.mydomain.com and 4 more domains
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/cocktail.mydomain.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/cocktail.mydomain.com/privkey.pem
This certificate expires on 2025-02-26.
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 cocktail.mydomain.com to /etc/apache2/sites-available/mydomain.com-le-ssl.conf
Successfully deployed certificate for immich.mydomain.com to /etc/apache2/sites-available/mydomain.com-le-ssl.conf
Successfully deployed certificate for london.mydomain.com to /etc/apache2/sites-available/mydomain.com-le-ssl.conf
Successfully deployed certificate for mc.mydomain.com to /etc/apache2/sites-available/mydomain.com-le-ssl.conf
Successfully deployed certificate for vault.mydomain.com to /etc/apache2/sites-available/mydomain.com-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://cocktail.mydomain.com, https://immich.mydomain.com, https://london.mydomain.com, https://mc.mydomain.com, and https://vault.mydomain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Код: Выделить всё
# /etc/apache2/sites-available/mydomain.com-le-ssl.conf
ServerName cocktail.mydomain.com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
Require all granted
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
SSLCertificateFile /etc/letsencrypt/live/cocktail.mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/cocktail.mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
ServerName immich.mydomain.com
ProxyRequests Off
ProxyVia Full
Require all granted
# Regular HTTP requests
ProxyPass / http://127.0.0.1:2283/ upgrade=websocket
ProxyPassReverse / http://127.0.0.1:2283/
ProxyPreserveHost On
SSLCertificateFile /etc/letsencrypt/live/cocktail.mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/cocktail.mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
ServerName london.mydomain.com
DocumentRoot /var/www/london
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
SSLCertificateFile /etc/letsencrypt/live/cocktail.mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/cocktail.mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
ServerName mc.mydomain.com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
Require all granted
ProxyPass / http://127.0.0.1:8765/
ProxyPassReverse / http://127.0.0.1:8765/
SSLCertificateFile /etc/letsencrypt/live/cocktail.mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/cocktail.mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
Все, что я проверяю, кажется, на месте, однако я не могу подключиться к ни одной из моих страниц больше нет (через HTTPS я получаю ошибку «400 Bad Request», а через HTTP меня перенаправляют на HTTPS xd).
Небольшой комментарий: при доступе к ним с телефона отключаюсь от моего Wi-Fi вместо того, чтобы получить 400, он некоторое время загружается, а затем истекает время ожидания и выдает ошибку «ERR_CONNECTION_REFUSED».
Подробнее здесь: https://stackoverflow.com/questions/792 ... ache-setup
Мобильная версия