Nginx邮件代理

Nginx邮件代理(--with-mail)
指令:
auth_http:提供认证方式,用于POP3/IMAP用户认证使用
imap_capabilities:后端服务支持IMAP4
pop3_capabilities:后端服务支持POP3
protocol:支持的协议
proxy:启用或禁用mail代理
proxy_buffer:代理连接缓冲
proxy_pass_error_message:后端向客户端发出一个有用的错误消息的情况下,该设置起作用
proxy_timeout:默认24小时

(--with-mail_ssl_module)
ssl:表明支持ssl处理
ssl_certificate:PEM编码的SSL证书路径
ssl_certificate_key:PEM编码的SSL密码密钥
ssl_ciphers:支持密码(OpenSSL格式)
ssl_prefer_server_ciphers:表明SSLv3和TLSv1服务器密码是客户首选
ssl_protocols:使用的SSL协议
ssl_session_cache:所有的worker进程是否共享指定SSL缓存
ssl_session_timeout:提供的参数被存储在缓存中,多久超时

OpenSSL生成SSL证书
openssl req -newkey rsa:2048 -nodes -out mail.example.com.csr -keyout mail.example.com.key
(mail.example.com.csr 证书签名是由Certificate Authority证书颁发机构授予的)
openssl x509 -req -days 365 -in mail.example.com.csr -signkey mail.example.com.key -out mail.example.com.crt
(获得mail.example.com.crt证书)

认证服务
Nginx会向认证服务发送以下请求头
Host/Auth-Method/Auth-User/Auth-Pass/Auth-Salt/Auth-Protocol/
Auth-Login-Attempt/Client-IP/Client-Host/
Auth-SMTP-Helo/Auth-SMTP-From/Auth-SMTP-To
响应信息头
Auth-Status:在头中,除OK之外其他信息都是错误的,如"OK","Invalid login"
Auth-Server:用于代理连接的IP地址,mailhost
Auth-Port:用于代理连接的端口,MailAuth Port
Auth-User:用于邮件服务器认证的用户名称
Auth-Pass:用于认证的(APOP协议)的明文密码
Auth-Wait:下一次尝试认证之前等待多少秒
Auth-Error-Code:用于向客户端返回的错误代码


操作系统限制
ulimit -n 
(打开文件描述符的最大数量,可以根据情况增加该值)

在nginx.conf中设置worker_rlimit_nofile为一个新的值

TCP端口连接限制默认5000,可以根据情况增加,通常设置为16384

完整配置
events {
  worker_connections 1024;
}
mail {
  server_name mail.example.com;

  auth_http localhost:9000/auth;

  proxy on;

  ssl_prefer_server_ciphers on;
  ssl_protocols TLSv1 SSLv3;
  ssl_ciphers HIGH:!ADH:!MD5:@STRENFTH;
  ssl_session_cache shared:MAIL:10m;
  ssl_certificate /opt/mail.example.com.crt;

  ssl_certificate_key /opt/mail.example.com.key;

  pop3_capabilities TOP USER;
  imap_capabilities IMAP4rev1 UIDPLUS QUOTA;

  smtp_capabilities PIPELINING 8BITMIME DSN;

  pop3_auth apop cram-md5;
  imap_auth login cram-md5;

  smtp_auth login cram-md5;

  server {
    listen 25;
    protocol smtp;
    timeout 120000;

  }

  server {
    listen 465;
    protocol smtp;
    ssl on;

  }

  server {
    listen 587;
    protocol smtp;
    starttls on;

  }

  server {
    listen 110;
    protocol pop3;
    starttls on;

  }

  server {
    listen 995;
    protocol pop3;
    ssl on;

  }

  server {
    listen 143;
    protocol imap;
    starttls on;

  }

  server {
    listen 993;
    protocol imap;
    ssl on;
  }
}

猜你喜欢

转载自blog.csdn.net/lovewebeye/article/details/79930515