Nginx中文文档
DocsHome
  • 贡献导引
  • 介绍
    • 安装 nginx
    • 从源码构建 nginx
    • 初学者指南
    • 管理指南
    • 控制 nginx
    • 连接处理方式
    • 设置哈希
    • 调试日志
    • 记录日志到 syslog
    • 配置文件度量单位
    • 命令行参数
    • Windows 下的 nginx
    • QUIC 和 HTTP/3 支持
    • nginx 如何处理请求
    • 服务器名称
    • 使用 nginx 作为 HTTP 负载均衡器
    • 配置 HTTPS 服务器
    • nginx 如何处理 TCP/UDP 会话
    • 关于 nginScript
  • 其他
    • Linux 软件包
  • How-To
    • 在 Win32 平台上使用 Visual C 构建 nginx
    • 设置 Amazon EC2 的 Nginx Plus 环境
    • 使用 DTrace pid 提供程序调试 nginx
    • 转换重写规则
    • WebSocket 代理
  • 开发
    • 贡献指南
    • 开发指南
  • 模块参考
  • 核心功能
    • HTTP
      • ngx_http_core_module
      • ngx_http_access_module
      • ngx_http_addition_module
      • ngx_http_api_module
      • ngx_http_auth_basic_module
      • ngx_http_auth_jwt_module
      • ngx_http_auth_request_module
      • ngx_http_autoindex_module
      • ngx_http_browser_module
      • ngx_http_charset_module
      • ngx_http_dav_module
      • ngx_http_empty_gif_module
      • ngx_http_f4f_module
      • ngx_http_fastcgi_module
      • ngx_http_flv_module
      • ngx_http_geo_module
      • ngx_http_geoip_module
      • ngx_http_grpc_module
      • ngx_http_gunzip_module
      • ngx_http_gzip_module
      • ngx_http_gzip_static_module
      • ngx_http_headers_module
      • ngx_http_hls_module
      • ngx_http_image_filter_module
      • ngx_http_index_module
      • ngx_http_js_module
      • ngx_http_keyval_module
      • ngx_http_limit_conn_module
      • ngx_http_limit_req_module
      • ngx_http_log_module
      • ngx_http_map_module
      • ngx_http_memcached_module
      • ngx_http_mirror_module
      • ngx_http_mp4_module
      • ngx_http_perl_module
      • ngx_http_proxy_module
      • ngx_http_random_index_module
      • ngx_http_realip_module
      • ngx_http_referer_module
      • ngx_http_rewrite_module
      • ngx_http_scgi_module
      • ngx_http_secure_link_module
      • ngx_http_session_log_module
      • ngx_http_slice_module
      • ngx_http_spdy_module(过时)
      • ngx_http_split_clients_module
      • ngx_http_ssi_module
      • ngx_http_ssl_module
      • ngx_http_status_module(过时)
      • ngx_http_stub_status_module
      • ngx_http_sub_module
      • ngx_http_upstream_module
      • ngx_http_upstream_conf_module
      • ngx_http_upstream_hc_module
      • ngx_http_userid_module
      • ngx_http_uwsgi_module
      • ngx_http_v2_module
      • ngx_http_xslt_module
    • Mail
      • ngx_mail_core_module
      • ngx_mail_auth_http_module
      • ngx_mail_proxy_module
      • ngx_mail_ssl_module
      • ngx_mail_imap_module
      • ngx_mail_pop3_module
      • ngx_mail_smtp_module
    • Stream
      • ngx_stream_core_module
      • ngx_stream_access_module
      • ngx_stream_geo_module
      • ngx_stream_geoip_module
      • ngx_stream_js_module
      • ngx_stream_keyval_module
      • ngx_stream_limit_conn_module
      • ngx_stream_log_module
      • ngx_stream_map_module
      • ngx_stream_proxy_module
      • ngx_stream_realip_module
      • ngx_stream_return_module
      • ngx_stream_split_clients_module
      • ngx_stream_ssl_module
      • ngx_stream_ssl_preread_module
      • ngx_stream_upstream_module
      • ngx_stream_upstream_hc_module
      • ngx_stream_zone_sync_module
    • 其他
      • ngx_google_perftools_module
