1 前言
一个问题,一篇文章,一出故事。
笔者在生产环境部署了PostFix邮件中继,由于邮件管理员希望有一个管理UI,因此笔者整理此文。
如果你尚未部署PostFix邮件中继,你可以参阅以下章节,
2 最佳实践
2.1 环境配置
2.1.1 部署LNMP环境
请参阅以下章节安装Nginx,
请参阅以下章节安装PHP-FPM 8.x
请参阅以下章节安装MariaDB,
2.1.2 安装所需的软件包
dnf install -y wget
2.2 创建MySQL数据库
2.2.1 登录MySQL数据库
mysql -u root -p
2.2.2 配置应用数据库
create database postfix; create user 'postfix'@'127.0.0.1' identified by 'postfixpwd'; grant all privileges on postfix.* to 'postfix'@'127.0.0.1'; flush privileges;
2.3 部署软件包
2.3.1 下载软件包
wget -P /opt https://github.com/postfixadmin/postfixadmin/archive/refs/tags/postfixadmin-3.3.13.tar.gz
2.3.2 解压软件包
cd /opt && tar -xf postfixadmin-3.3.13.tar.gz
2.3.3 配置软件包
ln -s postfixadmin-postfixadmin-3.3.13 postfixadmin mkdir -p /var/www/html/ ln -s /opt/postfixadmin/public /var/www/html/postfixadmin mkdir /opt/postfixadmin/templates_c chmod 755 -R /opt/postfixadmin/templates_c chown apache: -R /opt/postfixadmin/templates_c
2.4 配置虚拟服务器
2.4.1 创建虚拟服务器配置
vim /etc/nginx/conf.d/postfix.conf
加入如下配置,
upstream php-handler { server 127.0.0.1:9000; } server { listen 80; server_name postfix.cmdschool.org; server_tokens off; return 301 https://$server_name$request_uri; } server { listen 443 ssl http2; server_name postfix.cmdschool.org; root /var/www/html/postfixadmin; ssl_certificate /etc/ssl/wildcard.cmdschool.org-2023-nginx.crt; ssl_certificate_key /etc/ssl/wildcard.cmdschool.org-2023.key; index index.php index.html; location ~ \.php(?:$|/) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; set $path_info $fastcgi_path_info; try_files $fastcgi_script_name =404; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $path_info; fastcgi_param HTTPS on; fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice fastcgi_param front_controller_active true; # Enable pretty urls fastcgi_pass php-handler; fastcgi_intercept_errors on; fastcgi_request_buffering off; fastcgi_max_temp_file_size 0; } }
2.4.2 重载服务使配置生效
systemctl reload nginx.service
2.5 配置Postfix Admin
2.5.1 获取管理员密码
php -r 'echo password_hash("setuppwd", PASSWORD_DEFAULT);'
命令输出如下,
$2y$10$VGdQvNWht.xlNTDLb2XlleG4gX6o/WnpXRTzlzfP6GCt0c3bIS/xe
2.5.2 修改服务配置
cp /opt/postfixadmin/config.inc.php /opt/postfixadmin/config.local.php vim /opt/postfixadmin/config.local.php
修改如下配置,
<?php $CONF['configured'] = true; $CONF['setup_password'] = '$2y$10$VGdQvNWht.xlNTDLb2XlleG4gX6o/WnpXRTzlzfP6GCt0c3bIS/xe'; $CONF['database_type'] = 'mysqli'; $CONF['database_host'] = '127.0.0.1'; $CONF['database_user'] = 'postfix'; $CONF['database_password'] = 'postfixpwd'; $CONF['database_name'] = 'postfix'; ?>
2.5.3 测试服务配置
https://postfix.cmdschool.org/
如果遇到如下错误,
Fatal error: Uncaught Exception: DEBUG INFORMATION: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'postfix.config' doesn't exist
Check your error_log for the failed query in /opt/postfixadmin-postfixadmin-3.3.13/functions.inc.php:1872 Stack trace: #0 /opt/postfixadmin-postfixadmin-3.3.13/functions.inc.php(1821): db_query('SELECT value FR...', Array) #1 /opt/postfixadmin-postfixadmin-3.3.13/functions.inc.php(2159): db_query_one('SELECT value FR...') #2 /opt/postfixadmin-postfixadmin-3.3.13/public/login.php(40): check_db_version() #3 {main} thrown in /opt/postfixadmin-postfixadmin-3.3.13/functions.inc.php on line 1872
你需要运行如下程序完成基本的配置,
https://postfix.cmdschool.org/setup.php
如上图所示,
填写“setup password”,本范例的设置为“setuppwd”
单击【login with setup_password】即可完成设置
然后,你需要继续设置超级管理员的账号和密码,
如上图所示,
填写“setup password”,本范例的设置为“setuppwd”
填写“Admin”,本范例的设置为“superadmin@cmdschool.org”
填写“Password”,本范例的设置为“superadmin@123”
单击【Add Admin】即可完成设置
2.5.4 测试服务登录
https://postfix.cmdschool.org/login.php
如上图所示,
填写“Admin”,本范例的设置为“superadmin@cmdschool.org”
填写“Password”,本范例的设置为“superadmin@123”
单击【Login】即可完成登录
参阅文档
=================
官方gitHub
————–
https://github.com/postfixadmin/postfixadmin
安装配置文档
————–
https://postfix-configuration.readthedocs.io/en/latest/postfixadmin/#download-postfixadmin
https://github.com/postfixadmin/postfixadmin/blob/master/INSTALL.TXT
错误处理
—————-
https://askubuntu.com/questions/1025168/postfixadmin-error-table-postfixadmin-config-doesnt-exist
没有评论