summaryrefslogtreecommitdiff
path: root/pod/nginx/ngx_core_module.pod
blob: 249b19af2af6cd3ba32d013af479935cbea43b9a (plain)
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
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
=encoding utf-8

=head1 NAME

ngx_core_module - Core functionality




=head1 Example Configuration




    
    user www www;
    worker_processes 2;
    
    error_log /var/log/nginx-error.log info;
    
    events {
        use kqueue;
        worker_connections 2048;
    }
    
    ...






=head1 Directives

=head2 accept_mutex


B<syntax:> accept_mutex I<C<on> E<verbar> C<off>>


B<default:> I<off>


B<context:> I<events>





If C<accept_mutex> is enabled,
worker processes will accept new connections by turn.
Otherwise, all worker processes will be notified about new connections,
and if volume of new connections is low, some of the worker processes
may just waste system resources.

B<NOTE>

There is no need to enable C<accept_mutex>
on systems that support the
L<EPOLLEXCLUSIVE|events> flag (1.11.3) or
when using L<ngx_http_core_module>.


B<NOTE>

Prior to version 1.11.3, the default value was C<on>.








=head2 accept_mutex_delay


B<syntax:> accept_mutex_delay I<I<C<time>>>


B<default:> I<500ms>


B<context:> I<events>





If L</accept_mutex> is enabled, specifies the maximum time
during which a worker process will try to restart accepting new
connections if another worker process is currently accepting
new connections.







=head2 daemon


B<syntax:> daemon I<C<on> E<verbar> C<off>>


B<default:> I<on>


B<context:> I<main>





Determines whether nginx should become a daemon.
Mainly used during development.







=head2 debug_connection


B<syntax:> debug_connection I<
    I<C<address>> E<verbar>
    I<C<CIDR>> E<verbar>
    C<unix:>>



B<context:> I<events>





Enables debugging log for selected client connections.
Other connections will use logging level set by the
L</error_log> directive.
Debugged connections are specified by IPv4 or IPv6 (1.3.0, 1.2.1)
address or network.
A connection may also be specified using a hostname.
For connections using UNIX-domain sockets (1.3.0, 1.2.1),
debugging log is enabled by the “C<unix:>” parameter.

    
    events {
        debug_connection 127.0.0.1;
        debug_connection localhost;
        debug_connection 192.0.2.0/24;
        debug_connection ::1;
        debug_connection 2001:0db8::/32;
        debug_connection unix:;
        ...
    }



B<NOTE>

For this directive to work, nginx needs to
be built with C<--with-debug>,
see “L<debugging_log>”.








=head2 debug_points


B<syntax:> debug_points I<C<abort> E<verbar> C<stop>>



B<context:> I<main>





This directive is used for debugging.





When internal error is detected, e.g. the leak of sockets on
restart of working processes, enabling C<debug_points>
leads to a core file creation (C<abort>)
or to stopping of a process (C<stop>) for further
analysis using a system debugger.







=head2 env


B<syntax:> env I<I<C<variable>>[=I<C<value>>]>


B<default:> I<TZ>


B<context:> I<main>





By default, nginx removes all environment variables inherited
from its parent process except the TZ variable.
This directive allows preserving some of the inherited variables,
changing their values, or creating new environment variables.
These variables are then:

=over




=item *

inherited during a L<live upgrade|control>
of an executable file;



=item *

used by the
L<ngx_http_perl_module|ngx_http_perl_module> module;



=item *

used by worker processes.
One should bear in mind that controlling system libraries in this way
is not always possible as it is common for libraries to check
variables only during initialization, well before they can be set
using this directive.
An exception from this is an above mentioned
L<live upgrade|control>
of an executable file.



=back







The TZ variable is always inherited and available to the
L<ngx_http_perl_module|ngx_http_perl_module>
module, unless it is configured explicitly.





Usage example:

    
    env MALLOC_OPTIONS;
    env PERL5LIB=/data/site/modules;
    env OPENSSL_ALLOW_PROXY_CERTS=1;








B<NOTE>

The NGINX environment variable is used internally by nginx
and should not be set directly by the user.








=head2 error_log


B<syntax:> error_log I<I<C<file>> [I<C<level>>]>


B<default:> I<logsE<sol>error.log error>


B<context:> I<main>


B<context:> I<http>


B<context:> I<mail>


B<context:> I<stream>


B<context:> I<server>


B<context:> I<location>





Configures logging.
Several logs can be specified on the same configuration level (1.5.2).
If on the C<main> configuration level writing a log to a file
is not explicitly defined, the default file will be used.





The first parameter defines a I<C<file>> that will store the log.
The special value C<stderr> selects the standard error file.
Logging to L<syslog|syslog> can be configured by specifying
the “C<syslog:>” prefix.
Logging to a
L<cyclic memory buffer|debugging_log>
can be configured by specifying the “C<memory:>” prefix and
buffer I<C<size>>, and is generally used for debugging (1.7.11).