由 GitBook 提供支持
在本页
  • 示例配置
  • 指令
  • listen
  • mail
  • protocol
  • resolver
  • resolver_timeout
  • server
  • server_name
  • timeout
  • 原文档
  1. 核心功能
  2. Mail

ngx_mail_core_module

上一页Mail下一页ngx_mail_auth_http_module

最后更新于5年前

默认不构建此模块,可使用 --with-mail 配置参数启用。

示例配置

worker_processes 1;

error_log /var/log/nginx/error.log info;

events {
    worker_connections  1024;
}

mail {
    server_name       mail.example.com;
    auth_http         localhost:9000/cgi-bin/nginxauth.cgi;

    imap_capabilities IMAP4rev1 UIDPLUS IDLE LITERAL+ QUOTA;

    pop3_auth         plain apop cram-md5;
    pop3_capabilities LAST TOP USER PIPELINING UIDL;

    smtp_auth         login plain cram-md5;
    smtp_capabilities "SIZE 10485760" ENHANCEDSTATUSCODES 8BITMIME DSN;
    xclient           off;

    server {
        listen   25;
        protocol smtp;
    }
    server {
        listen   110;
        protocol pop3;
        proxy_pass_error_message on;
    }
    server {
        listen   143;
        protocol imap;
    }
    server {
        listen   587;
        protocol smtp;
    }
}

指令

listen

-

说明

语法

listen address:port [ssl] [backlog=number] [rcvbuf=size] [sndbuf=size] [bind] [ipv6only=on\|off] [so_keepalive=on\|off\|[keepidle]:[keepintvl]:[keepcnt]];

默认

——

上下文

server

为将接受请求的服务器的套接字设置地址(address)和端口(port)。可以仅指定端口。地址也可以是主机名,例如:

listen 127.0.0.1:110;
listen *:110;
listen 110;     # same as *:110
listen localhost:110;

IPv6 地址在方括号中指定(0.7.58):

listen [::1]:110;
listen [::]:110;

UNIX 域套接字使用 unix: 前缀指定(1.3.5):

listen unix:/var/run/nginx.sock;

不同的服务器必须侦听不同的 address:port 对,不能重复。

ssl 参数指定该端口上接受的所有连接均应以 SSL 模式工作。

listen 指令可以指定几个额外的参数给套接字相关的系统调用。

  • backlog=number

    在 listen() 调用中设置 backlog 参数,该参数限制挂起的连接队列的最大长度(1.9.2)。默认情况下,在 FreeBSD、DragonFly BSD 和 mac OS上,backlog 设置为 -1,而在其他平台上则设置为 511。

  • rcvbuf=size

    设置侦听套接字的接收缓冲区大小(SO_RCVBUF 选项)(1.11.13)。

  • sndbuf=size

    设置侦听套接字的发送缓冲区大小(SO_SNDBUF 选项)(1.11.13)。

  • bind

    此参数指示对给定的 address:port 对进行单独的 bind() 调用。事实上,如果有多个有相同端口但地址不同的 listen 指令,并且其中一个 listen 指令在给定端口(*:port)的所有地址上监听,nginx 只会将绑定(bind())到 *:port。要注意的是,这种情况下将进行 getsockname() 系统调用,以确定接受连接的地址。如果使用 ipv6only 或 so_keepalive 参数,则对于给定的 address:port 对,将始终进行单独的 bind() 调用。

  • ipv6only=on|off

    此参数确定(通过 IPV6_V6ONLY 套接字选项)监听通配符地址 [::] 的 IPv6 套接字是否仅接受 IPv6 连接,还是接受 IPv6 和 IPv4 连接。默认情况下,此参数是打开的。启动时只能设置一次。

  • so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]

    此参数为监听套接字配置「TCP keepalive」行为。如果省略此参数,则套接字的操作系统设置将生效。如果将其设置为值 on,则会为套接字打开 SO_KEEPALIVE 选项。如果将其设置为值 off,则将关闭套接字 SO_KEEPALIVE 选项。某些操作系统支持使用 TCP_KEEPIDLE、TCP_KEEPINTVL 和 TCP_KEEPCNT 套接字选项在每个套接字的基础上设置 TCP Keepalive 参数。在此类系统(当前为 Linux 2.4+、NetBSD 5+ 和 FreeBSD 9.0-STABLE)上,可以使用 keepidle、keepintvl 和 keepcnt 参数进行配置。可以省略一个或两个参数,在这种情况下,相应套接字选项的系统默认设置将生效。例如,

      so_keepalive=30m::10

    会将闲置超时时间(TCP_KEEPIDLE)设置为 30 分钟,将探测间隔(TCP_KEEPINTVL)保留为系统默认值,并将探测计数(TCP_KEEPCNT)设置为 10 个探测。

