最近需要搭建邮件系统,逐个测试了ExtMail、Zimbra和iRedMail,最后选定iRedMail。我喜欢用Nginx,所以尝试着从Apache到Nginx的转换。

1、RoundCube

RoundCube 的配置可参考 Nginx 网站 上的例子。

# roundcube
server {
    listen          80;
    server_name mail.example.com;

    location / {
            rewrite ^ https://mail.example.com permanent;
    }

    location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /usr/share/apache2/roundcubemail$fastcgi_script_name;
    }

}

server {
    listen       443;
    server_name  mail.example.com;

    location / {
        root   /usr/share/apache2/roundcubemail/;
        index  index.php index.html;
    }

     location ~ \.php$ {
        root            /usr/share/apache2/roundcubemail/;
        include         fastcgi_params;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME /usr/share/apache2/roundcubemail$fastcgi_script_name;
        fastcgi_param   SERVER_NAME $http_host;
        fastcgi_ignore_client_abort on;
    }

    ssl                  on;
    ssl_certificate      /etc/ssl/certs/iRedMail_CA.pem;
    ssl_certificate_key  /etc/ssl/private/iRedMail.key;
    ssl_session_timeout  5m;
    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    ssl_prefer_server_ciphers   on;
}

2、phpLDAPadmin

phpLDAPadmin 亦是 php 开发,配置与 RoundCube 类似。

#phpLDAPadmin
server {
    listen       443;
    server_name  ldap.example.com;

    location / {
        root   /usr/share/phpldapadmin/;
        index  index.php index.html;
    }

     location ~ \.php$ {
        root            /usr/share/phpldapadmin/;
        include         fastcgi_params;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME /usr/share/phpldapadmin$fastcgi_script_name;
        fastcgi_param   SERVER_NAME $http_host;
        fastcgi_ignore_client_abort on;
    }

    ssl                  on;
    ssl_certificate      /etc/ssl/certs/iRedMail_CA.pem;
    ssl_certificate_key  /etc/ssl/private/iRedMail.key;
    ssl_session_timeout  5m;
    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    ssl_prefer_server_ciphers   on;
}

3、iReaAdmin

iReaAdmin 是 python 代码,所以采用 uwsgi,Nginx 原生就支持 uwsgi。这一段主要参考了PTMoinMoin 与 Nginx, fastcgi 与 uwsgi 的配置 一文。

准备工作

#安装
sudo -s
add-apt-repository ppa:nginx/stable
add-apt-repository ppa:uwsgi/release
apt-get update
apt-get install nginx uwsgi-python python-virtualenv

#组件配置
cat >/etc/uwsgi-python/apps-enabled/uwsgi.xml << EOF
<uwsgi>
  <limit-as>256</limit-as>
  <processes>6</processes>
  <memory-report/>
  <vhost/>
  <no-site/>
</uwsgi>
EOF

#Python环境预备
mkdir /usr/share/apache2/iredadmin/python-home
virtualenv /usr/share/apache2/iredadmin/python-home

#修改文件属性
chown www-data:www-data /usr/share/apache2/iredadmin/* -R

Nginx 配置如下:

# iRedAdmin
server {
    listen          80;
    server_name iredadmin.example.com;

    location / {
        rewrite ^(.*) https://$server_name$1 permanent;
    }
}

server {
    listen 443;
    server_name ira.example.com;

    access_log  /var/log/nginx/iredadmin.access_log;
    error_log   /var/log/nginx/iredadmin.error_log;

    location / {
        root /usr/share/apache2/iredadmin;
        uwsgi_pass unix:///var/run/uwsgi-python/uwsgi/socket;
        uwsgi_param UWSGI_PYHOME /usr/share/apache2/iredadmin/python-home;
        uwsgi_param UWSGI_CHDIR /usr/share/apache2/iredadmin;
        uwsgi_param UWSGI_SCRIPT iredadmin;
        include uwsgi_params;
    }

    location /static {
        alias /usr/share/apache2/iredadmin/static/;
    }

    ssl                  on;
    ssl_certificate      /etc/ssl/certs/iRedMail_CA.pem;
    ssl_certificate_key  /etc/ssl/private/iRedMail.key;
    ssl_session_timeout  5m;
    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    ssl_prefer_server_ciphers   on;
}

4、启动运行

在 /etc/nginx/sites-enabled 建立以上配置文件。

#重启
/etc/init.d/nginx restart
/etc/init.d/uwsgi-python restart

访问地址:

https://mail.example.com

https://ldap.example.com


https://iredadmin.example.com