我正在使用 phpMyAdmin docker 映像连接到 AWS RDS 实例并需要它使用 SSL。 一切均按照 PMA documentation 的指示进行设置,但不会使用 SSL。
创建容器时,config.user.inc.php 和 rds-combined-ca-bundle.pem 都会被复制到 /etc/phpmyadmin 目录。
登录数据库服务器时,PMA 显示服务器连接:SSL 未被使用。 当 RDS 中的数据库用户设置为 SSL 时,需要登录失败,而当设置为不需要 SSL 时,我可以正常登录。希望有人能帮我解决这个问题。
Docker 组合
version: '3.1'
services:
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
PMA_HOST: somerdsserver.us-east-1.rds.amazonaws.com
PMA_PORT: 3306
restart: always
ports:
- 8081:80
volumes:
- /sessions
- /home/centos/phpmyadmin/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php
- /home/centos/phpmyadmin/rds-combined-ca-bundle.pem:/etc/phpmyadmin/rds-combined-ca-bundle.pem
config.user.inc.php
<?php
// Address of your instance
$cfg['Servers'][$i]['host'] = 'somerdsserver.us-east-1.rds.amazonaws.com';
// Use SSL for connection
$cfg['Servers'][$i]['ssl'] = true;
// Enable SSL verification
$cfg['Servers'][$i]['ssl_verify'] = true;
// You need to have the region CA file and the authority CA file (2019 edition CA for example) in the PEM bundle for it to work
$cfg['Servers'][$i]['ssl_ca'] = '/etc/phpmyadmin/rds-combined-ca-bundle.pem';
您可以在 docker-compose 中创建一个卷并将 apache 配置和证书复制到容器
phpmyadmin:
container_name: phpmyadmin
hostname: phpadmin.domain
image: phpmyadmin:latest
restart: always
build:
context: .
dockerfile: phpmyadmin.dockerfile
ports:
- 8080:443
volumes:
- ./phpmyadmin/000-default.conf:/etc/apache2/sites-enabled/000-default.conf
- ./ssl/cert.pem:/etc/ssl/cert.pem
- ./ssl/cert.key:/etc/ssl/cert.key
phpmyadmin/000-default.conf:
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/ssl/cert.pem
SSLCertificateKeyFile /etc/ssl/cert.key
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
要完成,您需要使用 a2enmod 启用 ssl 并重新启动 apache,在我的例子中,我使用 phpmyadmin.dockerfile :
FROM phpmyadmin
RUN a2enmod ssl
RUN service apache2 restart
就是这样。