Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nginx
GitHub Repository: nginx/nginx.org
Path: blob/main/xml/en/docs/mail/ngx_mail_ssl_module.xml
1 views
1
<?xml version="1.0"?>
2
3
<!--
4
Copyright (C) 2006, 2007 Anton Yuzhaninov
5
Copyright (C) Nginx, Inc.
6
-->
7
8
<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
9
10
<module name="Module ngx_mail_ssl_module"
11
link="/en/docs/mail/ngx_mail_ssl_module.html"
12
lang="en"
13
rev="34">
14
15
<section id="summary">
16
17
<para>
18
The <literal>ngx_mail_ssl_module</literal> module provides the necessary
19
support for a mail proxy server to work with the SSL/TLS protocol.
20
</para>
21
22
<para>
23
This module is not built by default, it should be enabled with the
24
<literal>--with-mail_ssl_module</literal>
25
configuration parameter.
26
<note>
27
This module requires the
28
<link url="http://www.openssl.org">OpenSSL</link> library.
29
</note>
30
</para>
31
32
</section>
33
34
35
<section id="example" name="Example Configuration">
36
37
<para>
38
To reduce the processor load, it is recommended to
39
<list type="bullet">
40
41
<listitem>
42
set the number of
43
<link doc="../ngx_core_module.xml" id="worker_processes">worker processes</link>
44
equal to the number of processors,
45
</listitem>
46
47
<listitem>
48
enable the <link id="ssl_session_cache_shared">shared</link> session cache,
49
</listitem>
50
51
<listitem>
52
disable the <link id="ssl_session_cache_builtin">built-in</link> session cache,
53
</listitem>
54
55
<listitem>
56
and possibly increase the session <link id="ssl_session_timeout">lifetime</link>
57
(by default, 5 minutes):
58
</listitem>
59
60
</list>
61
62
<example>
63
<emphasis>worker_processes auto;</emphasis>
64
65
mail {
66
67
...
68
69
server {
70
listen 993 ssl;
71
72
ssl_protocols TLSv1.2 TLSv1.3;
73
ssl_ciphers AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
74
ssl_certificate /usr/local/nginx/conf/cert.pem;
75
ssl_certificate_key /usr/local/nginx/conf/cert.key;
76
<emphasis>ssl_session_cache shared:SSL:10m;</emphasis>
77
<emphasis>ssl_session_timeout 10m;</emphasis>
78
79
...
80
}
81
</example>
82
</para>
83
84
</section>
85
86
87
<section id="directives" name="Directives">
88
89
<directive name="ssl">
90
<syntax><literal>on</literal> | <literal>off</literal></syntax>
91
<default>off</default>
92
<context>mail</context>
93
<context>server</context>
94
95
<para>
96
This directive was made obsolete in version 1.15.0
97
and was removed in version 1.25.1.
98
The <literal>ssl</literal> parameter
99
of the <link doc="ngx_mail_core_module.xml" id="listen"/> directive
100
should be used instead.
101
</para>
102
103
</directive>
104
105
106
<directive name="ssl_certificate">
107
<syntax><value>file</value></syntax>
108
<default/>
109
<context>mail</context>
110
<context>server</context>
111
112
<para>
113
Specifies a <value>file</value> with the certificate in the PEM format
114
for the given server.
115
If intermediate certificates should be specified in addition to a primary
116
certificate, they should be specified in the same file in the following
117
order: the primary certificate comes first, then the intermediate certificates.
118
A secret key in the PEM format may be placed in the same file.
119
</para>
120
121
<para>
122
Since version 1.11.0,
123
this directive can be specified multiple times
124
to load certificates of different types, for example, RSA and ECDSA:
125
<example>
126
server {
127
listen 993 ssl;
128
129
ssl_certificate example.com.rsa.crt;
130
ssl_certificate_key example.com.rsa.key;
131
132
ssl_certificate example.com.ecdsa.crt;
133
ssl_certificate_key example.com.ecdsa.key;
134
135
...
136
}
137
</example>
138
<note>
139
Only OpenSSL 1.0.2 or higher supports separate
140
<link doc="../http/configuring_https_servers.xml" id="chains">certificate
141
chains</link>
142
for different certificates.
143
With older versions, only one certificate chain can be used.
144
</note>
145
</para>
146
147
<para id="ssl_certificate_data">
148
The value
149
<literal>data</literal>:<value>certificate</value>
150
can be specified instead of the <value>file</value> (1.15.10),
151
which loads a certificate
152
without using intermediate files.
153
Note that inappropriate use of this syntax may have its security implications,
154
such as writing secret key data to
155
<link doc="../ngx_core_module.xml" id="error_log">error log</link>.
156
</para>
157
158
</directive>
159
160
161
<directive name="ssl_certificate_compression">
162
<syntax><literal>on</literal> | <literal>off</literal></syntax>
163
<default>off</default>
164
<context>mail</context>
165
<context>server</context>
166
<appeared-in>1.29.1</appeared-in>
167
168
<para>
169
Enables TLS 1.3
170
<link url="https://datatracker.ietf.org/doc/html/rfc8879">compression</link>
171
of server certificates.
172
<note>
173
The directive is supported when using OpenSSL 3.2 or higher;
174
the list of supported compression algorithms is provided by the library.
175
</note>
176
<note>
177
The directive is supported when using BoringSSL;
178
the list of supported compression algorithms includes
179
<literal>zlib</literal> (1.29.3).
180
</note>
181
</para>
182
183
</directive>
184
185
186
<directive name="ssl_certificate_key">
187
<syntax><value>file</value></syntax>
188
<default/>
189
<context>mail</context>
190
<context>server</context>
191
192
<para>
193
Specifies a <value>file</value> with the secret key in the PEM format
194
for the given server.
195
</para>
196
197
<para>
198
The value
199
<literal>engine</literal>:<value>name</value>:<value>id</value>
200
can be specified instead of the <value>file</value> (1.7.9),
201
which loads a secret key with a specified <value>id</value>
202
from the OpenSSL engine <value>name</value>.
203
</para>
204
205
<para>
206
The value
207
<literal>store</literal>:<value>scheme</value>:<value>id</value>
208
can be specified instead of the <value>file</value> (1.29.0),
209
which is used to load a secret key with a specified <value>id</value>
210
and OpenSSL provider registered URI <value>scheme</value>, such as
211
<link url="https://datatracker.ietf.org/doc/html/rfc7512"><literal>pkcs11</literal></link>.
212
</para>
213
214
<para id="ssl_certificate_key_data">
215
The value
216
<literal>data</literal>:<value>key</value>
217
can be specified instead of the <value>file</value> (1.15.10),
218
which loads a secret key without using intermediate files.
219
Note that inappropriate use of this syntax may have its security implications,
220
such as writing secret key data to
221
<link doc="../ngx_core_module.xml" id="error_log">error log</link>.
222
</para>
223
224
</directive>
225
226
227
<directive name="ssl_ciphers">
228
<syntax><value>ciphers</value></syntax>
229
<default>HIGH:!aNULL:!MD5</default>
230
<context>mail</context>
231
<context>server</context>
232
233
<para>
234
Specifies the enabled ciphers.
235
The ciphers are specified in the format understood by the
236
OpenSSL library, for example:
237
<example>
238
ssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
239
</example>
240
</para>
241
242
<para>
243
The full list can be viewed using the
244
<command>openssl ciphers</command>” command.
245
</para>
246
247
<para>
248
<note>
249
The previous versions of nginx used
250
<link doc="../http/configuring_https_servers.xml" id="compatibility">different</link>
251
ciphers by default.
252
</note>
253
</para>
254
255
</directive>
256
257
258
<directive name="ssl_client_certificate">
259
<syntax><value>file</value></syntax>
260
<default/>
261
<context>mail</context>
262
<context>server</context>
263
<appeared-in>1.7.11</appeared-in>
264
265
<para>
266
Specifies a <value>file</value> with trusted CA certificates in the PEM format
267
used to <link id="ssl_verify_client">verify</link> client certificates.
268
</para>
269
270
<para>
271
The list of certificates will be sent to clients.
272
If this is not desired, the <link id="ssl_trusted_certificate"/>
273
directive can be used.
274
</para>
275
276
</directive>
277
278
279
<directive name="ssl_conf_command">
280
<syntax><value>name</value> <value>value</value></syntax>
281
<default/>
282
<context>mail</context>
283
<context>server</context>
284
<appeared-in>1.19.4</appeared-in>
285
286
<para>
287
Sets arbitrary OpenSSL configuration
288
<link url="https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html">commands</link>.
289
<note>
290
The directive is supported when using OpenSSL 1.0.2 or higher.
291
</note>
292
</para>
293
294
<para>
295
Several <literal>ssl_conf_command</literal> directives
296
can be specified on the same level:
297
<example>
298
ssl_conf_command Options PrioritizeChaCha;
299
ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;
300
</example>
301
These directives are inherited from the previous configuration level
302
if and only if there are no <literal>ssl_conf_command</literal> directives
303
defined on the current level.
304
</para>
305
306
<para>
307
<note>
308
Note that configuring OpenSSL directly
309
might result in unexpected behavior.
310
</note>
311
</para>
312
313
</directive>
314
315
316
<directive name="ssl_crl">
317
<syntax><value>file</value></syntax>
318
<default/>
319
<context>mail</context>
320
<context>server</context>
321
<appeared-in>1.7.11</appeared-in>
322
323
<para>
324
Specifies a <value>file</value> with revoked certificates (CRL)
325
in the PEM format used to <link id="ssl_verify_client">verify</link>
326
client certificates.
327
When using intermediate certificates, their CRLs should be
328
specified in the same file.
329
</para>
330
331
</directive>
332
333
334
<directive name="ssl_dhparam">
335
<syntax><value>file</value></syntax>
336
<default/>
337
<context>mail</context>
338
<context>server</context>
339
<appeared-in>0.7.2</appeared-in>
340
341
<para>
342
Specifies a <value>file</value> with DH parameters for DHE ciphers.
343
</para>
344
345
<para>
346
By default no parameters are set,
347
and therefore DHE ciphers will not be used.
348
<note>
349
Prior to version 1.11.0, builtin parameters were used by default.
350
</note>
351
</para>
352
353
</directive>
354
355
356
<directive name="ssl_ecdh_curve">
357
<syntax><value>curve</value></syntax>
358
<default>auto</default>
359
<context>mail</context>
360
<context>server</context>
361
<appeared-in>1.1.0</appeared-in>
362
<appeared-in>1.0.6</appeared-in>
363
364
<para>
365
Specifies a <value>curve</value> for ECDHE ciphers.
366
</para>
367
368
<para>
369
When using OpenSSL 1.0.2 or higher,
370
it is possible to specify multiple curves (1.11.0), for example:
371
<example>
372
ssl_ecdh_curve prime256v1:secp384r1;
373
</example>
374
</para>
375
376
<para>
377
The special value <literal>auto</literal> (1.11.0) instructs nginx to use
378
a list built into the OpenSSL library when using OpenSSL 1.0.2 or higher,
379
or <literal>prime256v1</literal> with older versions.
380
</para>
381
382
<para>
383
<note>
384
Prior to version 1.11.0,
385
the <literal>prime256v1</literal> curve was used by default.
386
</note>
387
</para>
388
389
<para>
390
<note>
391
When using OpenSSL 1.0.2 or higher,
392
this directive sets the list of curves supported by the server.
393
Thus, in order for ECDSA certificates to work,
394
it is important to include the curves used in the certificates.
395
</note>
396
</para>
397
398
</directive>
399
400
401
<directive name="ssl_password_file">
402
<syntax><value>file</value></syntax>
403
<default/>
404
<context>mail</context>
405
<context>server</context>
406
<appeared-in>1.7.3</appeared-in>
407
408
<para>
409
Specifies a <value>file</value> with passphrases for
410
<link id="ssl_certificate_key">secret keys</link>
411
where each passphrase is specified on a separate line.
412
Passphrases are tried in turn when loading the key.
413
</para>
414
415
<para>
416
Example:
417
<example>
418
mail {
419
ssl_password_file /etc/keys/global.pass;
420
...
421
422
server {
423
server_name mail1.example.com;
424
ssl_certificate_key /etc/keys/first.key;
425
}
426
427
server {
428
server_name mail2.example.com;
429
430
# named pipe can also be used instead of a file
431
ssl_password_file /etc/keys/fifo;
432
ssl_certificate_key /etc/keys/second.key;
433
}
434
}
435
</example>
436
</para>
437
438
</directive>
439
440
441
<directive name="ssl_prefer_server_ciphers">
442
<syntax><literal>on</literal> | <literal>off</literal></syntax>
443
<default>off</default>
444
<context>mail</context>
445
<context>server</context>
446
447
<para>
448
Specifies that server ciphers should be preferred over client ciphers
449
when the SSLv3 and TLS protocols are used.
450
</para>
451
452
</directive>
453
454
455
<directive name="ssl_protocols">
456
<syntax>
457
[<literal>SSLv2</literal>]
458
[<literal>SSLv3</literal>]
459
[<literal>TLSv1</literal>]
460
[<literal>TLSv1.1</literal>]
461
[<literal>TLSv1.2</literal>]
462
[<literal>TLSv1.3</literal>]</syntax>
463
<default>TLSv1.2 TLSv1.3</default>
464
<context>mail</context>
465
<context>server</context>
466
467
<para>
468
Enables the specified protocols.
469
<note>
470
The <literal>TLSv1.1</literal> and <literal>TLSv1.2</literal> parameters
471
(1.1.13, 1.0.12) work only when OpenSSL 1.0.1 or higher is used.
472
</note>
473
<note>
474
The <literal>TLSv1.3</literal> parameter (1.13.0) works only when
475
OpenSSL 1.1.1 or higher is used.
476
</note>
477
<note>
478
The <literal>TLSv1.3</literal> parameter is used by default
479
since 1.23.4.
480
</note>
481
</para>
482
483
</directive>
484
485
486
<directive name="ssl_session_cache">
487
<syntax>
488
<literal>off</literal> |
489
<literal>none</literal> |
490
[<literal>builtin</literal>[:<value>size</value>]]
491
[<literal>shared</literal>:<value>name</value>:<value>size</value>]</syntax>
492
<default>none</default>
493
<context>mail</context>
494
<context>server</context>
495
496
<para>
497
Sets the types and sizes of caches that store session parameters.
498
A cache can be of any of the following types:
499
<list type="tag">
500
501
<tag-name><literal>off</literal></tag-name>
502
<tag-desc>
503
the use of a session cache is strictly prohibited:
504
nginx explicitly tells a client that sessions may not be reused.
505
</tag-desc>
506
507
<tag-name><literal>none</literal></tag-name>
508
<tag-desc>
509
the use of a session cache is gently disallowed:
510
nginx tells a client that sessions may be reused, but does not
511
actually store session parameters in the cache.
512
</tag-desc>
513
514
<tag-name id="ssl_session_cache_builtin"><literal>builtin</literal></tag-name>
515
<tag-desc>
516
a cache built in OpenSSL; used by one worker process only.
517
The cache size is specified in sessions.
518
If size is not given, it is equal to 20480 sessions.
519
Use of the built-in cache can cause memory fragmentation.
520
</tag-desc>
521
522
<tag-name id="ssl_session_cache_shared"><literal>shared</literal></tag-name>
523
<tag-desc>
524
a cache shared between all worker processes.
525
The cache size is specified in bytes; one megabyte can store
526
about 4000 sessions.
527
Each shared cache should have an arbitrary name.
528
A cache with the same name can be used in several
529
servers.
530
It is also used to automatically generate, store, and
531
periodically rotate TLS session ticket keys (1.23.2)
532
unless configured explicitly
533
using the <link id="ssl_session_ticket_key"/> directive.
534
</tag-desc>
535
536
</list>
537
</para>
538
539
<para>
540
Both cache types can be used simultaneously, for example:
541
<example>
542
ssl_session_cache builtin:1000 shared:SSL:10m;
543
</example>
544
but using only shared cache without the built-in cache should
545
be more efficient.
546
</para>
547
548
</directive>
549
550
551
<directive name="ssl_session_ticket_key">
552
<syntax><value>file</value></syntax>
553
<default/>
554
<context>mail</context>
555
<context>server</context>
556
<appeared-in>1.5.7</appeared-in>
557
558
<para>
559
Sets a <value>file</value> with the secret key used to encrypt
560
and decrypt TLS session tickets.
561
The directive is necessary if the same key has to be shared between
562
multiple servers.
563
By default, a randomly generated key is used.
564
</para>
565
566
<para>
567
If several keys are specified, only the first key is
568
used to encrypt TLS session tickets.
569
This allows configuring key rotation, for example:
570
<example>
571
ssl_session_ticket_key current.key;
572
ssl_session_ticket_key previous.key;
573
</example>
574
</para>
575
576
<para>
577
The <value>file</value> must contain 80 or 48 bytes
578
of random data and can be created using the following command:
579
<example>
580
openssl rand 80 > ticket.key
581
</example>
582
Depending on the file size either AES256 (for 80-byte keys, 1.11.8)
583
or AES128 (for 48-byte keys) is used for encryption.
584
</para>
585
586
</directive>
587
588
589
<directive name="ssl_session_tickets">
590
<syntax><literal>on</literal> | <literal>off</literal></syntax>
591
<default>on</default>
592
<context>mail</context>
593
<context>server</context>
594
<appeared-in>1.5.9</appeared-in>
595
596
<para>
597
Enables or disables session resumption through
598
<link url="https://datatracker.ietf.org/doc/html/rfc5077">TLS session tickets</link>.
599
</para>
600
601
</directive>
602
603
604
<directive name="ssl_session_timeout">
605
<syntax><value>time</value></syntax>
606
<default>5m</default>
607
<context>mail</context>
608
<context>server</context>
609
610
<para>
611
Specifies a time during which a client may reuse the
612
session parameters.
613
</para>
614
615
</directive>
616
617
618
<directive name="ssl_trusted_certificate">
619
<syntax><value>file</value></syntax>
620
<default/>
621
<context>mail</context>
622
<context>server</context>
623
<appeared-in>1.7.11</appeared-in>
624
625
<para>
626
Specifies a <value>file</value> with trusted CA certificates in the PEM format
627
used to <link id="ssl_verify_client">verify</link> client certificates.
628
</para>
629
630
<para>
631
In contrast to the certificate set by <link id="ssl_client_certificate"/>,
632
the list of these certificates will not be sent to clients.
633
</para>
634
635
</directive>
636
637
638
<directive name="ssl_verify_client">
639
<syntax>
640
<literal>on</literal> | <literal>off</literal> |
641
<literal>optional</literal> | <literal>optional_no_ca</literal></syntax>
642
<default>off</default>
643
<context>mail</context>
644
<context>server</context>
645
<appeared-in>1.7.11</appeared-in>
646
647
<para>
648
Enables verification of client certificates.
649
The verification result is passed in the
650
<header>Auth-SSL-Verify</header> header of the
651
<link doc="ngx_mail_auth_http_module.xml" id="auth_http">authentication</link>
652
request.
653
</para>
654
655
<para>
656
The <literal>optional</literal> parameter requests the client
657
certificate and verifies it if the certificate is present.
658
</para>
659
660
<para>
661
The <literal>optional_no_ca</literal> parameter
662
requests the client
663
certificate but does not require it to be signed by a trusted CA certificate.
664
This is intended for the use in cases when a service that is external to nginx
665
performs the actual certificate verification.
666
The contents of the certificate is accessible through requests
667
<link doc="ngx_mail_auth_http_module.xml"
668
id="auth_http_pass_client_cert">sent</link>
669
to the authentication server.
670
</para>
671
672
</directive>
673
674
675
<directive name="ssl_verify_depth">
676
<syntax><value>number</value></syntax>
677
<default>1</default>
678
<context>mail</context>
679
<context>server</context>
680
<appeared-in>1.7.11</appeared-in>
681
682
<para>
683
Sets the verification depth in the client certificates chain.
684
</para>
685
686
</directive>
687
688
689
<directive name="starttls">
690
<syntax>
691
<literal>on</literal> |
692
<literal>off</literal> |
693
<literal>only</literal></syntax>
694
<default>off</default>
695
<context>mail</context>
696
<context>server</context>
697
698
<para>
699
<list type="tag">
700
701
<tag-name><literal>on</literal></tag-name>
702
<tag-desc>
703
allow usage of the <literal>STLS</literal> command for the POP3
704
and the <literal>STARTTLS</literal> command for the IMAP and SMTP;
705
</tag-desc>
706
707
<tag-name><literal>off</literal></tag-name>
708
<tag-desc>
709
deny usage of the <literal>STLS</literal>
710
and <literal>STARTTLS</literal> commands;
711
</tag-desc>
712
713
<tag-name><literal>only</literal></tag-name>
714
<tag-desc>
715
require preliminary TLS transition.
716
</tag-desc>
717
718
</list>
719
</para>
720
721
</directive>
722
723
</section>
724
725
</module>
726
727