1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
|
=encoding utf-8
=head1 NAME
ngx_mail_ssl_module - Module ngx_mail_ssl_module
=head1
The C<ngx_mail_ssl_module> module provides the necessary
support for a mail proxy server to work with the SSLE<sol>TLS protocol.
This module is not built by default, it should be enabled with
the C<--with-mail_ssl_module>
configuration parameter.
B<NOTE>
This module requires the L<OpenSSL|http://www.openssl.org>
library.
=head1 Example Configuration
To reduce the processor load, it is recommended to
=over
=item *
set the number of
L<worker processes|ngx_core_module>
equal to the number of processors,
=item *
enable the shared session cache,
=item *
disable the built-in session cache,
=item *
and possibly increase the session lifetime
(by default, 5 minutes):
=back
<emphasis>worker_processes auto;</emphasis>
mail {
...
server {
listen 993 ssl;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
ssl_certificate /usr/local/nginx/conf/cert.pem;
ssl_certificate_key /usr/local/nginx/conf/cert.key;
<emphasis>ssl_session_cache shared:SSL:10m;</emphasis>
<emphasis>ssl_session_timeout 10m;</emphasis>
...
}
=head1 Directives
=head2 ssl
B<syntax:> ssl I<C<on> E<verbar> C<off>>
B<default:> I<off>
B<context:> I<mail>
B<context:> I<server>
This directive was made obsolete in version 1.15.0
and was removed in version 1.25.1.
The C<ssl> parameter
of the L<ngx_mail_core_module> directive
should be used instead.
=head2 ssl_certificate
B<syntax:> ssl_certificate I<I<C<file>>>
B<context:> I<mail>
B<context:> I<server>
Specifies a I<C<file>> with the certificate in the PEM format
for the given server.
If intermediate certificates should be specified in addition to a primary
certificate, they should be specified in the same file in the following
order: the primary certificate comes first, then the intermediate certificates.
A secret key in the PEM format may be placed in the same file.
Since version 1.11.0,
this directive can be specified multiple times
to load certificates of different types, for example, RSA and ECDSA:
server {
listen 993 ssl;
ssl_certificate example.com.rsa.crt;
ssl_certificate_key example.com.rsa.key;
ssl_certificate example.com.ecdsa.crt;
ssl_certificate_key example.com.ecdsa.key;
...
}
B<NOTE>
Only OpenSSL 1.0.2 or higher supports separate certificate chains
for different certificates.
With older versions, only one certificate chain can be used.
The value
C<data>:I<C<certificate>>
can be specified instead of the I<C<file>> (1.15.10),
which loads a certificate without using intermediate files.
Note that inappropriate use of this syntax may have its security implications,
such as writing secret key data to
L<error log|ngx_core_module>.
=head2 ssl_certificate_key
B<syntax:> ssl_certificate_key I<I<C<file>>>
B<context:> I<mail>
B<context:> I<server>
Specifies a I<C<file>> with the secret key in the PEM format
for the given server.
The value
C<engine>:I<C<name>>:I<C<id>>
can be specified instead of the I<C<file>> (1.7.9),
which loads a secret key with a specified I<C<id>>
from the OpenSSL engine I<C<name>>.
The value
C<data>:I<C<key>>
can be specified instead of the I<C<file>> (1.15.10),
which loads a secret key without using intermediate files.
Note that inappropriate use of this syntax may have its security implications,
such as writing secret key data to
L<error log|ngx_core_module>.
=head2 ssl_ciphers
B<syntax:> ssl_ciphers I<I<C<ciphers>>>
B<default:> I<HIGH:!aNULL:!MD5>
B<context:> I<mail>
B<context:> I<server>
Specifies the enabled ciphers.
The ciphers are specified in the format understood by the
OpenSSL library, for example:
ssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
The full list can be viewed using the
“C<openssl ciphers>” command.
B<NOTE>
The previous versions of nginx used
L<different|configuring_https_servers>
ciphers by default.
=head2 ssl_client_certificate
B<syntax:> ssl_client_certificate I<I<C<file>>>
B<context:> I<mail>
B<context:> I<server>
This directive appeared in version 1.7.11.
Specifies a I<C<file>> with trusted CA certificates in the PEM format
used to verify client certificates.
The list of certificates will be sent to clients.
If this is not desired, the L</ssl_trusted_certificate>
directive can be used.
=head2 ssl_conf_command
B<syntax:> ssl_conf_command I<I<C<name>> I<C<value>>>
B<context:> I<mail>
B<context:> I<server>
This directive appeared in version 1.19.4.
Sets arbitrary OpenSSL configuration
L<commands|https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html>.
B<NOTE>
The directive is supported when using OpenSSL 1.0.2 or higher.
Several C<ssl_conf_command> directives
can be specified on the same level:
ssl_conf_command Options PrioritizeChaCha;
ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;
These directives are inherited from the previous configuration level
if and only if there are no C<ssl_conf_command> directives
defined on the current level.
B<NOTE>
Note that configuring OpenSSL directly
might result in unexpected behavior.
=head2 ssl_crl
B<syntax:> ssl_crl I<I<C<file>>>
B<context:> I<mail>
B<context:> I<server>
This directive appeared in version 1.7.11.
Specifies a I<C<file>> with revoked certificates (CRL)
in the PEM format used to verify
client certificates.
=head2 ssl_dhparam
B<syntax:> ssl_dhparam I<I<C<file>>>
B<context:> I<mail>
B<context:> I<server>
This directive appeared in version 0.7.2.
Specifies a I<C<file>> with DH parameters for DHE ciphers.
By default no parameters are set,
and therefore DHE ciphers will not be used.
B<NOTE>
Prior to version 1.11.0, builtin parameters were used by default.
=head2 ssl_ecdh_curve
B<syntax:> ssl_ecdh_curve I<I<C<curve>>>
B<default:> I<auto>
B<context:> I<mail>
B<context:> I<server>
This directive appeared in version 1.1.0.
This directive appeared in version 1.0.6.
Specifies a I<C<curve>> for ECDHE ciphers.
When using OpenSSL 1.0.2 or higher,
it is possible to specify multiple curves (1.11.0), for example:
ssl_ecdh_curve prime256v1:secp384r1;
The special value C<auto> (1.11.0) instructs nginx to use
a list built into the OpenSSL library when using OpenSSL 1.0.2 or higher,
or C<prime256v1> with older versions.
B<NOTE>
Prior to version 1.11.0,
the C<prime256v1> curve was used by default.
B<NOTE>
When using OpenSSL 1.0.2 or higher,
this directive sets the list of curves supported by the server.
Thus, in order for ECDSA certificates to work,
it is important to include the curves used in the certificates.
=head2 ssl_password_file
B<syntax:> ssl_password_file I<I<C<file>>>
B<context:> I<mail>
B<context:> I<server>
This directive appeared in version 1.7.3.
Specifies a I<C<file>> with passphrases for
secret keys
where each passphrase is specified on a separate line.
Passphrases are tried in turn when loading the key.
Example:
mail {
ssl_password_file /etc/keys/global.pass;
...
server {
server_name mail1.example.com;
ssl_certificate_key /etc/keys/first.key;
}
server {
server_name mail2.example.com;
# named pipe can also be used instead of a file
ssl_password_file /etc/keys/fifo;
ssl_certificate_key /etc/keys/second.key;
}
}
=head2 ssl_prefer_server_ciphers
B<syntax:> ssl_prefer_server_ciphers I<C<on> E<verbar> C<off>>
B<default:> I<off>
B<context:> I<mail>
B<context:> I<server>
Specifies that server ciphers should be preferred over client ciphers
when the SSLv3 and TLS protocols are used.
=head2 ssl_protocols
B<syntax:> ssl_protocols I<
[C<SSLv2>]
[C<SSLv3>]
[C<TLSv1>]
[C<TLSv1.1>]
[C<TLSv1.2>]
[C<TLSv1.3>]>
B<default:> I<TLSv1.2 TLSv1.3>
B<context:> I<mail>
B<context:> I<server>
Enables the specified protocols.
B<NOTE>
The C<TLSv1.1> and C<TLSv1.2> parameters
(1.1.13, 1.0.12) work only when OpenSSL 1.0.1 or higher is used.
B<NOTE>
The C<TLSv1.3> parameter (1.13.0) works only when
OpenSSL 1.1.1 or higher is used.
B<NOTE>
The C<TLSv1.3> parameter is used by default
since 1.23.4.
=head2 ssl_session_cache
B<syntax:> ssl_session_cache I<
C<off> E<verbar>
C<none> E<verbar>
[C<builtin>[:I<C<size>>]]
[C<shared>:I<C<name>>:I<C<size>>]>
B<default:> I<none>
B<context:> I<mail>
B<context:> I<server>
Sets the types and sizes of caches that store session parameters.
A cache can be of any of the following types:
=over
=item C<off>
the use of a session cache is strictly prohibited:
nginx explicitly tells a client that sessions may not be reused.
=item C<none>
the use of a session cache is gently disallowed:
nginx tells a client that sessions may be reused, but does not
actually store session parameters in the cache.
=item C<builtin>
a cache built in OpenSSL; used by one worker process only.
The cache size is specified in sessions.
If size is not given, it is equal to 20480 sessions.
Use of the built-in cache can cause memory fragmentation.
=item C<shared>
a cache shared between all worker processes.
The cache size is specified in bytes; one megabyte can store
about 4000 sessions.
Each shared cache should have an arbitrary name.
A cache with the same name can be used in several
servers.
It is also used to automatically generate, store, and
periodically rotate TLS session ticket keys (1.23.2)
unless configured explicitly
using the L</ssl_session_ticket_key> directive.
=back
Both cache types can be used simultaneously, for example:
ssl_session_cache builtin:1000 shared:SSL:10m;
but using only shared cache without the built-in cache should
be more efficient.
=head2 ssl_session_ticket_key
B<syntax:> ssl_session_ticket_key I<I<C<file>>>
B<context:> I<mail>
B<context:> I<server>
This directive appeared in version 1.5.7.
Sets a I<C<file>> with the secret key used to encrypt
and decrypt TLS session tickets.
The directive is necessary if the same key has to be shared between
multiple servers.
By default, a randomly generated key is used.
If several keys are specified, only the first key is
used to encrypt TLS session tickets.
This allows configuring key rotation, for example:
ssl_session_ticket_key current.key;
ssl_session_ticket_key previous.key;
The I<C<file>> must contain 80 or 48 bytes
of random data and can be created using the following command:
openssl rand 80 > ticket.key
Depending on the file size either AES256 (for 80-byte keys, 1.11.8)
or AES128 (for 48-byte keys) is used for encryption.
=head2 ssl_session_tickets
B<syntax:> ssl_session_tickets I<C<on> E<verbar> C<off>>
B<default:> I<on>
B<context:> I<mail>
B<context:> I<server>
This directive appeared in version 1.5.9.
Enables or disables session resumption through
L<TLS session tickets|https://datatracker.ietf.org/doc/html/rfc5077>.
=head2 ssl_session_timeout
B<syntax:> ssl_session_timeout I<I<C<time>>>
B<default:> I<5m>
B<context:> I<mail>
B<context:> I<server>
Specifies a time during which a client may reuse the
session parameters.
=head2 ssl_trusted_certificate
B<syntax:> ssl_trusted_certificate I<I<C<file>>>
B<context:> I<mail>
B<context:> I<server>
This directive appeared in version 1.7.11.
Specifies a I<C<file>> with trusted CA certificates in the PEM format
used to verify client certificates.
In contrast to the certificate set by L</ssl_client_certificate>,
the list of these certificates will not be sent to clients.
=head2 ssl_verify_client
B<syntax:> ssl_verify_client I<
C<on> E<verbar> C<off> E<verbar>
C<optional> E<verbar> C<optional_no_ca>>
B<default:> I<off>
B<context:> I<mail>
B<context:> I<server>
This directive appeared in version 1.7.11.
Enables verification of client certificates.
The verification result is passed in the
C<Auth-SSL-Verify> header of the
L<authentication|ngx_mail_auth_http_module>
request.
The C<optional> parameter requests the client
certificate and verifies it if the certificate is present.
The C<optional_no_ca> parameter
requests the client
certificate but does not require it to be signed by a trusted CA certificate.
This is intended for the use in cases when a service that is external to nginx
performs the actual certificate verification.
The contents of the certificate is accessible through requests
L<sent|ngx_mail_auth_http_module>
to the authentication server.
=head2 ssl_verify_depth
B<syntax:> ssl_verify_depth I<I<C<number>>>
B<default:> I<1>
B<context:> I<mail>
B<context:> I<server>
This directive appeared in version 1.7.11.
Sets the verification depth in the client certificates chain.
=head2 starttls
B<syntax:> starttls I<
C<on> E<verbar>
C<off> E<verbar>
C<only>>
B<default:> I<off>
B<context:> I<mail>
B<context:> I<server>
=over
=item C<on>
allow usage of the C<STLS> command for the POP3
and the C<STARTTLS> command for the IMAP and SMTP;
=item C<off>
deny usage of the C<STLS>
and C<STARTTLS> commands;
=item C<only>
require preliminary TLS transition.
=back
|