The second parameter determines the I<C<level>> of logging,
and can be one of the following:
C<debug>, C<info>, C<notice>,
C<warn>, C<error>, C<crit>,
C<alert>, or C<emerg>.
Log levels above are listed in the order of increasing severity.
Setting a certain log level will cause all messages of
the specified and more severe log levels to be logged.
For example, the default level C<error> will
cause C<error>, C<crit>,
C<alert>, and C<emerg> messages
to be logged.
If this parameter is omitted then C<error> is used.

B<NOTE>

For C<debug> logging to work, nginx needs to
be built with C<--with-debug>,
see “L<debugging_log>”.



B<NOTE>

The directive can be specified on the
C<stream> level
starting from version 1.7.11,
and on the C<mail> level
starting from version 1.9.0.








=head2 events


events { B<...> }



B<context:> I<main>





Provides the configuration file context in which the directives that
affect connection processing are specified.







=head2 include


B<syntax:> include I<I<C<file>> E<verbar> I<C<mask>>>







Includes another I<C<file>>, or files matching the
specified I<C<mask>>, into configuration.
Included files should consist of
syntactically correct directives and blocks.





Usage example:

    
    include mime.types;
    include vhosts/*.conf;









=head2 load_module


B<syntax:> load_module I<I<C<file>>>



B<context:> I<main>



This directive appeared in version 1.9.11.





Loads a dynamic module.





Example:

    
    load_module modules/ngx_mail_module.so;









=head2 lock_file


B<syntax:> lock_file I<I<C<file>>>


B<default:> I<logsE<sol>nginx.lock>


B<context:> I<main>





nginx uses the locking mechanism to implement L</accept_mutex>
and serialize access to shared memory.
On most systems the locks are implemented using atomic operations,
and this directive is ignored.
On other systems the “lock file” mechanism is used.
This directive specifies a prefix for the names of lock files.







=head2 master_process


B<syntax:> master_process I<C<on> E<verbar> C<off>>


B<default:> I<on>


B<context:> I<main>





Determines whether worker processes are started.
This directive is intended for nginx developers.







=head2 multi_accept


B<syntax:> multi_accept I<C<on> E<verbar> C<off>>


B<default:> I<off>


B<context:> I<events>





If C<multi_accept> is disabled, a worker process
will accept one new connection at a time.
Otherwise, a worker process
will accept all new connections at a time.

B<NOTE>

The directive is ignored if L<events>
connection processing method is used, because it reports
the number of new connections waiting to be accepted.








=head2 pcre_jit


B<syntax:> pcre_jit I<C<on> E<verbar> C<off>>


B<default:> I<off>


B<context:> I<main>



This directive appeared in version 1.1.12.





Enables or disables the use of “just-in-time compilation” (PCRE JIT)
for the regular expressions known by the time of configuration parsing.





PCRE JIT can speed up processing of regular expressions significantly.

B<NOTE>

The JIT is available in PCRE libraries starting from version 8.20
built with the C<--enable-jit> configuration parameter.
When the PCRE library is built with nginx (C<--with-pcre=>),
the JIT support is enabled via the
C<--with-pcre-jit> configuration parameter.








=head2 pid


B<syntax:> pid I<I<C<file>>>


B<default:> I<logsE<sol>nginx.pid>


B<context:> I<main>





Defines a I<C<file>> that will store the process ID of the main process.







=head2 ssl_engine


B<syntax:> ssl_engine I<I<C<device>>>



B<context:> I<main>





Defines the name of the hardware SSL accelerator.






B<NOTE>

The module may be dynamically loaded by OpenSSL during configuration testing.








=head2 ssl_object_cache_inheritable


B<syntax:> ssl_object_cache_inheritable I<C<on> E<verbar> C<off>>


B<default:> I<on>


B<context:> I<main>



This directive appeared in version 1.27.4.





If enabled, SSL objects
(SSL certificates, secret keys, trusted CA certificates, CRL lists)
will be inherited across configuration reloads.





SSL objects loaded from a file are inherited
if the modification time and file index has not been changed
since the previous configuration load.
Secret keys specified as
C<engine:name:id> are never inherited.
Secret keys specified as
C<data:value> are always inherited.






B<NOTE>

SSL objects loaded from variables cannot be inherited.






Example:

    
    ssl_object_cache_inheritable on;
    
    http {
        ...
        server {
            ...
            ssl_certificate     example.com.crt;
            ssl_certificate_key example.com.key;
        }
    }









=head2 thread_pool


B<syntax:> thread_pool I<
    I<C<name>>
    C<threads>=I<C<number>>
    [C<max_queue>=I<C<number>>]>


B<default:> I<default threads=32 max_queue=65536>


B<context:> I<main>



This directive appeared in version 1.7.11.





Defines the I<C<name>> and parameters of a thread pool
used for multi-threaded reading and sending of files
L<without blocking|ngx_http_core_module>
worker processes.





The C<threads> parameter
defines the number of threads in the pool.





In the event that all threads in the pool are busy,
a new task will wait in the queue.
The C<max_queue> parameter limits the number
of tasks allowed to be waiting in the queue.
By default, up to 65536 tasks can wait in the queue.
When the queue overflows, the task is completed with an error.







=head2 timer_resolution


B<syntax:> timer_resolution I<I<C<interval>>>



B<context:> I<main>





Reduces timer resolution in worker processes, thus reducing the
number of C<gettimeofday> system calls made.
By default, C<gettimeofday> is called each time
a kernel event is received.
With reduced resolution, C<gettimeofday> is only
called once per specified I<C<interval>>.





Example:

    
    timer_resolution 100ms;







Internal implementation of the interval depends on the method used:

=over




=item *

the C<EVFILT_TIMER> filter if C<kqueue> is used;



=item *

C<timer_create> if C<eventport> is used;



=item *

C<setitimer> otherwise.



=back









=head2 use


B<syntax:> use I<I<C<method>>>



B<context:> I<events>





Specifies the L<connection processing|events>
I<C<method>> to use.
There is normally no need to specify it explicitly, because nginx will
by default use the most efficient method.







=head2 user


B<syntax:> user I<I<C<user>> [I<C<group>>]>


B<default:> I<nobody nobody>


B<context:> I<main>





Defines I<C<user>> and I<C<group>>
credentials used by worker processes.
If I<C<group>> is omitted, a group whose name equals
that of I<C<user>> is used.







=head2 worker_aio_requests


B<syntax:> worker_aio_requests I<I<C<number>>>


B<default:> I<32>


B<context:> I<events>



This directive appeared in version 1.1.4.



This directive appeared in version 1.0.7.





When using L<ngx_http_core_module>
with the L<events>
connection processing method, sets the maximum I<C<number>> of
outstanding asynchronous IE<sol>O operations
for a single worker process.







=head2 worker_connections


B<syntax:> worker_connections I<I<C<number>>>


B<default:> I<512>


B<context:> I<events>





Sets the maximum number of simultaneous connections that
can be opened by a worker process.





It should be kept in mind that this number includes all connections
(e.g. connections with proxied servers, among others),
not only connections with clients.
Another consideration is that the actual number of simultaneous
connections cannot exceed the current limit on
the maximum number of open files, which can be changed by
L</worker_rlimit_nofile>.







=head2 worker_cpu_affinity


B<syntax:> worker_cpu_affinity I<I<C<cpumask>> ...>


B<syntax:> worker_cpu_affinity I<C<auto> [I<C<cpumask>>]>



B<context:> I<main>





Binds worker processes to the sets of CPUs.
Each CPU set is represented by a bitmask of allowed CPUs.
There should be a separate set defined for each of the worker processes.
By default, worker processes are not bound to any specific CPUs.





For example,

    
    worker_processes    4;
    worker_cpu_affinity 0001 0010 0100 1000;


binds each worker process to a separate CPU, while

    
    worker_processes    2;
    worker_cpu_affinity 0101 1010;


binds the first worker process to CPU0E<sol>CPU2,
and the second worker process to CPU1E<sol>CPU3.
The second example is suitable for hyper-threading.





The special value C<auto> (1.9.10) allows
binding worker processes automatically to available CPUs:

    
    worker_processes auto;
    worker_cpu_affinity auto;


The optional mask parameter can be used to limit the CPUs
available for automatic binding:

    
    worker_cpu_affinity auto 01010101;








B<NOTE>

The directive is only available on FreeBSD and Linux.








=head2 worker_priority


B<syntax:> worker_priority I<I<C<number>>>


B<default:> I<0>


B<context:> I<main>





Defines the scheduling priority for worker processes like it is
done by the C<nice> command: a negative
I<C<number>>
means higher priority.
Allowed range normally varies from -20 to 20.





Example:

    
    worker_priority -10;









=head2 worker_processes


B<syntax:> worker_processes I<I<C<number>> E<verbar> C<auto>>


B<default:> I<1>


B<context:> I<main>





Defines the number of worker processes.





The optimal value depends on many factors including (but not
limited to) the number of CPU cores, the number of hard disk
drives that store data, and load pattern.
When one is in doubt, setting it to the number of available CPU cores
would be a good start (the value “C<auto>”
will try to autodetect it).

B<NOTE>

The C<auto> parameter is supported starting from
versions 1.3.8 and 1.2.5.








=head2 worker_rlimit_core


B<syntax:> worker_rlimit_core I<I<C<size>>>



B<context:> I<main>





Changes the limit on the largest size of a core file
(C<RLIMIT_CORE>) for worker processes.
Used to increase the limit without restarting the main process.







=head2 worker_rlimit_nofile


B<syntax:> worker_rlimit_nofile I<I<C<number>>>



B<context:> I<main>





Changes the limit on the maximum number of open files
(C<RLIMIT_NOFILE>) for worker processes.
Used to increase the limit without restarting the main process.







=head2 worker_shutdown_timeout


B<syntax:> worker_shutdown_timeout I<I<C<time>>>



B<context:> I<main>



This directive appeared in version 1.11.11.





Configures a timeout for a graceful shutdown of worker processes.
When the I<C<time>> expires,
nginx will try to close all the connections currently open
to facilitate shutdown.







=head2 working_directory


B<syntax:> working_directory I<I<C<directory>>>



B<context:> I<main>





Defines the current working directory for a worker process.
It is primarily used when writing a core-file, in which case
a worker process should have write permission for the
specified directory.