centos7 安装 iRedmail 后 给nginx添加虚拟主机

iRedmail安装参考官方文档

https://ywnz.com/linuxyffq/4563.html

准备工作

更新操作系统

yum update -y

安装必要组件

yum install perl perl-core ntpl nmap sudo libidn gmp libaio libstdc++ unzip sysstat wget nc -y

 停止任何安装在该Centos7 Server上面的 MTA服务

systemctl stop postfix
systemctl disable postfix
systemctl stop sendmail
systemctl disable sendmail

修改主机名vi /etc/hostname 改成mail.abc.net

还有/etc/hosts 和,/etc/sysconfig/network 两个地方都要改成IP 主机名形式

127.0.0.1       mail.abc.net localhost

 接着开始安装

bash iReadmail.sh

注册数据库的选择,还有要两次输入密码,第一次是数据库,第二次是管理密码

安装完成后reboot。

进行ssl证书申请 

yum install certbot
certbot certonly --webroot --agree-tos --email abc.net -d mail.abc.net -w /var/www/html/

装好iRedmail之后,用Let's Encrypt生成证书并修改相关位置,使webmail以及SMTP/IMAP都开启ssl。

再根据生成的iRedMail.tips文件,修改mysql(mariadb)的root用户名密码和权限(有需要的话)。

给nginx添加虚拟主机,修改/etc/nginx/sites-enabled里面的两个文件,一个ssl,一个非ssl

新建的虚拟主机要开ssl的话,一样的操作

 certbot certonly -d abc.com -d www.abc.com

出来的选项,选第3个,然后输入绑定的webroot目录,如

/var/www/hosts/abc.com
会生成相应的证书文件。

然后打开非ssl配置文件00-default.conf,在后面添加,因为我要让非ssl的直接跳转到https

server {
if ($host = abc.com) {
return 301 https://www.abc.com$request_uri;
}

if ($host = www.abc.com) {
return 301 https://www.abc.com$request_uri;
}

ssl配置文件中,修改原来的server_name _为server_name mail.abc.net在后面添加,做了修改,以支持PHP

server {
listen 443 ssl;
# listen [::]:443 ssl;
server_name abc.com www.abc.com;

ssl_certificate /etc/letsencrypt/live/abc.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/abc.com/privkey.pem;

location / {
root /var/www/hosts/abc.com;
index index.php index.html index.htm;
}
location ~ .php$ {
root /var/www/hosts/abc.com;
fastcgi_pass 127.0.0.1:9999;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

重启nginx即可

 systemctl restart nginx.service

mysql 远程连接时注意修改防火墙

# 查询端口是否开放
firewall-cmd --query-port=3306/tcp
# 开放3306端口
firewall-cmd --permanent --add-port=3306/tcp
# 移除端口
firewall-cmd --permanent --remove-port=3306/tcp

#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload

php的配置文件在/etc/php.ini,需要修改上传文件大小的限制,max_execution_time,upload_max_filesize,post_max_size,还有/etc/nginx/conf-enabled/client_max_body_size.conf里的client_max_body_size一并修改

修改php设置(/etc/php.ini)

memory_limit = 512M;
upload_max_filesize = 512M;
post_max_size = 512M;

修改 /opt/www/roundcubemail/.htaccess

在末尾加上

php_value    memory_limit   512M
php_value    upload_max_filesize    512M
php_value    post_max_size  512M

重启服务service php-fpm restart

最后修改的地方

postconf -e message_size_limit='536870912'
postconf -e mailbox_size_limit='536870912'

/sbin/service postfix restart

 如果用客户端发送,那关于附件大小的限量就只需要最后一步就行了。

修改后,要systemctl restart php-fpm 一下。

另外,注意将/etc/nginx/templates/roundcube.tmpl文件里的跳转到mail目录的代码注释掉,以防后面添加的虚拟主机访问时,会被跳转

# Redirect URI `/mail` to `/mail/`.
#location = /mail {
#    return 301 /mail/;
#}

如果更改了mysql的root密码,记得 vi /root/.my.cnf文件,修改一下,不然系统在自动备份邮件操作时会失败

另外,域名的自动续期要加一下,每隔60天凌晨4点自动续,证书有效期90天,所以,没有必要太频繁

0 4 */60 * * /bin/certbot renew --renew-hook "/sbin/service nginx reload"

另外,修改界面方面:

/opt/www/roundcubemail-1.4.2/config

里的$config['product_name']可以改一下

还可以使用别名,

参考:http://www.iredmail.org/docs/sql.create.mail.alias.html

https://bill.tt/2016/03/20/iRedMail%E8%AE%BE%E7%BD%AE%EF%BC%9A%E9%82%AE%E7%AE%B1%E5%88%AB%E5%90%8D%E3%80%81%E9%BB%98%E8%AE%A4%E6%8E%A5%E6%94%B6%E9%82%AE%E7%AE%B1%E7%AD%89/

原文地址:https://www.cnblogs.com/iitrust/p/12315284.html