mail

-

说明

语法

mail { ... };

默认

——

上下文

main

在指定的邮件服务器指令中提供配置文件上下文。

protocol

-

说明

语法

protocol imap | pop3 | smtp;

默认

——

上下文

server

  • imap:143、993

  • pop3:110、995

  • smtp:25、587、465

resolver

-

说明

语法

resolver address ... [valid=time] [ipv6=on\|off] [status_zone=zone]; resolver off

默认

resolver off;

上下文

mail、server

resolver 127.0.0.1 [::1]:5353;

可以使用可选端口(1.3.1、1.2.2)将地址指定为域名或 IP 地址。如果未指定端口,则使用端口 53。以轮询方式查询名称服务器。

在 1.1.7 版本之前,只能配置一个名称服务器。从 1.3.1 和 1.2.2 版本开始,支持使用 IPv6 地址指定名称服务器。

默认情况下,nginx 将在解析时同时查找 IPv4 和 IPv6 地址。如果不需要查找 IPv6 地址,则可以指定 ipv6=off 参数。

从 1.5.8 版本开始,支持将名称解析为 IPv6 地址。

默认情况下,nginx 使用响应的 TTL 值缓存应答。可选的 valid 参数可覆盖它:

resolver 127.0.0.1 [::1]:5353 valid=30s;

在1.1.9 版本之前,无法调整缓存时间,nginx 始终将应答缓存 5 分钟。

为防止 DNS 欺骗,建议在适当安全的受信任本地网络中配置 DNS 服务器。

特殊值 off 禁用解析。

resolver_timeout

-

说明

语法

resolver_timeout time;

默认

resolver_timeout 30s;

上下文

mail、server

设置 DNS 操作的超时时间,例如:

resolver_timeout 5s;

server

-

说明

语法

server { ... };

默认

——

上下文

mail

设置服务器的配置。

server_name

-

说明

语法

server_name name;

默认

server_name hostname;

上下文

mail、server

设置服务器名称,在以下场景中使用的:

  • 最开始的 POP3/SMTP 服务器问候语中

  • SASL CRAM-MD5 身份验证中的盐值中

如果未指定指令,则使用计算机的主机名。

timeout

-

说明

语法

timeout time;

默认

timeout 60s;

上下文

mail、server

设置超时时间,在代理到后端开始之前使用。

原文档

设置代理服务器的协议。支持的协议有 、 和 。

如果未设置该指令,则可以基于 指令中指定的为人熟知的默认端口来自动检测协议:

可以使用参数 --without-mail_imap_module、--without-mail_pop3_module 和 --without-mail_smtp_module 禁用不必要的协议。

配置用于查找客户端主机名以将其传递给的名称服务器,以及代理 SMTP 时的 命令。 例如:

可选的 status_zone 参数(1.17.1)启用对指定区域中的请求和响应的 DNS 服务器统计信息的[收集]功能(../http/ngxhttp_api_module.md#resolvers)。该参数为我们的部分。

如果启用了 命令的传递,则在连接到 SMTP 后端时,在 EHLO 命令中

IMAP
POP3
SMTP
配置
商业订阅
http://nginx.org/en/docs/mail/ngx_mail_core_module.html
示例配置
指令
listen
mail
protocol
resolver
resolver_timeout
server
server_name
timeout
listen
身份验证服务器
XCLIENT
XCLIENT