linux(ubuntu)中配置apache2当作代理去访问docker服务中(分别是grafana,devlake,python)内容,,其中grafana使用443,devlake使用4000,python使用5000。并使用 Let's Encrypt 证书
时间: 2024-09-30 20:13:24 浏览: 42
在Ubuntu系统中设置Apache作为代理服务器访问Docker容器里的服务(包括Grafana、DevLake和Python应用),你需要进行以下步骤:
1. **安装必要的软件**:
- 更新包列表并安装Apache、mod_proxy和letsencrypt-certbot:
```
sudo apt update && sudo apt install apache2 libapache2-mod-proxy-html python3-certbot-apache
```
2. **配置Apache**:
a. 首先,停止Apache服务并启用HTTPS模块:
```
sudo systemctl stop apache2
sudo a2enmod proxy_http ssl
```
b. 创建一个新的Apache虚拟主机文件,例如`/etc/apache2/sites-available/proxy.conf`,内容如下:
```conf
<VirtualHost *:80>
ServerName your_domain.com
Redirect / https://$server_name$request_uri
</VirtualHost>
<VirtualHost *:443>
ServerName your_domain.com
ProxyPass / http://localhost:4000/
ProxyPassReverse / http://localhost:4000/
ProxyPass /grafana https://localhost:443/grafana
ProxyPassReverse /grafana https://localhost:443/grafana
ProxyPass /devlake https://localhost:4000/devlake
ProxyPassReverse /devlake https://localhost:4000/devlake
ProxyPass /api https://localhost:5000/api
ProxyPassReverse /api https://localhost:5000/api
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/your_domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/your_domain.com/privkey.pem
</VirtualHost>
```
将`your_domain.com`替换为你实际的域名。
3. **启用虚拟主机并启动Apache**:
```
sudo ln -s /etc/apache2/sites-available/proxy.conf /etc/apache2/sites-enabled/
sudo systemctl start apache2
```
4. **获取Let's Encrypt证书**:
```
sudo certbot --nginx
```
按照提示完成证书申请流程。
5. **测试配置**:
- 打开浏览器输入你的域名,应被重定向到HTTPS页面,并通过代理访问相应的端口。
阅读全文