自学内容网 自学内容网

Postfix+Dovecot+Roundcube开源邮件系统搭建系列5:Roundcube安装配置(含Nginx+PHP部署配置)

1. PHP安装配置

参考wordpress 6.5.2版本安装记录 中关于PHP安装方法,此处不再详述。

修改php-fpm的启动用户和组为vmail,这一步是和nginx配置相呼应。配置文件/etc/opt/remi/php83/php-fpm.d/www.conf 下面几个配置:

user vmail
group vmail
listen.acl_users = vmail
#access.log = /var/opt/remi/php83/log/php-fpm/$pool.access.log #可选配置
listen = /var/opt/remi/php83/run/php-fpm/www.sock # 这个配置需要记录一下,下面nginx的配置需要用到

配置启动php-fpm:

systemctl enable php83-php-fpm
systemctl start php83-php-fpm

2. Nginx安装配置

2.1 安装nginx

yum install nginx

2.2 /etc/nginx/nginx.conf 配置文件

user  vmail; #以vmail身份运行,下面会涉及相关的配置
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    # 日志文件位置
    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

2.3 /etc/nginx/conf.d/roundcube.conf 配置文件

在/etc/nginx/conf.d目录创建roundcube.conf配置文件,配置相关参数(下面参数仅供参考,里面很多是跟安全有关的配置):

    send_timeout            60;
    client_body_timeout     60;
    client_header_timeout   60;

    client_max_body_size            50m;
    client_body_buffer_size         1m;
    client_header_buffer_size       1k;
    large_client_header_buffers     4 8k;
    proxy_read_timeout              180;
    server_tokens                   off; # default on
    server_names_hash_bucket_size   512;
    map_hash_max_size               13107200;

    gzip on;
    gzip_disable     "msie6";

    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 2;
    gzip_http_version 1.1;
    gzip_min_length 256;
    gzip_types text/plain text/css text/xml text/javascript text/x-json application/json application/x-javascript application/javascript application/xml
 application/xml+rss;
    ssl_session_timeout  5m;
    ssl_session_cache    shared:SSL:10m;
    ssl_session_tickets  off;
    ssl_protocols        TLSv1.2 TLSv1.3;
    ssl_ciphers          "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-S
HA384:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES256-SHA:HIGH:!MEDIUM:!LOW:!aNUL
L:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4:@STRENGTH";
    ssl_prefer_server_ciphers   on;
    proxy_ssl_verify     off;

server {
        listen 80;
        server_name www.mailabc.cn;
        rewrite ^(.*)$ https://$host$1 permanent;
}

server {
        listen 443 ssl http2;

        # server_name  @web_name
        server_name www.mailabc.cn;
        # 这里配SSL证书
        ssl_certificate     /var/sslcert/www.mailabc.cn.pem;
        ssl_certificate_key /var/sslcert/www.mailabc.cn.key;
        ssl_dhparam         /etc/nginx/dhparam.pem;
        ssl_stapling        on;
        ssl_stapling_verify on;
        # 配置roundcube的数据目录,需要提前创建
        root /var/www/roundcube;
        index index.php;
        # 配置fastcgi相关内容
        location ~ \.php$ {
            fastcgi_pass unix:/var/opt/remi/php83/run/php-fpm/www.sock; #该配置对应上述php-fpm的设置
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
}

2.4 创建 /var/www/roundcube 目录

mkdir /var/www/roundcube
chown vmail:vmail /var/www/roundcube

2.5 启动服务

systemctl start nginx
systemctl enable nginx

3. Roundcube配置

3.1 下载程序

下载链接单击此处

3.2 部署Roundcube

3.2.1 解压程序:
tar -zxvf roundcubemail-1.6.7-complete.tar.gz -C /var/www/
cd /var/www/ && mv roundcubemail-1.6.7/* roundcube/
# 设置目录权限为vmail:vmail
chown vmail:vmail -R /var/www/roundcube
3.2.2 初始化数据库:
/* 创建数据库,名称可以自定义 */
CREATE DATABASE roundcube;

/* 初始化数据库 */
USE roundcube;
source /var/www/roundcube/SQL/mysql.initial.sql 

/* 授权用户roundcube对roundcube数据库操作权限,可以自行定义账户名和密码 */
grant all on roundcube.* to roundcube@localhost identified by 'admin123';
FLUSH PRIVILEGES;
3.2.3 config.inc.php 配置文件:

创建配置文件:

cp /var/www/roundcube/config/config.inc.php.sample /var/www/roundcube/config/config.inc.php

修改配置文件内容:

# 配置数据库连接方式,见上面数据库初始化内容
$config['db_dsnw'] = 'mysql://roundcube:admin123@localhost/roundcube';
# smtp采用tls方式连接587端口
$config['smtp_host'] = 'tls://localhost:587';
# 启用installer进行图形界面初始化测试,测试完毕需要删除。我不打算用该配置
#$config['enable_installer'] = true; 
# 忽略检查ssl证书有效性,方便测试用。生产环境不建议启用
$config['smtp_conn_options'] = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
];
3.2.4 安全起见,删除installer目录:
rm -rf /var/www/roundcube/installer/

4. 测试

4.1 登录测试

通过域名或者ip访问roundcube界面,显示如下:

Roundcube登录界面

Roundcube登录界面

登录之后,界面如下:

roundcube主界面

Roundcube主界面

4.2 信件收发测试

写信:

Roundcube写信界面

Roundcube写信界面

读信:

Roundcube读信界面

Roundcube读信界面

至此,本系列文章结束。但是,实际上我们的工作刚开始,还有大量功能等着我们去探索,例如如何修改附件大小、别名邮箱如何处理、自动转发如何配置等等。后续我们将针对相关主题更新文档进行讨论。


原文地址:https://blog.csdn.net/sdexcel/article/details/140412395

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!