在Linux上配置pgAdmin的SSL可按以下步驟操作:
生成SSL證書和私鑰
使用OpenSSL生成自簽名證書(生產環境建議使用CA簽發的證書):
sudo mkdir -p /etc/pgadmin/ssl
sudo openssl req -new -x509 -days 365 -nodes -keyout /etc/pgadmin/ssl/server.key -out /etc/pgadmin/ssl/server.crt -subj "/CN=localhost"
(若需指定域名/IP,替換-subj
中的/CN=localhost
為對應值,如/CN=pgadmin.example.com
)
配置pgAdmin使用SSL
編輯pgAdmin配置文件(路徑可能因安裝方式不同而異,常見為/etc/pgadmin/pgadmin4.conf
或/usr/lib/python*/site-packages/pgadmin4-web/config_local.py
):
[server]
ssl = on
ssl_cert_file = /etc/pgadmin/ssl/server.crt
ssl_key_file = /etc/pgadmin/ssl/server.key
若通過Web服務器(如Nginx/Apache)代理,需在服務器配置中添加SSL證書路徑。
重啟pgAdmin服務
sudo systemctl restart pgadmin4
(若使用虛擬環境安裝,需先激活環境再重啟)
驗證配置
/var/log/pgadmin/
)確認無錯誤。注意: