说明
- 基于Mailu https://mailu.io/2.0/ ;
- 我几乎所有的服务,一个docker-compose.yml文件,一个nginx文件基本都可以搞定;
- 配置文件只有3个,看着长,实际上复制粘贴,稍作修改即可(所有example.com替换为自己的,还有一个证书位置、ip、key);
- 内存平均占用500多M,CPU平均1%左右,1C1G小鸡都行,
条件/准备
- Docker
- Nginx
- 域名以及证书
- 可 rDNS 以及开启25端口的vps
Docker
- 新建一个目录,比如mailu,里面创建
docker-compose.yml,记得改ssl证书位置
version: '2.2'
services:
# External dependencies
redis:
image: redis:alpine
restart: always
container_name: mailu-redis
volumes:
- "./redis:/data"
depends_on:
- resolver
dns:
- 172.30.1.254
# Core services
front:
image: ${DOCKER_ORG:-ghcr.io/mailu}/${DOCKER_PREFIX:-}nginx:${MAILU_VERSION:-2.0}
restart: always
container_name: mailu-nginx
env_file: mailu.env
logging:
driver: journald
options:
tag: mailu-front
ports:
- "127.0.0.1:8880:80"
- "127.0.0.1:44443:443"
- "127.0.0.1:25:25"
- "127.0.0.1:465:465"
- "127.0.0.1:587:587"
- "127.0.0.1:110:110"
- "127.0.0.1:995:995"
- "127.0.0.1:143:143"
- "127.0.0.1:993:993"
networks:
- default
- webmail
volumes:
- "/etc/nginx/ssl/example.com:/certs:ro" #ssl证书位置
- "./overrides/nginx:/overrides:ro"
depends_on:
- resolver
dns:
- 172.30.1.254
resolver:
image: ${DOCKER_ORG:-ghcr.io/mailu}/${DOCKER_PREFIX:-}unbound:${MAILU_VERSION:-2.0}
env_file: mailu.env
container_name: mailu-unbound
restart: always
networks:
default:
ipv4_address: 172.30.1.254
admin:
image: ${DOCKER_ORG:-ghcr.io/mailu}/${DOCKER_PREFIX:-}admin:${MAILU_VERSION:-2.0}
restart: always
env_file: mailu.env
container_name: mailu-admin
logging:
driver: journald
options:
tag: mailu-admin
volumes:
- "./data:/data"
- "./dkim:/dkim"
depends_on:
- redis
- resolver
dns:
- 172.30.1.254
imap:
image: ${DOCKER_ORG:-ghcr.io/mailu}/${DOCKER_PREFIX:-}dovecot:${MAILU_VERSION:-2.0}
restart: always
env_file: mailu.env
container_name: mailu-dovecot
logging:
driver: journald
options:
tag: mailu-imap
volumes:
- "./mail:/mail"
- "./overrides/dovecot:/overrides:ro"
depends_on:
- front
- resolver
dns:
- 172.30.1.254
smtp:
image: ${DOCKER_ORG:-ghcr.io/mailu}/${DOCKER_PREFIX:-}postfix:${MAILU_VERSION:-2.0}
restart: always
env_file: mailu.env
container_name: mailu-postfix
logging:
driver: journald
options:
tag: mailu-smtp
volumes:
- "./mailqueue:/queue"
- "./overrides/postfix:/overrides:ro"
depends_on:
- front
- resolver
dns:
- 172.30.1.254
oletools:
image: ${DOCKER_ORG:-ghcr.io/mailu}/${DOCKER_PREFIX:-}oletools:${MAILU_VERSION:-2.0}
hostname: oletools
container_name: mailu-oletools
restart: always
networks:
- noinet
depends_on:
- resolver
dns:
- 172.30.1.254
antispam:
image: ${DOCKER_ORG:-ghcr.io/mailu}/${DOCKER_PREFIX:-}rspamd:${MAILU_VERSION:-2.0}
hostname: antispam
restart: always
container_name: mailu-rspamd
env_file: mailu.env
logging:
driver: journald
options:
tag: mailu-antispam
networks:
- default
- noinet
volumes:
- "./filter:/var/lib/rspamd"
- "./overrides/rspamd:/overrides:ro"
depends_on:
- front
- redis
- oletools
- resolver
dns:
- 172.30.1.254
# Optional services
fetchmail:
image: ${DOCKER_ORG:-ghcr.io/mailu}/${DOCKER_PREFIX:-}fetchmail:${MAILU_VERSION:-2.0}
restart: always
env_file: mailu.env
container_name: mailu-fetchmail
volumes:
- "./data/fetchmail:/data"
depends_on:
- admin
- smtp
- imap
- resolver
dns:
- 172.30.1.254
# Webmail
webmail:
image: ${DOCKER_ORG:-ghcr.io/mailu}/${DOCKER_PREFIX:-}webmail:${MAILU_VERSION:-2.0}
restart: always
env_file: mailu.env
container_name: mailu-webmail
volumes:
- "./webmail:/data"
- "./overrides/roundcube:/overrides:ro"
networks:
- webmail
depends_on:
- front
networks:
default:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.30.1.0/24
webmail:
driver: bridge
noinet:
driver: bridge
internal: true
- 同目录创建环境配置文件
mailu.env,要改域名、IP和SECRET_KEY
# 16位随机key
SECRET_KEY=aaaaaaaaaaaaaaaa
# docker子网
SUBNET=172.30.1.0/24
# 一级域名
DOMAIN=example.com
# 二级域名
HOSTNAMES=mail.example.com
# Postmaster local part (will append the main mail domain)
POSTMASTER=admin
# Choose how secure connections will behave (value: letsencrypt, cert, notls, mail, mail-letsencrypt)
TLS_FLAVOR=mail
TLS_KEYPAIR_FILENAME=privkey.pem
TLS_CERT_FILENAME=fullchain.pem
# Authentication rate limit per IP (per /24 on ipv4 and /48 on ipv6)
AUTH_RATELIMIT_IP=5/hour
# Authentication rate limit per user (regardless of the source-IP)
AUTH_RATELIMIT_USER=50/day
# Opt-out of statistics, replace with "True" to opt out
DISABLE_STATISTICS=True
# Expose the admin interface (value: true, false)
ADMIN=true
# Choose which webmail to run if any (values: roundcube, snappymail, none)
WEBMAIL=roundcube
# Expose the API interface (value: true, false)
API=false
# Dav server implementation (value: radicale, none)
WEBDAV=none
# Antivirus solution (value: clamav, none)
ANTIVIRUS=none
# Scan Macros solution (value: true, false)
SCAN_MACROS=true
# Message size limit in bytes
# Default: accept messages up to 50MB
# Max attachment size will be 33% smaller
MESSAGE_SIZE_LIMIT=50000000
# Message rate limit (per user)
MESSAGE_RATELIMIT=200/day
# Enable fetchmail
FETCHMAIL_ENABLED=true
# Fetchmail delay
FETCHMAIL_DELAY=600
# Recipient delimiter, character used to delimiter localpart from custom address part
RECIPIENT_DELIMITER=+
# DMARC rua and ruf email
DMARC_RUA=admin
DMARC_RUF=admin
# Welcome email, enable and set a topic and body if you wish to send welcome
# emails to all users.
WELCOME=false
WELCOME_SUBJECT=Welcome to your new email account
WELCOME_BODY=Welcome to your new email account, if you can read this, then it is configured properly!
# IMAP full-text search is enabled by default. Set the following variable to off in order to disable the feature.
# FULL_TEXT_SEARCH=off
# Path to redirect / to
WEBROOT_REDIRECT=/webmail
# Path to the admin interface if enabled
WEB_ADMIN=/admin
# Path to the webmail if enabled
WEB_WEBMAIL=/webmail
# Path to the API interface if enabled
WEB_API=/api
# Website name
SITENAME=Mailu
# 二级域名
WEBSITE=https://mail.example.com
# Docker-compose project name, this will prepended to containers names.
COMPOSE_PROJECT_NAME=mailu
# Number of rounds used by the password hashing scheme
CREDENTIAL_ROUNDS=12
# Header to take the real ip from
REAL_IP_HEADER=X-Real-IP
# 服务器ip
REAL_IP_FROM=114.5.1.4
# Log level threshold in start.py (value: CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET)
LOG_LEVEL=WARNING
# Timezone for the Mailu containers. See this link for all possible values https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
TZ=Asia/Shanghai
# Default spam threshold used for new users
DEFAULT_SPAM_THRESHOLD=80
server {
listen 80;
listen [::]:80;
server_name mail.example.com autodiscover.example.com autoconfig.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name mail.example.com autodiscover.example.com autoconfig.example.com;
ssl_certificate /etc/nginx/ssl/example.com/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/example.com/privkey.pem;
ssl_session_timeout 1d;
ssl_session_tickets off;
ssl_protocols TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5:!SHA1:!kRSA;
ssl_prefer_server_ciphers off;
location ~* ^/(admin|api|sso|static|webdav|webmail|(apple\.)?mobileconfig|(\.well\-known/autoconfig/)?mail/|Autodiscover/Autodiscover) {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass https://localhost:44443;
}
location / {
return 301 $scheme://$host/webmail;
}
location /admin {
proxy_pass https://localhost:44443/admin;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
location /webmail {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass https://127.0.0.1:44443/webmail;
}
access_log /www/wwwlogs/mail.example.com.log main;
error_log /www/wwwlogs/error/mail.example.com.error.log;
}
启动
DNS解析相关
效果
- webmail 是这样的

- 剩余的所有要添加的解析是这些

- 评分
