Nginx Modules Reference r3
Nginx Modules Reference r3
Modules reference
NGINX Plus - release 3, based on 1.5.12 core
March 21, 2014
Copyright Notice
2012-2014 Nginx, Inc. All rights reserved. NGINX, NGINX Plus and any
Nginx, Inc. product or service name or logo used herein are trademarks of Nginx, Inc.
All other trademarks used herein belong to their respective owners. The trademarks
and logos displayed herein may not be used without the prior written consent of
Nginx, Inc. or their respective owners.
This documentation is provided AS IS and is subject to change without notice
and should not be interpreted as a commitment by Nginx, Inc. This documentation
may not be copied, modified or distributed without authorization of Nginx, Inc. and
may be used only in connection with Nginx, Inc. products and services. Nginx, Inc.
assumes no responsibility or liability for any errors or inaccuracies that may appear
in this documentation.
Preface
About NGINX
NGINX (engine x) is a high performance, high concurrency web server
excelling at large scale content delivery, web acceleration and protecting
application containers. Its precise integration with modern operating systems
allows unprecedented levels of efficiency even when running on commodity
hardware.
Nginx, Inc. develops and maintains NGINX open source distribution, and
offers commercial support and professional services for NGINX.
about
NGINX
products
and
support
at
Contents
Title
Preface
Table of Contents
1 Core modules
1.1 Core functionality . . . . . . . .
1.1.1 Example Configuration .
1.1.2 Directives . . . . . . . .
accept mutex . . . . . .
accept mutex delay . . .
daemon . . . . . . . . .
debug connection . . . .
debug points . . . . . .
error log . . . . . . . . .
env . . . . . . . . . . . .
events . . . . . . . . . .
include . . . . . . . . . .
lock file . . . . . . . . .
master process . . . . .
multi accept . . . . . . .
pcre jit . . . . . . . . .
pid . . . . . . . . . . . .
ssl engine . . . . . . . .
timer resolution . . . . .
use . . . . . . . . . . . .
user . . . . . . . . . . .
worker aio requests . . .
worker connections . . .
worker cpu affinity . . .
worker priority . . . . .
worker processes . . . .
worker rlimit core . . . .
worker rlimit nofile . . .
worker rlimit sigpending
working directory . . . .
3
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
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.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
27
27
28
28
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
29
29
29
29
30
31
31
32
32
32
32
33
33
33
33
34
34
34
34
35
36
36
37
37
37
38
38
39
39
39
40
40
40
41
41
41
44
46
46
46
46
p.4 of 242
CONTENTS
2.2
2.3
msie padding . . . . . . . . .
msie refresh . . . . . . . . . .
open file cache . . . . . . . .
open file cache errors . . . . .
open file cache min uses . . .
open file cache valid . . . . .
optimize server names . . . .
output buffers . . . . . . . . .
port in redirect . . . . . . . .
postpone output . . . . . . .
read ahead . . . . . . . . . .
recursive error pages . . . . .
request pool size . . . . . . .
reset timedout connection . .
resolver . . . . . . . . . . . .
resolver timeout . . . . . . . .
root . . . . . . . . . . . . . .
satisfy . . . . . . . . . . . . .
satisfy any . . . . . . . . . . .
send lowat . . . . . . . . . . .
send timeout . . . . . . . . .
sendfile . . . . . . . . . . . . .
sendfile max chunk . . . . . .
server . . . . . . . . . . . . .
server name . . . . . . . . . .
server name in redirect . . . .
server names hash bucket size
server names hash max size .
server tokens . . . . . . . . .
tcp nodelay . . . . . . . . . .
tcp nopush . . . . . . . . . .
try files . . . . . . . . . . . .
types . . . . . . . . . . . . . .
types hash bucket size . . . .
types hash max size . . . . .
underscores in headers . . . .
variables hash bucket size . .
variables hash max size . . .
2.1.2 Embedded Variables . . . . .
Module ngx http access module . . .
2.2.1 Summary . . . . . . . . . . .
2.2.2 Example Configuration . . . .
2.2.3 Directives . . . . . . . . . . .
allow . . . . . . . . . . . . . .
deny . . . . . . . . . . . . . .
Module ngx http addition module . .
Nginx, Inc.
CONTENTS
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
47
47
47
48
48
48
48
48
49
49
49
49
49
50
50
51
51
51
52
52
52
52
52
53
53
55
55
55
55
55
56
56
58
58
59
59
59
59
59
63
63
63
63
63
63
64
p.5 of 242
CONTENTS
2.3.1
2.3.2
2.3.3
2.4
2.5
2.6
2.7
2.8
2.9
Summary . . . . . . . . . . . .
Example Configuration . . . . .
Directives . . . . . . . . . . . .
add before body . . . . . . . .
add after body . . . . . . . . .
addition types . . . . . . . . . .
Module ngx http auth basic module .
2.4.1 Summary . . . . . . . . . . . .
2.4.2 Example Configuration . . . . .
2.4.3 Directives . . . . . . . . . . . .
auth basic . . . . . . . . . . . .
auth basic user file . . . . . . .
Module ngx http auth request module
2.5.1 Summary . . . . . . . . . . . .
2.5.2 Example Configuration . . . . .
2.5.3 Directives . . . . . . . . . . . .
auth request . . . . . . . . . . .
auth request set . . . . . . . .
Module ngx http autoindex module . .
2.6.1 Summary . . . . . . . . . . . .
2.6.2 Example Configuration . . . . .
2.6.3 Directives . . . . . . . . . . . .
autoindex . . . . . . . . . . . .
autoindex exact size . . . . . .
autoindex localtime . . . . . . .
Module ngx http browser module . . .
2.7.1 Summary . . . . . . . . . . . .
2.7.2 Example Configuration . . . . .
2.7.3 Directives . . . . . . . . . . . .
ancient browser . . . . . . . . .
ancient browser value . . . . .
modern browser . . . . . . . . .
modern browser value . . . . .
Module ngx http charset module . . .
2.8.1 Summary . . . . . . . . . . . .
2.8.2 Example Configuration . . . . .
2.8.3 Directives . . . . . . . . . . . .
charset . . . . . . . . . . . . . .
charset map . . . . . . . . . . .
charset types . . . . . . . . . .
override charset . . . . . . . . .
source charset . . . . . . . . . .
Module ngx http dav module . . . . .
2.9.1 Summary . . . . . . . . . . . .
2.9.2 Example Configuration . . . . .
2.9.3 Directives . . . . . . . . . . . .
Nginx, Inc.
CONTENTS
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
64
64
64
64
64
64
65
65
65
65
65
65
67
67
67
67
67
67
69
69
69
69
69
69
69
70
70
70
70
70
71
71
71
72
72
72
72
72
73
73
74
74
75
75
75
75
p.6 of 242
CONTENTS
dav access . . . . . . . . . .
dav methods . . . . . . . .
create full put path . . . . .
min delete depth . . . . . .
2.10 Module ngx http empty gif module
2.10.1 Summary . . . . . . . . . .
2.10.2 Example Configuration . . .
2.10.3 Directives . . . . . . . . . .
empty gif . . . . . . . . . .
2.11 Module ngx http fastcgi module . .
2.11.1 Summary . . . . . . . . . .
2.11.2 Example Configuration . . .
2.11.3 Directives . . . . . . . . . .
fastcgi bind . . . . . . . . .
fastcgi buffer size . . . . . .
fastcgi buffering . . . . . . .
fastcgi buffers . . . . . . . .
fastcgi busy buffers size . .
fastcgi cache . . . . . . . . .
fastcgi cache bypass . . . .
fastcgi cache key . . . . . .
fastcgi cache lock . . . . . .
fastcgi cache lock timeout .
fastcgi cache methods . . .
fastcgi cache min uses . . .
fastcgi cache path . . . . .
fastcgi cache purge . . . . .
fastcgi cache revalidate . . .
fastcgi cache use stale . . .
fastcgi cache valid . . . . .
fastcgi catch stderr . . . . .
fastcgi connect timeout . .
fastcgi hide header . . . . .
fastcgi ignore client abort .
fastcgi ignore headers . . .
fastcgi index . . . . . . . . .
fastcgi intercept errors . . .
fastcgi keep conn . . . . . .
fastcgi max temp file size .
fastcgi next upstream . . .
fastcgi no cache . . . . . . .
fastcgi param . . . . . . . .
fastcgi pass . . . . . . . . .
fastcgi pass header . . . . .
fastcgi read timeout . . . .
fastcgi pass request body .
Nginx, Inc.
CONTENTS
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.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
.
.
.
.
.
.
.
.
.
.
.
.
.
89
89
89
90
90
91
91
91
92
92
93
93
93
93
93
93
94
94
94
94
94
95
95
95
95
95
95
96
97
97
98
98
98
98
98
101
101
101
101
101
101
102
102
102
102
102
p.8 of 242
CONTENTS
2.18
2.19
2.20
2.21
2.22
2.23
gzip buffers . . . . . . . . . .
gzip comp level . . . . . . . .
gzip disable . . . . . . . . . .
gzip min length . . . . . . . .
gzip http version . . . . . . .
gzip proxied . . . . . . . . . .
gzip types . . . . . . . . . . .
gzip vary . . . . . . . . . . .
2.17.4 Embedded Variables . . . . .
Module ngx http gzip static module
2.18.1 Summary . . . . . . . . . . .
2.18.2 Example Configuration . . . .
2.18.3 Directives . . . . . . . . . . .
gzip static . . . . . . . . . . .
Module ngx http headers module . .
2.19.1 Summary . . . . . . . . . . .
2.19.2 Example Configuration . . . .
2.19.3 Directives . . . . . . . . . . .
add header . . . . . . . . . .
expires . . . . . . . . . . . . .
Module ngx http hls module . . . . .
2.20.1 Summary . . . . . . . . . . .
2.20.2 Example Configuration . . . .
2.20.3 Directives . . . . . . . . . . .
hls . . . . . . . . . . . . . . .
hls buffers . . . . . . . . . . .
hls fragment . . . . . . . . . .
hls mp4 buffer size . . . . . .
hls mp4 max buffer size . . .
Module ngx http image filter module
2.21.1 Summary . . . . . . . . . . .
2.21.2 Example Configuration . . . .
2.21.3 Directives . . . . . . . . . . .
image filter . . . . . . . . . .
image filter buffer . . . . . . .
image filter interlace . . . . .
image filter jpeg quality . . .
image filter sharpen . . . . .
image filter transparency . . .
Module ngx http index module . . .
2.22.1 Summary . . . . . . . . . . .
2.22.2 Example Configuration . . . .
2.22.3 Directives . . . . . . . . . . .
index . . . . . . . . . . . . . .
Module ngx http limit conn module
2.23.1 Summary . . . . . . . . . . .
Nginx, Inc.
CONTENTS
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.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
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
102
102
103
103
103
103
104
104
104
105
105
105
105
105
106
106
106
106
106
106
108
108
108
108
108
108
109
109
109
110
110
110
110
110
111
111
111
112
112
113
113
113
113
113
114
114
p.9 of 242
CONTENTS
2.24
2.25
2.26
2.27
2.28
Nginx, Inc.
CONTENTS
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.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
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
130
130
130
131
132
132
132
133
134
134
134
134
135
135
135
138
138
138
138
138
138
138
139
139
139
140
140
140
140
141
141
141
142
143
143
143
144
144
145
146
146
146
146
146
147
147
p.11 of 242
CONTENTS
2.31
2.32
2.33
2.34
Nginx, Inc.
CONTENTS
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
147
148
148
149
149
151
151
151
151
152
153
153
154
154
154
155
155
155
156
156
157
157
158
158
158
158
158
159
159
159
159
159
159
160
161
161
161
161
161
161
161
163
163
163
163
163
p.12 of 242
CONTENTS
2.35
2.36
2.37
2.38
2.39
return . . . . . . . . . . . . .
rewrite . . . . . . . . . . . . .
rewrite log . . . . . . . . . . .
set . . . . . . . . . . . . . . .
uninitialized variable warn . .
2.34.3 Internal Implementation . . .
Module ngx http secure link module
2.35.1 Summary . . . . . . . . . . .
2.35.2 Directives . . . . . . . . . . .
secure link . . . . . . . . . . .
secure link md5 . . . . . . . .
secure link secret . . . . . . .
2.35.3 Embedded Variables . . . . .
Module ngx http session log module
2.36.1 Summary . . . . . . . . . . .
2.36.2 Example Configuration . . . .
2.36.3 Directives . . . . . . . . . . .
session log format . . . . . .
session log zone . . . . . . . .
session log . . . . . . . . . . .
2.36.4 Embedded Variables . . . . .
Module ngx http spdy module . . . .
2.37.1 Summary . . . . . . . . . . .
2.37.2 Known Bugs . . . . . . . . . .
2.37.3 Example Configuration . . . .
2.37.4 Directives . . . . . . . . . . .
spdy chunk size . . . . . . . .
spdy headers comp . . . . . .
2.37.5 Embedded Variables . . . . .
Module ngx http split clients module
2.38.1 Summary . . . . . . . . . . .
2.38.2 Example Configuration . . . .
2.38.3 Directives . . . . . . . . . . .
split clients . . . . . . . . . .
Module ngx http ssi module . . . . .
2.39.1 Summary . . . . . . . . . . .
2.39.2 Example Configuration . . . .
2.39.3 Directives . . . . . . . . . . .
ssi . . . . . . . . . . . . . . .
ssi last modified . . . . . . .
ssi min file chunk . . . . . . .
ssi silent errors . . . . . . . .
ssi types . . . . . . . . . . . .
ssi value length . . . . . . . .
2.39.4 SSI Commands . . . . . . . .
2.39.5 Embedded Variables . . . . .
Nginx, Inc.
CONTENTS
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
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.3
3.4
3.5
3.6
3.7
protocol . . . . . . . . . . .
resolver . . . . . . . . . . .
resolver timeout . . . . . . .
server . . . . . . . . . . . .
server name . . . . . . . . .
so keepalive . . . . . . . . .
timeout . . . . . . . . . . .
Module ngx mail pop3 module . .
3.2.1 Directives . . . . . . . . . .
pop3 auth . . . . . . . . . .
pop3 capabilities . . . . . .
Module ngx mail imap module . .
3.3.1 Directives . . . . . . . . . .
imap auth . . . . . . . . . .
imap capabilities . . . . . .
imap client buffer . . . . . .
Module ngx mail smtp module . .
3.4.1 Directives . . . . . . . . . .
smtp auth . . . . . . . . . .
smtp capabilities . . . . . .
Module ngx mail auth http module
3.5.1 Directives . . . . . . . . . .
auth http . . . . . . . . . .
auth http header . . . . . .
auth http timeout . . . . .
3.5.2 Protocol . . . . . . . . . . .
Module ngx mail proxy module . .
3.6.1 Directives . . . . . . . . . .
proxy buffer . . . . . . . . .
proxy pass error message .
proxy timeout . . . . . . . .
xclient . . . . . . . . . . . .
Module ngx mail ssl module . . . .
3.7.1 Summary . . . . . . . . . .
3.7.2 Directives . . . . . . . . . .
ssl . . . . . . . . . . . . . .
ssl certificate . . . . . . . .
ssl certificate key . . . . . .
ssl prefer server ciphers . .
ssl protocols . . . . . . . . .
ssl session cache . . . . . .
ssl session ticket key . . . .
ssl session timeout . . . . .
starttls . . . . . . . . . . . .
Nginx, Inc.
CONTENTS
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
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.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
218
219
219
220
220
220
220
221
221
221
221
222
222
222
222
222
223
223
223
223
224
224
224
224
224
224
227
227
227
227
227
227
229
229
229
229
229
229
229
230
230
231
231
231
232
p.16 of 242
CONTENTS
CONTENTS
234
C Legal Notices
235
Index
238
Nginx, Inc.
p.17 of 242
Chapter 1
Core modules
1.1
1.1.1
Core functionality
Example Configuration
1.1.2
Directives
accept mutex
syntax:
default
context:
accept_mutex on | off;
on
events
18
127.0.0.1;
localhost ;
192.0.2.0/24;
::1;
2001:0 db8 ::/32;
unix :;
debug points
syntax: debug_points abort | stop;
default
context: main
Nginx, Inc.
p.19 of 242
error log
syntax:
Configures logging. Several logs can be specified on the same level (1.5.2).
The first parameter defines a file that will store the log.
The special value stderr selects the standard error file. Logging to syslog
can be configured by specifying the syslog: prefix.
The second parameter determines the level of logging. 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 error will cause error, crit, alert, and emerg
messages to be logged. If this parameter is omitted then error is used.
For debug logging to work, nginx needs to be built with --with-debug,
see A debugging log.
The following parameters configure logging to syslog:
server=address
Defines an address of a syslog server. An address can be specified as a
domain name or IP address, and an optional port, or as a UNIX-domain
socket path specified after the unix: prefix. If port is not specified, the
port 514 is used. If a domain name resolves to several IP addresses, the
first resolved address is used.
facility=string
Sets facility of syslog messages, as defined in RFC 3164. Facility can
be one of kern, user, mail, daemon, auth, intern, lpr,
news, uucp, clock, authpriv, ftp, ntp, audit, alert,
cron, local0..local7. Default is local7.
tag=string
Sets tag of syslog messages. Default is nginx.
Example syslog configuration:
error_log syslog : server =192.168.1.1 debug ;
error_log syslog : server = unix :/ var / log / nginx . sock ;
error_log syslog : server =[2001: db8 ::1]:12345 , facility = local7 , tag = nginx
error ;
Nginx, Inc.
p.20 of 242
env
syntax: env variable[=value];
default TZ
context: main
events
syntax: events { . . . }
default
context: main
Provides the configuration file context in which the directives that affect
connection processing are specified.
include
syntax: include file | mask;
default
context: any
p.21 of 242
lock file
syntax: lock_file file;
default logs/nginx.lock
context: main
nginx uses the locking mechanism to implement 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.
master process
syntax: master_process on | off;
default on
context: main
pcre jit
syntax: pcre_jit on | off;
default off
context: main
This directive appeared in version 1.1.12.
Nginx, Inc.
p.22 of 242
pid
syntax: pid file;
default nginx.pid
context: main
Defines a file that will store the process ID of the main process.
ssl engine
syntax: ssl_engine device;
default
context: main
Nginx, Inc.
p.23 of 242
use
syntax: use method;
default
context: events
When using aio with the epoll connection processing method, sets the
maximum number of outstanding asynchronous I/O operations for a single
worker process.
worker connections
syntax: worker_connections number;
default 512
context: events
Nginx, Inc.
p.24 of 242
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,
w or k er _ pr o ce s se s
4;
w o r k e r _ c p u _ a f f i n i t y 0001 0010 0100 1000;
binds the first worker process to CPU0/CPU2, and the second worker
process to CPU1/CPU3. The second example is suitable for hyper-threading.
The directive is only available on FreeBSD and Linux.
worker priority
syntax: worker_priority number;
default 0
context: main
Defines the scheduling priority for worker processes like it is done by the
nice command: a negative number means higher priority. Allowed range
normally varies from -20 to 20.
Example:
wo rker _pri orit y -10;
worker processes
syntax: worker_processes number | auto;
default 1
context: main
Nginx, Inc.
p.25 of 242
Changes the limit on the largest size of a core file (RLIMIT_CORE) for worker
processes. Used to increase the limit without restarting the main process.
worker rlimit nofile
syntax: worker_rlimit_nofile number;
default
context: main
Nginx, Inc.
p.26 of 242
1.2
1.2.1
Setting up hashes
Overview
To quickly process static sets of data such as server names, map directives
values, MIME types, names of request header strings, nginx uses hash tables.
During the start and each re-configuration nginx selects the minimum possible
sizes of hash tables such that the bucket size that stores keys with identical
hash values does not exceed the configured parameter (hash bucket size). The
size of a table is expressed in buckets. The adjustment is continued until
the table size exceeds the hash max size parameter. Most hashes have the
corresponding directives that allow to change these parameters, for example,
for the server names hash they are server names hash max size and server names hash bucket size.
The hash bucket size parameter is aligned to the size that is a multiple of
the processors cache line size. This speeds up key search in a hash on modern
processors by reducing the number of memory accesses. If hash bucket size is
equal to one processors cache line size then the number of memory accesses
during the key search will be two in the worst case first to compute the
bucket address, and second during the key search inside the bucket. Therefore,
if nginx emits the message requesting to increase either hash max size or hash
bucket size then the first parameter should first be increased.
Nginx, Inc.
p.27 of 242
1.3
1.3.1
Overview
Nginx, Inc.
p.28 of 242
Chapter 2
HTTP server modules
2.1
2.1.1
aio
syntax: aio on | off | sendfile;
default off
context: http, server, location
This directive appeared in version 0.8.11.
Enables or disables the use of asynchronous file I/O (AIO) on FreeBSD and
Linux.
On FreeBSD, AIO can be used starting from FreeBSD 4.3. AIO can either
be linked statically into a kernel:
options VFS_AIO
29
The requirement to use the Giant lock with AIO is related to the fact
that FreeBSD supports asynchronous calls aio_read and aio_write when
working with sockets. However, since nginx uses AIO only for disk I/O, no
problems should arise.
For AIO to work, sendfile needs to be disabled:
location / video / {
sendfile
off ;
aio
on ;
output_buffers 1 64 k ;
}
In addition, starting from FreeBSD 5.2.1 and nginx 0.8.12, AIO can also
be used to pre-load data for sendfile:
location / video / {
sendfile
on ;
tcp_nopush
on ;
aio
sendfile ;
}
On Linux, directio can only be used for reading blocks that are aligned on
512-byte boundaries (or 4K for XFS). Files unaligned end is read in blocking
mode. The same holds true for byte range requests and for FLV requests not
from the beginning of a file: reading of unaligned data at the beginning and
end of a file will be blocking. There is no need to turn off sendfile explicitly,
as it is turned off automatically when directio is used.
alias
syntax: alias path;
default
context: location
Defines a replacement for the specified location. For example, with the
following configuration
Nginx, Inc.
p.30 of 242
location / i / {
alias / data / w3 / images /;
}
Sets buffer size for reading client request body. In case the request body is
larger than the buffer, the whole body or only its part is written to a temporary
file. By default, buffer size is equal to two memory pages. This is 8K on x86,
other 32-bit platforms, and x86-64. It is usually 16K on other 64-bit platforms.
Nginx, Inc.
p.31 of 242
Determines whether nginx should save the entire client request body into
a file. This directive can be used during debugging, or when using the
$request body file variable, or the $r->request body file method of the module
ngx http perl module.
When set to the value on, temporary files are not removed after request
processing.
The value clean will cause the temporary files left after request processing
to be removed.
client body in single buffer
syntax: client_body_in_single_buffer on | off;
default off
context: http, server, location
Determines whether nginx should save the entire client request body in
a single buffer. The directive is recommended when using the $request body
variable, to save the number of copy operations involved.
client body temp path
syntax: client_body_temp_path path [level1 [level2 [level3]]];
default client_body_temp
context: http, server, location
Defines a directory for storing temporary files holding client request bodies.
Up to three-level subdirectory hierarchy can be used under the specified
directory. For example, in the following configuration
c l i e n t _ b o d y _ t e m p _ p a t h / spool / nginx / client_temp 1 2;
Defines a timeout for reading client request body. The timeout is set only
for a period between two successive read operations, not for the transmission
Nginx, Inc.
p.32 of 242
of the whole request body. If a client does not transmit anything within this
time, the 408 Request Time-out error is returned to the client.
client header buffer size
syntax: client_header_buffer_size size;
default 1k
context: http, server
Sets buffer size for reading client request header. For most requests, a
buffer of 1K bytes is enough. However, if a request includes long cookies, or
comes from a WAP client, it may not fit into 1K. If a request line or a request
header field does not fit into this buffer then larger buffers, configured by the
large client header buffers directive, are allocated.
client header timeout
syntax: client_header_timeout time;
default 60s
context: http, server
Defines a timeout for reading client request header. If a client does not
transmit the entire header within this time, the 408 Request Time-out error
is returned to the client.
client max body size
syntax: client_max_body_size size;
default 1m
context: http, server, location
Sets the maximum allowed size of the client request body, specified in
the Content-Length request header field. If the size in a request exceeds the
configured value, the 413 Request Entity Too Large error is returned to
the client. Please be aware that browsers cannot correctly display this error.
Setting size to 0 disables checking of client request body size.
connection pool size
syntax: connection_pool_size size;
default 256
context: http, server
Nginx, Inc.
p.33 of 242
default type
syntax: default_type mime-type;
default text/plain
context: http, server, location
Enables the use of the O_DIRECT flag (FreeBSD, Linux), the F_NOCACHE flag
(Mac OS X), or the directio function (Solaris), when reading files that are
larger than or equal to the specified size. The directive automatically disables
(0.7.15) the use of sendfile for a given request. It can be useful for serving large
files:
directio 4 m ;
disable_symlinks off;
disable_symlinks on | if_not_owner [from=part];
off
http, server, location
Nginx, Inc.
p.34 of 242
on
If any component of the pathname is a symbolic link, access to a file is
denied.
if_not_owner
Access to a file is denied if any component of the pathname is a symbolic
link, and the link and object that the link points to have different owners.
from=part
When checking symbolic links (parameters on and if_not_owner), all
components of the pathname are normally checked. Checking of symbolic
links in the initial part of the pathname may be avoided by specifying
additionally the from=part parameter. In this case, symbolic links are
checked only from the pathname component that follows the specified
initial part. If the value is not an initial part of the pathname checked,
the whole pathname is checked as if this parameter was not specified
at all. If the value matches the whole file name, symbolic links are not
checked. The parameter value can contain variables.
Example:
d is a bl e _s y ml i nk s on from = $document_root ;
This directive is only available on systems that have the openat and
fstatat interfaces. Such systems include modern versions of FreeBSD, Linux,
and Solaris.
Parameters on and if_not_owner add a processing overhead.
On systems that do not support opening of directories only for search,
to use these parameters it is required that worker processes have read
permissions for all directories being checked.
The ngx http autoindex module, ngx http random index module, and
ngx http dav module modules currently ignore this directive.
error page
syntax: error_page code . . . [=[response]] uri;
default
context: http, server, location, if in location
Defines the URI that will be shown for the specified errors. error_page
directives are inherited from the previous level only if there are no error_page
directives defined on the current level. A uri value can contain variables.
Example:
error_page 404
/404. html ;
error_page 500 502 503 504 /50 x . html ;
Nginx, Inc.
p.35 of 242
In this case, by default, the response code 302 is returned to the client. It
can only be changed to one of the redirect status codes (301, 302, 303, and
307).
If there is no need to change URI during internal redirection it is possible
to pass error processing into a named location:
location / {
error_page 404 = @fallback ;
}
location @fallback {
proxy_pass http :// backend ;
}
If uri processing leads to an error, the status code of the last occurred
error is returned to the client.
etag
syntax: etag on | off;
default on
context: http, server, location
This directive appeared in version 1.3.3.
Provides the configuration file context in which the HTTP server directives
are specified.
Nginx, Inc.
p.36 of 242
if modified since
syntax: if_modified_since off | exact | before;
default exact
context: http, server, location
This directive appeared in version 0.7.24.
Specifies that a given location can only be used for internal requests. For
external requests, the client error 404 Not Found is returned. Internal requests
are the following:
requests redirected by the error page, index, random index, and try files
directives;
requests redirected by the X-Accel-Redirect response header field from
an upstream server;
subrequests formed by the include virtual command of the ngx http ssi module module and by the ngx http addition module module
directives;
Nginx, Inc.
p.37 of 242
keepalive disable
syntax: keepalive_disable none | browser . . . ;
default msie6
context: http, server, location
keepalive requests
syntax: keepalive_requests number;
default 100
context: http, server, location
This directive appeared in version 0.8.0.
Sets the maximum number of requests that can be served through one
keep-alive connection. After the maximum number of requests are made, the
connection is closed.
Nginx, Inc.
p.38 of 242
keepalive timeout
syntax: keepalive_timeout timeout [header timeout];
default 75s
context: http, server, location
Sets the maximum number and size of buffers used for reading large client
request header. A request line cannot exceed the size of one buffer, or the 414
Request-URI Too Large error is returned to the client. A request header field
cannot exceed the size of one buffer as well, or the 400 Bad Request error is
returned to the client. Buffers are allocated only on demand. By default,
the buffer size is equal to 8K bytes. If after the end of request processing a
connection is transitioned into the keep-alive state, these buffers are released.
limit except
syntax: limit_except method . . . { . . . }
default
context: location
Please note that this will limit access to all methods except GET and
HEAD.
Nginx, Inc.
p.39 of 242
limit rate
syntax: limit_rate rate;
default 0
context: http, server, location, if in location
Sets the initial amount after which the further transmission of a response
to a client will be rate limited.
Example:
location / flv / {
flv ;
l im i t_ r at e _a f te r 500 k ;
limit_rate
50 k ;
}
lingering close
syntax: lingering_close off | on | always;
default on
context: http, server, location
This directive appeared in versions 1.1.0 and 1.0.6.
Nginx, Inc.
p.40 of 242
The default value on instructs nginx to wait for and process additional
data from a client before fully closing a connection, but only if heuristics
suggests that a client may be sending more data.
The value always will cause nginx to unconditionally wait for and process
additional client data.
The value off tells nginx to never wait for more data and close the
connection immediately. This behavior breaks the protocol and should not
be used under normal circumstances.
lingering time
syntax: lingering_time time;
default 30s
context: http, server, location
When lingering close is in effect, this directive specifies the maximum time
during which nginx will process (read and ignore) additional data coming from
a client. After that, the connection will be closed, even if there will be more
data.
lingering timeout
syntax: lingering_timeout time;
default 5s
context: http, server, location
Nginx, Inc.
p.41 of 242
Sets the address and port for IP, or the path for a UNIX-domain socket on
which the server will accept requests. Both address and port, or only address
or only port can be specified. An address may also be a hostname, for example:
listen
listen
listen
listen
listen
Nginx, Inc.
p.42 of 242
fastopen=number
enables TCP Fast Open for the listening socket (1.5.8) and limits
the maximum length for the queue of connections that have not yet
completed the three-way handshake.
Do not enable this feature unless the server can handle receiving the
same SYN packet with data more than once.
backlog=number
sets the backlog parameter in the listen call that limits the maximum
length for the queue of pending connections. By default, backlog is set
to -1 on FreeBSD and Mac OS X, and to 511 on other platforms.
rcvbuf=size
sets the receive buffer size (the SO_RCVBUF option) for the listening socket.
sndbuf=size
sets the send buffer size (the SO_SNDBUF option) for the listening socket.
accept_filter=filter
sets the name of accept filter (the SO_ACCEPTFILTER option) for the
listening socket that filters incoming connections before passing them
to accept. This works only on FreeBSD and NetBSD 5.0+. Possible
values are dataready and httpready.
deferred
instructs to use a deferred accept (the TCP_DEFER_ACCEPT socket option)
on Linux.
bind
instructs to make a separate bind call for a given address:port pair. This
is useful because if there are several listen directives with the same
port but different addresses, and one of the listen directives listens
on all addresses for the given port (*:port), nginx will bind only to
*:port. It should be noted that the getsockname system call will be
made in this case to determine the address that accepted the connection.
If the setfib, backlog, rcvbuf, sndbuf, accept_filter, deferred, or
so_keepalive parameters are used then for a given address:port pair a
separate bind call will always be made.
ipv6only=on|off
this parameter (0.7.42) determines (via the IPV6_V6ONLY socket option)
whether an IPv6 socket listening on a wildcard address [::] will
accept only IPv6 connections or both IPv6 and IPv4 connections. This
parameter is turned on by default. It can only be set once on start.
Prior to version 1.3.4, if this parameter was omitted then the operating
systems settings were in effect for the socket.
so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]
this parameter (1.1.11) configures the TCP keepalive behavior for the
listening socket. If this parameter is omitted then the operating systems
Nginx, Inc.
p.43 of 242
settings will be in effect for the socket. If it is set to the value on, the
SO_KEEPALIVE option is turned on for the socket. If it is set to the
value off, the SO_KEEPALIVE option is turned off for the socket. Some
operating systems support setting of TCP keepalive parameters on a persocket basis using the TCP_KEEPIDLE, TCP_KEEPINTVL, and TCP_KEEPCNT
socket options. On such systems (currently, Linux 2.4+, NetBSD 5+,
and FreeBSD 9.0-STABLE), they can be configured using the keepidle,
keepintvl, and keepcnt parameters. One or two parameters may be
omitted, in which case the system default setting for the corresponding
socket option will be in effect. For example,
so_keepalive =30 m ::10
will set the idle timeout (TCP_KEEPIDLE) to 30 minutes, leave the probe
interval (TCP_KEEPINTVL) at its system default, and set the probes count
(TCP_KEEPCNT) to 10 probes.
Example:
listen 127.0.0.1 default_server accept_filter = dataready backlog =1024;
location
syntax:
syntax:
default
context:
location [ = | ~ | ~* | ^~ ] uri { . . . }
location @name { . . . }
server, location
p.44 of 242
Regular expressions can contain captures (0.7.40) that can later be used in
other directives.
If the longest matching prefix location has the ^~ modifier then regular
expressions are not checked.
Also, using the = modifier it is possible to define an exact match of
URI and location. If an exact match is found, the search terminates. For
example, if a / request happens frequently, defining location = / will
speed up the processing of these requests, as search terminates right after the
first comparison. Such a location cannot obviously contain nested locations.
In versions from 0.7.1 to 0.8.41, if a request matched the prefix location
without the = and ^~ modifiers, the search also terminated and regular
expressions were not checked.
Lets illustrate the above by an example:
location = / {
[ configuration A ]
}
location / {
[ configuration B ]
}
location / documents / {
[ configuration C ]
}
location ^~ / images / {
[ configuration D ]
}
location ~* \.( gif | jpg | jpeg ) $ {
[ configuration E ]
}
Nginx, Inc.
p.45 of 242
location = / user {
proxy_pass http :// login . example . com ;
}
Enables or disables logging of errors about not found files into error log.
log subrequest
syntax: log_subrequest on | off;
default off
context: http, server, location
So it gets converted to
p.46 of 242
open_file_cache off;
open_file_cache max=N [inactive=time];
off
http, server, location
p.47 of 242
off
disables the cache.
Example:
op en_f ile_ cach e
open_file_cache_valid
open_file_cache_min_uses
open_file_cache_errors
Sets the minimum number of file accesses during the period configured by
the inactive parameter of the open file cache directive, required for a file
descriptor to remain open in the cache.
open file cache valid
syntax: open_file_cache_valid time;
default 60s
context: http, server, location
Sets a time after which open file cache elements should be validated.
optimize server names
syntax: optimize_server_names on | off;
default off
context: http, server
Sets the number and size of buffers used for reading a response from a disk.
Nginx, Inc.
p.48 of 242
port in redirect
syntax: port_in_redirect on | off;
default on
context: http, server, location
Sets the amount of pre-reading for the kernel when working with file.
On Linux, the posix_fadvise(0, 0, 0, POSIX_FADV_SEQUENTIAL) system call is used, and so the size parameter is ignored.
On FreeBSD, the fcntl(O_READAHEAD, size) system call, supported since
FreeBSD 9.0-CURRENT, is used. FreeBSD 7 has to be patched.
recursive error pages
syntax: recursive_error_pages on | off;
default off
context: http, server, location
Enables or disables doing several redirects using the error page directive.
The number of such redirects is limited.
request pool size
syntax: request_pool_size size;
default 4k
context: http, server
Nginx, Inc.
p.49 of 242
Before version 1.1.9, tuning of caching time was not possible, and nginx
always cached answers for the duration of 5 minutes.
Nginx, Inc.
p.50 of 242
resolver timeout
syntax: resolver_timeout time;
default 30s
context: http, server, location
root
syntax: root path;
default html
context: http, server, location, if in location
location / i / {
root / data / w3 ;
}
Allows access if all (all) or at least one (any) of the ngx http access module, ngx http auth basic module or ngx http auth request module
modules allow access.
Example:
location / {
satisfy any ;
allow 192 .168 .1.0 /32 ;
deny all ;
auth_basic
" closed site ";
a u t h _ b a s i c _ u s e r _ f i l e conf / htpasswd ;
}
Nginx, Inc.
p.51 of 242
satisfy any
syntax: satisfy_any on | off;
default off
context: http, server, location
This directive has been replaced by the any parameter of the satisfy
directive.
send lowat
syntax: send_lowat size;
default 0
context: http, server, location
If the directive is set to a non-zero value, nginx will try to minimize the
number of send operations on client sockets by using either NOTE_LOWAT flag
of the kqueue method or the SO_SNDLOWAT socket option. In both cases the
specified size is used.
This directive is ignored on Linux, Solaris, and Windows.
send timeout
syntax: send_timeout time;
default 60s
context: http, server, location
When set to a non-zero value, limits the amount of data that can be
transferred in a single sendfile call. Without the limit, one fast connection
may seize the worker process entirely.
Nginx, Inc.
p.52 of 242
server
syntax: server { . . . }
default
context: http
Regular expressions can contain captures (0.7.40) that can later be used in
other directives:
server {
server_name ~^( www \.) ?(.+) $ ;
location / {
Nginx, Inc.
p.53 of 242
root / sites / $2 ;
}
}
server {
server_name _ ;
location / {
root / sites / default ;
}
}
It allows this server to process requests without the Host header field
instead of the default server for the given address:port pair. This is the
default setting.
Before 0.8.48, the machines hostname was used by default.
During searching for a virtual server by name, if the name matches more
than one of the specified variants, (e.g. both a wildcard name and regular
expression match), the first matching variant will be chosen, in the following
order of priority:
1. the exact name
2. the longest wildcard
*.example.com
name
starting
with
an
asterisk,
e.g.
Nginx, Inc.
p.54 of 242
Enables or disables the use of the primary server name, specified by the
server name directive, in redirects issued by nginx. When the use of the
primary server name is disabled, the name from the Host request header field
is used. If this field is not present, the IP address of the server is used.
The use of a port in redirects is controlled by the port in redirect directive.
server names hash bucket size
syntax: server_names_hash_bucket_size size;
default 32|64|128
context: http
Sets the bucket size for the server names hash tables. The default value
depends on the size of the processors cache line. The details of setting up
hash tables are provided in a separate document.
server names hash max size
syntax: server_names_hash_max_size size;
default 512
context: http
Sets the maximum size of the server names hash tables. The details of
setting up hash tables are provided in a separate document.
server tokens
syntax: server_tokens on | off;
default on
context: http, server, location
Nginx, Inc.
p.55 of 242
server, location
Checks the existence of files in the specified order and uses the first found
file for request processing; the processing is performed in the current context.
The path to a file is constructed from the file parameter according to the root
and alias directives. It is possible to check directorys existence by specifying
a slash at the end of a name, e.g. $uri/. If none of the files were found,
an internal redirect to the uri specified in the last parameter is made. For
example:
location / images / {
try_files $uri / images / default . gif ;
}
location = / images / default . gif {
expires 30 s ;
}
Nginx, Inc.
p.56 of 242
location / {
try_files / system / maintenance . html
$uri $uri / index . html $uri . html
@mongrel ;
}
location @mongrel {
proxy_pass http :// mongrel ;
}
And here,
location ~ \. php$ {
try_files $uri @drupal ;
fastcgi_pass ...;
fastcgi_param SCR IPT_ FIL ENAM E / path / t o $ f a s t c g i _ s c r i p t _ n a m e ;
...
}
Nginx, Inc.
p.57 of 242
try_files checks the existence of the PHP file before passing the request
to the FastCGI server.
Example for Wordpress and Joomla:
location / {
try_files $uri $uri / @wordpress ;
}
location ~ \. php$ {
try_files $uri @wordpress ;
fastcgi_pass ...;
fastcgi_param SCR IPT_ FIL ENAM E / path / t o $ f a s t c g i _ s c r i p t _ n a m e ;
... other fastcgi_param s
}
location @wordpress {
fastcgi_pass ...;
fastcgi_param SCR IPT_ FIL ENAM E / path / to / index . php ;
... other fastcgi_param s
}
types
syntax: types { . . . }
default
text/html html; image/gif gif; image/jpeg jpg;
context: http, server, location
Nginx, Inc.
p.58 of 242
Sets the bucket size for the types hash tables. The default value depends
on the size of the processors cache line. The details of setting up hash tables
are provided in a separate document.
types hash max size
syntax: types_hash_max_size size;
default 1024
context: http, server, location
Sets the maximum size of the types hash tables. The details of setting up
hash tables are provided in a separate document.
underscores in headers
syntax: underscores_in_headers on | off;
default off
context: http, server
Sets the bucket size for the variables hash table. The details of setting up
hash tables are provided in a separate document.
variables hash max size
syntax: variables_hash_max_size size;
default 512
context: http
Sets the maximum size of the variables hash table. The details of setting
up hash tables are provided in a separate document.
2.1.2
Embedded Variables
Nginx, Inc.
p.59 of 242
representing client request header fields, such as $http user agent, $http cookie,
and so on. Also there are other variables:
$arg name
argument name in the request line
$args
arguments in the request line
$binary remote addr
client address in a binary form, values length is always 4 bytes
$body bytes sent
number of bytes sent to a client, not counting the response header; this
variable is compatible with the %B parameter of the mod_log_config
Apache module
$bytes sent
number of bytes sent to a client (1.3.8, 1.2.5)
$connection
connection serial number (1.3.8, 1.2.5)
$connection requests
current number of requests made through a connection (1.3.8, 1.2.5)
$content length
Content-Length request header field
$content type
Content-Type request header field
$cookie name
the name cookie
$document root
root or alias directives value for the current request
$document uri
same as $uri
$host
in this order of precedence: host name from the request line, or host
name from the Host request header field, or the server name matching a
request
$hostname
host name
$http name
arbitrary request header field; the last part of a variable name is the field
name converted to lower case with dashes replaced by underscores
$https
on if connection operates in SSL mode, or an empty string otherwise
$is args
? if a request line has arguments, or an empty string otherwise
$limit rate
setting this variable enables response rate limiting; see limit rate
$msec
current time in seconds with the milliseconds resolution (1.3.9, 1.2.6)
Nginx, Inc.
p.60 of 242
$nginx version
nginx version
$pid
PID of the worker process
$pipe
p if request was pipelined, . otherwise (1.3.12, 1.2.7)
$proxy protocol addr
client address from the PROXY protocol header, or an empty string
otherwise (1.5.12)
The PROXY protocol must be previously enabled by setting the proxy_protocol parameter in the listen directive.
$query string
same as $args
$realpath root
an absolute pathname corresponding to the root or alias directives value
for the current request, with all symbolic links resolved to real paths
$remote addr
client address
$remote port
client port
$remote user
user name supplied with the Basic authentication
$request
full original request line
$request body
request body
The variables value is made available in locations processed by the
proxy pass and fastcgi pass directives.
$request body file
name of a temporary file with the request body
At the end of processing, the file needs to be removed. To always write
the request body to a file, client body in file only needs to be enabled.
When the name of a temporary file is passed in a proxied request or in a
request to a FastCGI server, passing the request body should be disabled
by the proxy pass request body off and fastcgi pass request body off
directives, respectively.
$request completion
OK if a request has completed, or an empty string otherwise
$request filename
file path for the current request, based on the root or alias directives,
and the request URI
$request length
request length (including request line, header, and request body) (1.3.12,
1.2.7)
$request method
Nginx, Inc.
p.61 of 242
Nginx, Inc.
p.62 of 242
2.2
2.2.1
2.2.2
Example Configuration
location / {
deny 192.168.1.1;
allow 192 .168 .1.0 /24 ;
allow 10.1.1.0/16;
allow 2001:0 db8 ::/32;
deny all ;
}
The rules are checked in sequence until the first match is found. In
this example, access is allowed only for IPv4 networks 10.1.1.0/16 and
192.168.1.0/24 excluding the address 192.168.1.1, and for IPv6 network
2001:0db8::/32. In case of a lot of rules, the use of the ngx http geo module
module variables is preferable.
2.2.3
Directives
allow
syntax: allow address | CIDR | unix: | all;
default
context: http, server, location, limit except
Allows access for the specified network or address. If the special value
unix: is specified (1.5.1), allows access for all UNIX-domain sockets.
deny
syntax: deny address | CIDR | unix: | all;
default
context: http, server, location, limit except
Denies access for the specified network or address. If the special value
unix: is specified (1.5.1), denies access for all UNIX-domain sockets.
Nginx, Inc.
p.63 of 242
2.3
2.3.1
2.3.2
Example Configuration
location / {
ad d_be fore _bod y / before_action ;
add_after_body / after_action ;
}
2.3.3
Directives
Adds the text returned as a result of processing a given subrequest after the
response body. An empty string ("") as a parameter cancels addition inherited
from the previous configuration level.
addition types
syntax: addition_types mime-type . . . ;
default text/html
context: http, server, location
This directive appeared in version 0.7.9.
Allows adding text in responses with the specified MIME types, in addition
to text/html. The special value * matches any MIME type (0.8.29).
Nginx, Inc.
p.64 of 242
2.4
2.4.1
2.4.2
Example Configuration
location / {
auth_basic
" closed site ";
a u t h _ b a s i c _ u s e r _ f i l e conf / htpasswd ;
}
2.4.3
Directives
auth basic
syntax: auth_basic string | off;
default off
context: http, server, location, limit except
Enables validation of user name and password using the HTTP Basic
Authentication protocol. The specified parameter is used as a realm.
Parameter value can contain variables (1.3.10, 1.2.7). The special value off
allows cancelling the effect of the auth_basic directive inherited from the
previous configuration level.
auth basic user file
syntax: auth_basic_user_file file;
default
context: http, server, location, limit except
Specifies a file that keeps user names and passwords, in the following format:
# comment
name1 : password1
name2 : password2 : comment
name3 : password3
p.65 of 242
Nginx, Inc.
p.66 of 242
2.5
2.5.1
2.5.2
Example Configuration
location / private / {
auth_request / auth ;
...
}
location = / auth {
proxy_pass ...
p r o x y _ p a s s _ r e q u e s t _ b o d y off ;
p ro x y_ s et _ he a de r Content - Length "";
p ro x y_ s et _ he a de r X - Original - URI $request_uri ;
}
2.5.3
Directives
auth request
syntax: auth_request uri | off;
default off
context: http, server, location
Enables authorization based on the result of a subrequest and sets the URI
to which the subrequest will be sent.
auth request set
syntax: auth_request_set variable value;
default
context: http, server, location
Nginx, Inc.
p.67 of 242
Sets the request variable to the given value after the authorization request
completes. The value may contain variables from the authorization request,
such as $upstream http *.
Nginx, Inc.
p.68 of 242
2.6
2.6.1
2.6.2
Example Configuration
location / {
autoindex on ;
}
2.6.3
Directives
autoindex
syntax: autoindex on | off;
default off
context: http, server, location
Specifies whether exact file sizes should be output in the directory listing,
or rather rounded to kilobytes, megabytes, and gigabytes.
autoindex localtime
syntax: autoindex_localtime on | off;
default off
context: http, server, location
Specifies whether times in the directory listing should be output in the local
time zone or UTC.
Nginx, Inc.
p.69 of 242
2.7
2.7.1
2.7.2
Example Configuration
msie
gecko
opera
safari
konqueror
5.5;
1.0.0;
9.0;
413;
3.0;
msie
gecko
opera
safari
konqueror
5.0;
0.9.1;
8.0;
413;
3.0;
modern_browser unlisted ;
an cien t_br owse r Links Lynx netscape4 ;
if ( $ an c ie n t_ b ro w se r ) {
rewrite ^ / ancient . html ;
}
2.7.3
Directives
ancient browser
syntax: ancient_browser string . . . ;
default
context: http, server, location
Nginx, Inc.
p.70 of 242
Nginx, Inc.
p.71 of 242
2.8
2.8.1
2.8.2
Example Configuration
include
charset
windows -1251;
source_charset koi8 - r ;
2.8.3
Directives
charset
syntax: charset charset | off;
default off
context: http, server, location, if in location
Adds the specified charset to the Content-Type response header field. If this
charset is different from the charset specified in the source charset directive, a
conversion is performed.
The parameter off cancels the addition of charset to the Content-Type
response header field.
A charset can be defined with a variable:
charset $charset ;
p.72 of 242
charset map
syntax: charset_map charset1 charset2 { . . . }
default
context: http
When describing a conversion table to UTF-8, codes for the UTF-8 charset
should be given in the second column, for example:
charset_map
C0 D18E
C1 D0B0
C2 D0B1
C3 D186
...
}
koi8 - r utf -8 {
; # small yu
; # small a
; # small b
; # small ts
Full conversion tables from koi8-r to windows-1251, and from koi8-r and
windows-1251 to utf-8 are provided in the distribution files conf/koi-win,
conf/koi-utf, and conf/win-utf.
charset types
syntax:
default
charset_types mime-type . . . ;
text/html text/xml text/plain text/vnd.wap.wml
application/javascript application/rss+xml
context: http, server, location
This directive appeared in version 0.7.9.
Nginx, Inc.
p.73 of 242
override charset
syntax: override_charset on | off;
default off
context: http, server, location, if in location
source charset
syntax: source_charset charset;
default
context: http, server, location, if in location
Nginx, Inc.
p.74 of 242
2.9
2.9.1
2.9.2
Example Configuration
location / {
root
/ data / www ;
c l i e n t _ b o d y _ t e m p _ p a t h / data / client_temp ;
dav_methods PUT DELETE MKCOL COPY MOVE ;
create_full_put_path
dav_access
on ;
group : rw
all : r ;
limit_except GET {
allow 192 .168 .1.0 /32 ;
deny all ;
}
}
2.9.3
Directives
dav access
syntax: dav_access users:permissions . . . ;
default user:rw
context: http, server, location
Sets access permissions for newly created files and directories, e.g.:
dav_access user : rw group : rw all : r ;
If any group or all access permissions are specified then user permissions
may be omitted:
dav_access group : rw all : r ;
Nginx, Inc.
p.75 of 242
dav methods
syntax: dav_methods off | method . . . ;
default off
context: http, server, location
Allows the specified HTTP and WebDAV methods. The parameter off
denies all methods processed by this module. The following methods are
supported: PUT, DELETE, MKCOL, COPY, and MOVE.
A file uploaded with the PUT method is first written to a temporary file,
and then the file is renamed. Starting from version 0.8.9, temporary files and
the persistent store can be put on different file systems. However, be aware
that in this case a file is copied across two file systems instead of the cheap
renaming operation. It is thus recommended that for any given location both
saved files and a directory holding temporary files, set by the client body temp path directive, are put on the same file system.
When creating a file with the PUT method, it is possible to specify the
modification date by passing it in the Date header field.
create full put path
syntax: create_full_put_path on | off;
default off
context: http, server, location
Allows the DELETE method to remove files provided that the number of
elements in a request path is not less than the specified number. For example,
the directive
m in _ de l et e _d e pt h 4;
Nginx, Inc.
p.76 of 242
2.10
2.10.1
Summary
2.10.2
Example Configuration
location = / _ . gif {
empty_gif ;
}
2.10.3
Directives
empty gif
syntax: empty_gif;
default
context: location
Nginx, Inc.
p.77 of 242
2.11
2.11.1
Summary
2.11.2
Example Configuration
location / {
fastcgi_pass localhost :9000;
fastcgi_index index . php ;
fastcgi_param SCR IPT_ FIL ENAM E
php$fastcgi_script_name ;
fastcgi_param QUERY_STRING
fastcgi_param REQUEST_METHOD
fastcgi_param CONTENT_TYPE
fastcgi_param CONTENT_LENGTH
2.11.3
Directives
fastcgi bind
syntax: fastcgi_bind address | off;
default
context: http, server, location
This directive appeared in version 0.8.22.
Sets the size of the buffer used for reading the first part of a response
received from the FastCGI server. This part usually contains a small response
header. By default, the buffer size is equal to the size of one buffer set by the
fastcgi buffers directive. It can be made smaller however.
Nginx, Inc.
p.78 of 242
fastcgi buffering
syntax: fastcgi_buffering on | off;
default on
context: http, server, location
This directive appeared in version 1.5.6.
Sets the number and size of buffers used for reading a response from the
FastCGI server, for a single connection. By default, the buffer size is equal to
one memory page. This is either 4K or 8K, depending on a platform.
fastcgi busy buffers size
syntax: fastcgi_busy_buffers_size size;
default 8k|16k
context: http, server, location
When buffering of responses from the FastCGI server is enabled, limits the
total size of buffers that can be busy sending a response to the client while the
response is not yet fully read. In the mean time, the rest of the buffers can be
used for reading a response and, if needed, buffering part of a response to a
temporary file. By default, size is limited by the size of two buffers set by the
fastcgi buffer size and fastcgi buffers directives.
fastcgi cache
syntax: fastcgi_cache zone | off;
default off
context: http, server, location
Nginx, Inc.
p.79 of 242
Defines a shared memory zone used for caching. The same zone can be
used in several places. The off parameter disables caching inherited from the
previous configuration level.
fastcgi cache bypass
syntax: fastcgi_cache_bypass string . . . ;
default
context: http, server, location
Defines conditions under which the response will not be taken from a cache.
If at least one value of the string parameters is not empty and is not equal to
0 then the response will not be taken from the cache:
f a s t c g i _ c a c h e _ b y p a s s $coo kie_ noc ache $ a r g _ n o c a c h e $ a r g _ c o m m e n t ;
f a s t c g i _ c a c h e _ b y p a s s $http_pragma
$http_authorization ;
When enabled, only one request at a time will be allowed to populate a new
cache element identified according to the fastcgi cache key directive by passing
a request to a FastCGI server. Other requests of the same cache element will
either wait for a response to appear in the cache or the cache lock for this
element to be released, up to the time set by the fastcgi cache lock timeout
directive.
fastcgi cache lock timeout
syntax: fastcgi_cache_lock_timeout time;
default 5s
context: http, server, location
This directive appeared in version 1.1.12.
Nginx, Inc.
p.80 of 242
If the client request method is listed in this directive then the response will
be cached. GET and HEAD methods are always added to the list, though
it is recommended to specify them explicitly. See also the fastcgi no cache
directive.
fastcgi cache min uses
syntax: fastcgi_cache_min_uses number;
default 1
context: http, server, location
Sets the number of requests after which the response will be cached.
fastcgi cache path
syntax:
Sets the path and other parameters of a cache. Cache data are stored in
files. Both the key and file name in a cache are a result of applying the MD5
function to the proxied URL.
The levels parameter defines hierarchy levels of a cache. For example, in
the following configuration
f a s t c g i _ c a c h e _ p a t h / data / nginx / cache levels =1:2 keys_zone = one :10 m ;
A cached response is first written to a temporary file, and then the file is
renamed. Starting from version 0.8.9, temporary files and the cache can be put
on different file systems. However, be aware that in this case a file is copied
across two file systems instead of the cheap renaming operation. It is thus
recommended that for any given location both cache and a directory holding
temporary files, set by the fastcgi temp path directive, are put on the same
file system.
Nginx, Inc.
p.81 of 242
In addition, all active keys and information about data are stored in a
shared memory zone, whose name and size are configured by the keys_zone
parameter. Cached data that are not accessed during the time specified by the
inactive parameter get removed from the cache regardless of their freshness.
By default, inactive is set to 10 minutes.
The special cache manager process monitors the maximum cache size set
by the max_size parameter. When this size is exceeded, it removes the least
recently used data.
A minute after the start the special cache loader process is activated. It
loads information about previously cached data stored on file system into a
cache zone. The loading is done in iterations. During one iteration no more
than loader_files items are loaded (by default, 100). Besides, the duration of
one iteration is limited by the loader_threshold parameter (by default, 200
milliseconds). Between iterations, a pause configured by the loader_sleep
parameter (by default, 50 milliseconds) is made.
fastcgi cache purge
syntax: fastcgi_cache_purgestring . . . ;
default
context: http, server, location
This directive appeared in version 1.5.7.
Defines conditions under which the request will be considered a cache purge
request. If at least one value of the string parameters is not empty and
is not equal to 0 then the cache entry with a corresponding cache key is
removed. The result of successful operation is indicated by returning the 204
No Content response.
If the cache key of a purge request ends with an asterisk (*), all cache
entries matching the wildcard key will be removed from the cache.
Example configuration:
f a s t c g i _ c a c h e _ p a t h / data / nginx / cache keys_zone = cache_zone :10 m ;
map $re ques t_m etho d $purge_method {
PURGE
1;
default 0;
}
server {
...
location / {
fastcgi_pass backend ;
fastcgi_cache cache_zone ;
f a s t c g i _ c a c h e _ k e y $uri ;
f a s t c g i _ c a c h e _ p u r g e $purge_method ;
}
}
Nginx, Inc.
p.82 of 242
Sets caching time for different response codes. For example, the following
directives
f a s t c g i _ c a c h e _ v a l i d 200 302 10 m ;
f a s t c g i _ c a c h e _ v a l i d 404
1m;
set 10 minutes of caching for responses with codes 200 and 302 and 1 minute
for responses with code 404.
If only caching time is specified
fastcgi_cache_valid 5m;
Nginx, Inc.
p.83 of 242
Parameters of caching can also be set directly in the response header. This
has higher priority than setting of caching time using the directive. The XAccel-Expires header field sets caching time of a response in seconds. The zero
value disables caching for a response. If a value starts with the @ prefix, it
sets an absolute time in seconds since Epoch, up to which the response may
be cached. If header does not include the X-Accel-Expires field, parameters of
caching may be set in the header fields Expires or Cache-Control. If a header
includes the Set-Cookie field, such a response will not be cached. Processing of
one or more of these response header fields can be disabled using the fastcgi ignore headers directive.
fastcgi catch stderr
syntax: fastcgi_catch_stderr string;
default
context: http, server, location
Sets a string to search for in the error stream of a response received from
a FastCGI server. If the string is found then it is considered that the FastCGI
server has returned an invalid response. This allows handling application errors
in nginx, for example:
location / php {
fastcgi_pass backend :9000;
...
f a s t c g i _ c a t c h _ s t d e r r " PHP Fatal error ";
f a s t c g i _ n e x t _ u p s t r e a m error timeout invalid_header ;
}
By default, nginx does not pass the header fields Status and X-Accel-. . .
from the response of a FastCGI server to a client. The fastcgi_hide_header
directive sets additional fields that will not be passed. If, on the contrary, the
passing of fields needs to be permitted, the fastcgi pass header directive can
be used.
Nginx, Inc.
p.84 of 242
Sets a file name that will be appended after a URI that ends with a slash, in
the value of the $fastcgi script name variable. For example, with these settings
fastcgi_index index . php ;
fastcgi_param SCR IPT _FIL ENAM E / home / www / scripts / p h p $ f a s t c g i _ s c r i p t _ n a m e ;
Nginx, Inc.
p.85 of 242
By default, a FastCGI server will close a connection right after sending the
response. However, when this directive is set to the value on, nginx will instruct
a FastCGI server to keep connections open. This is necessary, in particular,
for keepalive connections to FastCGI servers to function.
fastcgi max temp file size
syntax: fastcgi_max_temp_file_size size;
default 1024m
context: http, server, location
When buffering of responses from the FastCGI server is enabled, and the
whole response does not fit into the memory buffers set by the fastcgi buffer size and fastcgi buffers directives, a part of the response can be saved to a
temporary file. This directive sets the maximum size of a temporary file. The
size of data written to a temporary file at a time is set by the fastcgi temp file write size directive.
The zero value disables buffering of responses to temporary files.
fastcgi next upstream
syntax:
p.86 of 242
invalid_header
a server returned an empty or invalid response;
http_500
a server returned a response with the code 500;
http_503
a server returned a response with the code 503;
http_403
a server returned a response with the code 403;
http_404
a server returned a response with the code 404;
off
disables passing a request to the next server.
One should bear in mind that passing a request to the next server is only
possible if nothing has been sent to a client yet. That is, if an error or timeout
occurs in the middle of the transferring of a response, fixing this is impossible.
The directive also defines what is considered an unsuccessful attempt of
communication with a server. The cases of error, timeout and invalid_header are always considered unsuccessful attempts, even if they are not
specified in the directive. The cases of http_500 and http_503 are considered
unsuccessful attempts only if they are specified in the directive. The cases of
http_403 and http_404 are never considered unsuccessful attempts.
fastcgi no cache
syntax: fastcgi_no_cache string . . . ;
default
context: http, server, location
Defines conditions under which the response will not be saved to a cache.
If at least one value of the string parameters is not empty and is not equal to
0 then the response will not be saved:
f as t cg i _n o _c a ch e $ cook ie_n ocac he $ a r g _ n o c a c h e $ a r g _ c o m m e n t ;
f as t cg i _n o _c a ch e $http_pragma
$http_authorization ;
Sets a parameter that should be passed to the FastCGI server. A value can
contain text, variables, and their combination. These directives are inherited
from the previous level if and only if there are no fastcgi_param directives
defined on the current level.
The following example shows the minimum required settings for PHP:
Nginx, Inc.
p.87 of 242
$https if_not_empty ;
fastcgi pass
syntax: fastcgi_pass address;
default
context: location, if in location
p.88 of 242
Indicates whether the original request body is passed to the FastCGI server.
See also the fastcgi pass request headers directive.
fastcgi pass request headers
syntax: fastcgi_pass_request_headers on | off;
default on
context: http, server, location
Indicates whether the header fields of the original request are passed to the
FastCGI server. See also the fastcgi pass request body directive.
fastcgi send lowat
syntax: fastcgi_send_lowat size;
default 0
context: http, server, location
If the directive is set to a non-zero value, nginx will try to minimize the
number of send operations on outgoing connections to a FastCGI server by
using either NOTE_LOWAT flag of the kqueue method, or the SO_SNDLOWAT socket
option, with the specified size.
This directive is ignored on Linux, Solaris, and Windows.
fastcgi send timeout
syntax: fastcgi_send_timeout time;
default 60s
context: http, server, location
p.89 of 242
Defines a regular expression that captures a value for the $fastcgi path info
variable. A regular expression should have two captures: the first becomes a
value of the $fastcgi script name variable, the second becomes a value of the
$fastcgi path info variable. For example, with these settings
location ~ ^(.+\. php ) (.*) $ {
fastcgi_split_path_info
^(.+\. php ) (.*) $ ;
fastcgi_param SCR IPT_ FIL ENAM E / path / to / p h p $ f a s t c g i _ s c r i p t _ n a m e ;
fastcgi_param PATH_INFO
$fastcgi_path_info ;
Enables saving of files to a disk. The on parameter saves files with paths
corresponding to the directives alias or root. The off parameter disables saving
of files. In addition, the file name can be set explicitly using the string with
variables:
fastcgi_store / data / ww w $o r ig i na l _u r i ;
/ data / www ;
404 = / fetch$uri ;
location / fetch / {
internal ;
fastcgi_pass
Nginx, Inc.
backend :9000;
p.90 of 242
...
fastcgi_store
on ;
f a s t c g i _ s t o r e _ a c c e s s user : rw group : rw all : r ;
fastcgi_temp_path
/ data / temp ;
alias
/ data / www /;
Sets access permissions for newly created files and directories, e.g.:
f a s t c g i _ s t o r e _ a c c e s s user : rw group : rw all : r ;
If any group or all access permissions are specified then user permissions
may be omitted:
f a s t c g i _ s t o r e _ a c c e s s group : rw all : r ;
Limits the size of data written to a temporary file at a time, when buffering
of responses from the FastCGI server to temporary files is enabled. By default,
size is limited by two buffers set by the fastcgi buffer size and fastcgi buffers
directives. The maximum size of a temporary file is set by the fastcgi max temp file size directive.
fastcgi temp path
syntax: fastcgi_temp_path path [level1 [level2 [level3]]];
default fastcgi_temp
context: http, server, location
Defines a directory for storing temporary files with data received from
FastCGI servers. Up to three-level subdirectory hierarchy can be used
underneath the specified directory. For example, in the following configuration
f a s t c g i _ t e m p _ p a t h / spool / nginx / fastcgi_temp 1 2;
Nginx, Inc.
p.91 of 242
2.11.4
HTTP request header fields are passed to the FastCGI server as parameters.
In applications and scripts running as FastCGI servers, these parameters are
usually made available as environment variables. For example, the User-Agent
header field is passed as the HTTP_USER_AGENT parameter. In addition to
HTTP request header fields, it is possible to pass arbitrary parameters using
the fastcgi param directive.
2.11.5
Embedded Variables
the
SCRIPT_FILENAME
parameter
will
be
equal
to
/home/www/scripts/php/info/index.php.
When using the fastcgi split path info directive, the $fastcgi script name
variable equals the value of the first capture set by the directive.
$fastcgi path info
the value of the second capture set by the fastcgi split path info
directive. This variable can be used to set the PATH_INFO parameter.
Nginx, Inc.
p.92 of 242
2.12
2.12.1
Summary
2.12.2
Example Configuration
location / video / {
f4f ;
...
}
2.12.3
Directives
f4f
syntax: f4f;
default
context: location
Sets the size of a memory buffer used for reading the .f4x index file.
Nginx, Inc.
p.93 of 242
2.13
2.13.1
Summary
2.13.2
Example Configuration
location ~ \. flv$ {
flv ;
}
2.13.3
Directives
flv
syntax: flv;
default
context: location
Nginx, Inc.
p.94 of 242
2.14
2.14.1
Summary
2.14.2
Example Configuration
http {
geoip_country
geoip_city
geoip_proxy
geoip_proxy
geoip_proxy_recursive
...
2.14.3
GeoIP . dat ;
GeoLiteCity . dat ;
192.168.100.0/24;
2001:0 db8 ::/32;
on ;
Directives
geoip country
syntax: geoip_country file;
default
context: http
geoip city
syntax: geoip_city file;
default
context: http
Nginx, Inc.
p.95 of 242
p.96 of 242
geoip proxy
syntax: geoip_proxy address | CIDR;
default
context: http
This directive appeared in versions 1.3.0 and 1.2.1.
If recursive search is disabled then instead of the original client address that
matches one of the trusted addresses, the last address sent in X-Forwarded-For
will be used. If recursive search is enabled then instead of the original client
address that matches one of the trusted addresses, the last non-trusted address
sent in X-Forwarded-For will be used.
Nginx, Inc.
p.97 of 242
2.15
2.15.1
Summary
2.15.2
Example Configuration
geo $geo {
default
0;
127.0.0.1
2;
192.168.1.0/24 1;
10.1.0.0/16
1;
::1
2;
2001:0 db8 ::/32 1;
}
2.15.3
Directives
geo
syntax: geo [$address] $variable { . . . }
default
context: http
Since variables are evaluated only when used, the mere existence of even
a large number of declared geo variables does not cause any extra costs for
request processing.
If the value of a variable does not represent a valid IP address then the
255.255.255.255 address is used.
Addresses are specified either as prefixes in CIDR notation (including
individual addresses) or as ranges (0.7.23).
IPv6 prefixes are supported starting from versions 1.3.10 and 1.2.7.
The following special parameters are also supported:
Nginx, Inc.
p.98 of 242
delete
deletes the specified network (0.7.23).
default
a value set to the variable if the client address does not match any of
the specified addresses. When addresses are specified in CIDR notation,
0.0.0.0/0 and ::/0 can be used instead of default. When default
is not specified, the default value will be an empty string.
include
includes a file with addresses and values. There can be several inclusions.
proxy
defines trusted addresses (0.8.7, 0.7.63). When a request comes from a
trusted address, an address from the X-Forwarded-For request header
field will be used instead. In contrast to the regular addresses, trusted
addresses are checked sequentially.
Trusted IPv6 addresses are supported starting from versions 1.3.0 and
1.2.1.
proxy_recursive
enables recursive address search (1.3.0, 1.2.1). If recursive search is
disabled then instead of the original client address that matches one
of the trusted addresses, the last address sent in X-Forwarded-For will
be used. If recursive search is enabled then instead of the original client
address that matches one of the trusted addresses, the last non-trusted
address sent in X-Forwarded-For will be used.
ranges
indicates that addresses are specified as ranges (0.7.23). This parameter
should be the first. To speed up loading of a geo base, addresses should
be put in ascending order.
Example:
geo $country {
default
include
delete
proxy
proxy
127.0.0.0/24
127.0.0.1/32
10.1.0.0/16
192.168.1.0/24
ZZ ;
conf / geo . conf ;
127.0.0.0/16;
192.168.100.0/24;
2001:0 db8 ::/32;
US ;
RU ;
RU ;
UK ;
A value of the most specific match is used. For example, for the 127.0.0.1
address the value RU will be chosen, not US.
Nginx, Inc.
p.99 of 242
Nginx, Inc.
ZZ ;
US ;
RU ;
US ;
RU ;
UK ;
p.100 of 242
2.16
2.16.1
Summary
2.16.2
Example Configuration
location / storage / {
gunzip on ;
...
}
2.16.3
Directives
gunzip
syntax: gunzip on | off;
default off
context: http, server, location
Nginx, Inc.
p.101 of 242
2.17
2.17.1
Summary
2.17.2
Example Configuration
gzip
gz ip_m in_l engt h
gzip_proxied
gzip_types
on ;
1000;
expired no - cache no - store private auth ;
text / plain application / xml ;
The $gzip ratio variable can be used to log the achieved compression ratio.
2.17.3
Directives
gzip
syntax: gzip on | off;
default off
context: http, server, location, if in location
Sets the number and size of buffers used to compress a response. By default,
the buffer size is equal to one memory page. This is either 4K or 8K, depending
on a platform.
Until version 0.7.28, four 4K or 8K buffers were used by default.
Nginx, Inc.
p.102 of 242
gzip disable
syntax: gzip_disable regex . . . ;
default
context: http, server, location
This directive appeared in version 0.6.23.
Sets the minimum length of a response that will be gzipped. The length is
determined only from the Content-Length response header field.
gzip http version
syntax: gzip_http_version 1.0 | 1.1;
default 1.1
context: http, server, location
p.103 of 242
no-store
enables compression if a response header includes the Cache-Control field
with the no-store parameter;
private
enables compression if a response header includes the Cache-Control field
with the private parameter;
no_last_modified
enables compression if a response header does not include the LastModified field;
no_etag
enables compression if a response header does not include the ETag field;
auth
enables compression if a request header includes the Authorization field;
any
enables compression for all proxied requests.
gzip types
syntax: gzip_types mime-type . . . ;
default text/html
context: http, server, location
2.17.4
Embedded Variables
$gzip ratio
achieved compression ratio, computed as the ratio between the original
and compressed response sizes.
Nginx, Inc.
p.104 of 242
2.18
2.18.1
Summary
The ngx_http_gzip_static_module module allows sending precompressed files with the .gz filename extension instead of regular files.
This module is not built by default, it should be enabled with the
--with-http_gzip_static_module configuration parameter.
2.18.2
Example Configuration
gzip_static on ;
gzip_proxied expired no - cache no - store private auth ;
2.18.3
Directives
gzip static
syntax: gzip_static on | off | always;
default off
context: http, server, location
Nginx, Inc.
p.105 of 242
2.19
2.19.1
Summary
2.19.2
Example Configuration
expires
expires
expires
expires
expires
expires
add_header
2.19.3
24 h ;
modified +24 h ;
@24h ;
0;
-1;
epoch ;
Cache - Control private ;
Directives
add header
syntax: add_header name value;
default
context: http, server, location, if in location
Adds the specified field to a response header provided that the response
code equals 200, 201, 204, 206, 301, 302, 303, 304, or 307. A value can contain
variables.
There could be several add_header directives. These directives are
inherited from the previous level if and only if there are no add_header
directives defined on the current level.
expires
syntax:
syntax:
default
context:
p.106 of 242
expires @15h30m ;
The epoch parameter corresponds to the absolute time Thu, 01 Jan 1970
00:00:01 GMT. The contents of the Cache-Control field depends on the sign
of the specified time:
time is negative Cache-Control: no-cache.
time is positive or zero Cache-Control: max-age=t, where t is a time
specified in the directive, in seconds.
The max parameter sets Expires to the value Thu, 31 Dec 2037
23:55:55 GMT, and Cache-Control to 10 years.
The off parameter disables adding or modifying the Expires and CacheControl response header fields.
Nginx, Inc.
p.107 of 242
2.20
2.20.1
Summary
2.20.2
Example Configuration
location / video / {
hls ;
hls_fragment
hls_buffers
hls_mp4_buffer_size
hls_mp4_max_buffer_size
alias / var / video /;
}
5s;
10 10 m ;
1m;
5m;
With this configuration, the following URIs are supported for the /var
/video/test.mp4 file:
http :// hls . example . com / video / test . mp4 . m3u8 ? len =8.000
http :// hls . example . com / video / test . mp4 . ts ? start =1.000& end =2.200
2.20.3
Directives
hls
syntax: hls;
default
context: location
Sets the maximum number and size of buffers that are used for reading and
writing data frames.
Nginx, Inc.
p.108 of 242
hls fragment
syntax: hls_fragment time;
default 5s
context: http, server, location
Defines the default fragment length for playlist URIs requested without the
len argument.
hls mp4 buffer size
syntax: hls_mp4_buffer_size size;
default 512k
context: http, server, location
Sets the initial size of the memory buffer used to process MP4 files.
hls mp4 max buffer size
syntax: hls_mp4_max_buffer_size size;
default 10m
context: http, server, location
During metadata processing, a larger buffer may become necessary. Its size
cannot exceed the specified size, or else nginx will return the server error 500
Internal Server Error, and log the following message:
"/ some / movie / file . mp4 " mp4 moov atom is too large :
12583268 , you may want to increase h l s _ m p 4 _ m a x _ b u f f e r _ s i z e
Nginx, Inc.
p.109 of 242
2.21
2.21.1
Summary
2.21.2
Example Configuration
location / img / {
proxy_pass
image_filter
image_filter
error_page
}
location = / empty {
empty_gif ;
}
2.21.3
Directives
image filter
syntax:
syntax:
syntax:
syntax:
syntax:
syntax:
default
context:
image_filter
image_filter
image_filter
image_filter
image_filter
image_filter
off
location
off;
test;
size;
rotate 90 | 180 | 270;
resize width height;
crop width height;
Nginx, Inc.
p.110 of 242
rotate 90|180|270
rotates images counter-clockwise by the specified number of degrees.
Parameter value can contain variables. This mode can be used either
alone or along with the resize and crop transformations.
resize width height
proportionally reduces an image to the specified sizes. To reduce by
only one dimension, another dimension can be specified as -. In case
of an error, the server will return code 415 Unsupported Media Type.
Parameter values can contain variables. When used along with the
rotate parameter, the rotation happens after reduction.
crop width height
proportionally reduces an image to the larger side size and crops
extraneous edges by another side. To reduce by only one dimension,
another dimension can be specified as -. In case of an error, the server
will return code 415 Unsupported Media Type. Parameter values can
contain variables. When used along with the rotate parameter, the
rotation happens before reduction.
image filter buffer
syntax: image_filter_buffer size;
default 1M
context: http, server, location
Sets the maximum size of the buffer used for reading images. When the
size is exceeded the server returns error 415 Unsupported Media Type.
image filter interlace
syntax: image_filter_interlace on | off;
default off
context: http, server, location
This directive appeared in version 1.3.15.
If enabled, final images will be interlaced. For JPEG, final images will be
in progressive JPEG format.
image filter jpeg quality
syntax: image_filter_jpeg_quality quality;
default 75
context: http, server, location
Sets the desired quality of the transformed JPEG images. Acceptable values
are in the range from 1 to 100. Lesser values usually imply both lower image
Nginx, Inc.
p.111 of 242
quality and less data to transfer. The maximum recommended value is 95.
Parameter value can contain variables.
image filter sharpen
syntax: image_filter_sharpen percent;
default 0
context: http, server, location
Nginx, Inc.
p.112 of 242
2.22
2.22.1
Summary
2.22.2
Example Configuration
location / {
index index . $geo . html index . html ;
}
2.22.3
Directives
index
syntax: index file . . . ;
default index.html
context: http, server, location
Defines files that will be used as an index. The file name can contain
variables. Files are checked in the specified order. The last element of the list
can be a file with an absolute path. Example:
index index . $geo . html index .0. html / index . html ;
It should be noted that using an index file causes an internal redirect, and
the request can be processed in a different location. For example, with the
following configuration:
location = / {
index index . html ;
}
location / {
...
}
Nginx, Inc.
p.113 of 242
2.23
2.23.1
Summary
2.23.2
Example Configuration
http {
li mit_ conn _zon e $ b i n a r y _ r e m o t e _ a d d r zone = addr :10 m ;
...
server {
...
location / download / {
limit_conn addr 1;
}
2.23.3
Directives
limit conn
syntax: limit_conn zone number;
default
context: http, server, location
Sets the shared memory zone and the maximum allowed number of
connections for a given key value. When this limit is exceeded, the server
will return the 503 Service Temporarily Unavailable error in reply to a
request. For example, the directives
li mit_ conn _zon e $ b i n a r y _ r e m o t e _ a d d r zone = addr :10 m ;
server {
location / download / {
limit_conn addr 1;
}
Nginx, Inc.
p.114 of 242
These directives are inherited from the previous level if and only if there
are no limit_conn directives on the current level.
limit conn log level
syntax: limit_conn_log_level info | notice | warn | error;
default error
context: http, server, location
This directive appeared in version 0.8.18.
Sets the desired logging level for cases when the server limits the number
of connections.
limit conn status
syntax: limit_conn_status code;
default 503
context: http, server, location
This directive appeared in version 1.3.15.
Sets parameters for a shared memory zone that will keep states for various
keys. In particular, the state includes the current number of connections. The
key is any non-empty value of the specified variable (empty values are not
accounted). Usage example:
li mit_ conn _zon e $ b i n a r y _ r e m o t e _ a d d r zone = addr :10 m ;
Here, a client IP address serves as a key. Note that instead of $remote addr,
the $binary remote addr variable is used here. The $remote addr variables
size can vary from 7 to 15 bytes. The stored state occupies either 32 or 64
bytes of memory on 32-bit platforms and always 64 bytes on 64-bit platforms.
The $binary remote addr variables size is always 4 bytes. The stored state
always occupies 32 bytes on 32-bit platforms and 64 bytes on 64-bit platforms.
One megabyte zone can keep about 32 thousand 32-byte states or about 16
Nginx, Inc.
p.115 of 242
thousand 64-byte states. If the zone storage is exhausted, the server will return
the 503 Service Temporarily Unavailable error to all further requests.
limit zone
syntax: limit_zone name $variable size;
default
context: http
This directive is made obsolete in version 1.1.8, an equivalent limit conn zone directive with a changed syntax should be used instead:
limit_conn_zone $variable zone=name:size;
Nginx, Inc.
p.116 of 242
2.24
2.24.1
Summary
2.24.2
Example Configuration
http {
limit_req_zone $ b i n a r y _ r e m o t e _ a d d r zone = one :10 m rate =1 r / s ;
...
server {
...
location / search / {
limit_req zone = one burst =5;
}
2.24.3
Directives
limit req
syntax: limit_req zone=name [burst=number] [nodelay];
default
context: http, server, location
Sets the shared memory zone and the maximum burst size of requests. If the
requests rate exceeds the rate configured for a zone, their processing is delayed
such that requests are processed at a defined rate. Excessive requests are
delayed until their number exceeds the maximum burst size in which case the
request is terminated with an error 503 Service Temporarily Unavailable.
By default, the maximum burst size is equal to zero. For example, the
directives
limit_req_zone $ b i n a r y _ r e m o t e _ a d d r zone = one :10 m rate =1 r / s ;
server {
location / search / {
limit_req zone = one burst =5;
}
allow not more than 1 request per second at an average, with bursts not
exceeding 5 requests.
If delaying of excessive requests while requests are being limited is not
desired, the parameter nodelay should be used:
Nginx, Inc.
p.117 of 242
Sets the desired logging level for cases when the server refuses to process
requests due to rate exceeding, or delays request processing. Logging level for
delays is one point less than for refusals; for example, if limit_req_log_level notice is specified, delays are logged with the info level.
limit req status
syntax: limit_req_status code;
default 503
context: http, server, location
This directive appeared in version 1.3.15.
Sets parameters for a shared memory zone that will keep states for various
keys. In particular, the state stores the current number of excessive requests.
The key is any non-empty value of the specified variable (empty values are not
accounted). Usage example:
limit_req_zone $ b i n a r y _ r e m o t e _ a d d r zone = one :10 m rate =1 r / s ;
Here, the states are kept in a 10 megabyte zone one, and an average
request processing rate for this zone cannot exceed 1 request per second.
A client IP address serves as a key. Note that instead of $remote addr, the
$binary remote addr variable is used here, that allows to decrease the state
size down to 64 bytes. One megabyte zone can keep about 16 thousand 64byte states. If the zone storage is exhausted, the server will return the 503
Service Temporarily Unavailable error to all further requests.
The rate is specified in requests per second (r/s). If a rate of less than one
request per second is desired, it is specified in request per minute (r/m). For
example, half-request per second is 30r/m.
Nginx, Inc.
p.118 of 242
2.25
2.25.1
Summary
2.25.2
Example Configuration
2.25.3
Directives
access log
syntax:
syntax:
syntax:
syntax:
default
context:
Sets the path, format, and configuration for a buffered log write. Several
logs can be specified on the same level. Logging to syslog can be configured
by specifying the syslog: prefix in the first parameter. The special value
off cancels all access_log directives on the current level. If the format is not
specified then the predefined combined format is used.
If either the buffer or gzip (1.3.10, 1.2.7) parameter is used, writes to log
will be buffered.
The buffer size must not exceed the size of an atomic write to a disk file.
For FreeBSD this size is unlimited.
When buffering is enabled, the data will be written to the file:
if the next log line does not fit into the buffer;
if the buffered data is older than specified by the flush parameter (1.3.10,
1.2.7);
when a worker process is re-opening log files or is shutting down.
Nginx, Inc.
p.119 of 242
If the gzip parameter is used, then the buffered data will be compressed
before writing to the file. The compression level can be set between 1 (fastest,
less compression) and 9 (slowest, best compression). By default, the buffer
size is equal to 64K bytes, and the compression level is set to 1. Since the data
is compressed in atomic blocks, the log file can be decompressed or read by
zcat at any time.
Example:
access_log / path / to / log . gz combined gzip flush =5 m ;
For gzip compression to work, nginx must be built with the zlib library.
The file path can contain variables (0.7.6+), but such logs have some
constraints:
the user whose credentials are used by worker processes should have
permissions to create files in a directory with such logs;
buffered writes do not work;
the file is opened and closed for each log write. However, since the
descriptors of frequently used files can be stored in a cache, writing to
the old file can continue during the time specified by the open log file cache directives valid parameter
during each log write the existence of the requests root directory is
checked, and if it does not exist the log is not created. It is thus a good
idea to specify both root and access_log on the same level:
server {
root
/ spool / vhost / data / $host ;
access_log / spool / vhost / logs / $host ;
...
Nginx, Inc.
p.120 of 242
severity=string
Sets severity of syslog messages, as defined in RFC 3164. Possible values
are the same as for the second parameter (level) of the error log directive.
Default is info.
tag=string
Sets the tag of syslog messages. Default is nginx.
Example syslog configuration:
access_log syslog : server =192.168.1.1;
access_log syslog : server = unix :/ var / log / nginx . sock ;
access_log syslog : server =[2001: db8 ::1]:12345 , facility = local7 , tag = nginx ,
severity = info combined ;
log format
syntax: log_format name string . . . ;
default combined "..."
context: http
Nginx, Inc.
p.121 of 242
$time local
local time in the Common Log Format
In the modern nginx versions variables $status (1.3.2, 1.2.2), $bytes sent (1.3.8, 1.2.5), $connection (1.3.8, 1.2.5), $connection requests (1.3.8,
1.2.5), $msec (1.3.9, 1.2.6), $request time (1.3.9, 1.2.6), $pipe (1.3.12, 1.2.7),
$request length (1.3.12, 1.2.7), $time iso8601 (1.3.12, 1.2.7), and $time local
(1.3.12, 1.2.7) are also available as common variables.
Header lines sent to a client have the prefix sent_http_, for example,
$sent http content range.
The configuration always includes the predefined combined format:
log_format combined $remote_addr - $remote_user [ $time_local ]
" $request " $status $ b od y _b y te s _s e nt
" $http_referer " " $ h tt p _u s er _ ag e nt " ;
Defines a cache that stores the file descriptors of frequently used logs whose
names contain variables. The directive has the following parameters:
max
sets the maximum number of descriptors in a cache; if the cache becomes
full the least recently used (LRU) descriptors are closed
inactive
sets the time after which the cached descriptor is closed if there were no
access during this time; by default, 10 seconds
min_uses
sets the minimum number of file uses during the time defined by the
inactive parameter to let the descriptor stay open in a cache; by default,
1
valid
sets the time after which it should be checked that the file still exists
with the same name; by default, 60 seconds
off
disables caching
Usage example:
o p e n _ l o g _ f i l e _ c a c h e max =1000 inactive =20 s valid =1 m min_uses =2;
Nginx, Inc.
p.122 of 242
2.26
2.26.1
Summary
2.26.2
Example Configuration
0;
example . com
*. example . com
example . org
*. example . org
. example . net
wap .*
1;
1;
2;
2;
3;
4;
}
map $ h tt p _u se r _a g en t $mobile {
default
0;
"~ Opera Mini " 1;
}
2.26.3
Directives
map
syntax: map string $variable { . . . }
default
context: http
p.123 of 242
can be combined:
. example . com
1;
Sets the bucket size for the map variables hash tables. Default value
depends on the processors cache line size. The details of setting up hash
tables are provided in a separate document.
Nginx, Inc.
p.124 of 242
Sets the maximum size of the map variables hash tables. The details of
setting up hash tables are provided in a separate document.
Nginx, Inc.
p.125 of 242
2.27
2.27.1
Summary
2.27.2
Example Configuration
server {
location / {
set
$memcached_key " $uri ? $args ";
memcached_pass host :11211;
error_page
404 502 504 = @fallback ;
}
location @fallback {
proxy_pass
http :// backend ;
}
}
2.27.3
Directives
memcached bind
syntax: memcached_bind address | off;
default
context: http, server, location
This directive appeared in version 0.8.22.
Sets the size of the buffer used for reading a response received from the
memcached server. A response is passed to a client synchronously, as soon as
it is received.
memcached connect timeout
syntax: memcached_connect_timeout time;
default 60s
context: http, server, location
Nginx, Inc.
p.126 of 242
Enables the test for the flag presence in the memcached server response
and sets the Content-Encoding response header field to gzip if the flag is
set.
memcached next upstream
syntax:
Nginx, Inc.
p.127 of 242
Nginx, Inc.
p.128 of 242
2.28
2.28.1
Summary
2.28.2
Nginx, Inc.
Example Configuration
p.129 of 242
location / video / {
mp4 ;
mp 4_bu ffer _siz e
mp4_max_buffer_size
mp4_limit_rate
mp4_limit_rate_after
}
2.28.3
1m;
5m;
on ;
30 s ;
Directives
mp4
syntax: mp4;
default
context: location
Sets the initial size of a memory buffer used for processing MP4 files.
mp4 max buffer size
syntax: mp4_max_buffer_size size;
default 10M
context: http, server, location
During metadata processing, a larger buffer may become necessary. Its size
cannot exceed the specified size, or else nginx will return the 500 Internal
Server Error server error, and log the following message:
"/ some / movie / file . mp4 " mp4 moov atom is too large :
12583268 , you may want to increase m p 4 _ m a x _ b u f f e r _ s i z e
Enables or disables rate limiting based on the average bitrate of the MP4
file served. To calculate the rate, the bitrate is multiplied by the specified
factor. The special value on corresponds to the factor of 1.1.
Nginx, Inc.
p.130 of 242
Limits the rate after sending the specified amount of media data.
This directive is available as part of our commercial subscription.
Nginx, Inc.
p.131 of 242
2.29
2.29.1
Summary
2.29.2
Known Bugs
Nginx, Inc.
p.132 of 242
or (Linux):
*** glibc detected *** realloc () : invalid pointer : ... ***
Out of memory !
Callback called exit .
should be replaced by
my $i = $r - > variable ( counter ) ;
$i ++;
Since most strings inside nginx are stored without a terminating null
character, they are similarly returned by the $r request object methods
(except for the $r->filename and $r->request_body_file methods). Thus,
such values cannot be used as filenames and the likes. The workaround is
similar to the previous case the value should either be assigned to a variable
(this results in data copying and adding of the necessary null character) or
used in an expression, for example:
open FILE , / path / . $r - > variable ( name ) ;
2.29.3
Example Configuration
http {
perl_modules perl / lib ;
perl_require hello . pm ;
perl_set $msie6
sub {
my $r = shift ;
my $ua = $r - > header_in (" User - Agent ") ;
return "" if $ua =~ / Opera /;
return "1" if $ua =~ / MSIE [6 -9]\.\ d +/;
return "";
}
;
Nginx, Inc.
p.133 of 242
server {
location / {
perl hello :: handler ;
}
}
2.29.4
Directives
perl
syntax: perl module::function|sub { . . . };
default
context: location, limit except
Nginx, Inc.
p.134 of 242
perl set
syntax: perl_set $variable module::function|sub { . . . };
default
context: http
2.29.5
2.29.6
$r->args
returns request arguments.
$r->filename
returns a filename corresponding to the request URI.
$r->has_request_body(handler)
returns 0 if there is no body in a request. If there is a body, the specified
handler is set for the request and 1 is returned. After reading the request
body, nginx will call the specified handler. Note that the handler function
should be passed by reference. Example:
package hello ;
use nginx ;
sub handler {
my $r = shift ;
if ( $r - > request_method ne " POST ") {
return DECLINED ;
}
if ( $r - > ha s _r e qu e st _ bo d y (&post ) ) {
return OK ;
}
return HT T P_ B AD_R E QU E ST ;
}
sub post {
my $r = shift ;
$r - > s e nd _ ht t p_ hea d er ;
$r - > print (" request_body : \"" , $r - > request_body , "\" < br / >") ;
$r - > print (" r e q u e s t _ b o d y _ f i l e : \"" , $r - > request_body_file , "\" < br
/ >\ n ") ;
return OK ;
}
Nginx, Inc.
p.135 of 242
1;
__END__
$r->allow_ranges
enables the use of byte ranges when sending responses.
$r->discard_request_body
instructs nginx to discard the request body.
$r->header_in(field)
returns the value of the specified client request header field.
$r->header_only
determines whether the whole response or only its header should be sent
to the client.
$r->header_out(field, value)
sets a value for the specified response header field.
$r->internal_redirect(uri)
does an internal redirect to the specified uri. An actual redirect happens
after the Perl handler execution is completed.
Redirections to named locations are currently not supported.
$r->log_error(errno, message)
writes the specified message into the error log. If errno is non-zero, an
error code and its description will be appended to the message.
$r->print(text, ...)
passes data to a client.
$r->request_body
returns the client request body if it has not been written to a temporary
file. To ensure that the client request body is in memory, its size should
be limited by client max body size, and a sufficient buffer size should be
set using client body buffer size.
$r->request_body_file
returns the name of the file with the client request body. After the
processing, the file should be removed. To always write a request body
to a file, client body in file only should be enabled.
$r->request_method
returns the client request HTTP method.
$r->remote_addr
returns the client IP address.
$r->flush
immediately sends data to the client.
$r->sendfile(name[, offset[, length]])
sends the specified file content to the client. Optional parameters specify
the initial offset and length of the data to be transmitted. The actual
data transmission happens after the Perl handler has completed.
$r->send_http_header([type])
Nginx, Inc.
p.136 of 242
sends the response header to the client. The optional type parameter sets
the value of the Content-Type response header field. If the value is an
empty string, the Content-Type header field will not be sent.
$r->status(code)
sets a response code.
$r->sleep(milliseconds, handler)
sets the specified handler and stops request processing for the specified
time. In the mean time, nginx continues to process other requests. After
the specified time has elapsed, nginx will call the installed handler. Note
that the handler function should be passed by reference. In order to pass
data between handlers, $r->variable() should be used. Example:
package hello ;
use nginx ;
sub handler {
my $r = shift ;
$r - > d i s c a r d _ r e q u e s t _ b o d y ;
$r - > variable (" var " , " OK ") ;
$r - > sleep (1000 , &next ) ;
return OK ;
}
sub next {
my $r = shift ;
$r - > s e nd _ ht t p_ hea d er ;
$r - > print ( $r - > variable (" var ") ) ;
return OK ;
}
1;
__END__
$r->unescape(text)
decodes a text encoded in the %XX form.
$r->uri
returns a request URI.
$r->variable(name[, value])
returns or sets the value of the specified variable. Variables are local to
each request.
Nginx, Inc.
p.137 of 242
2.30
2.30.1
Summary
2.30.2
Example Configuration
location / {
proxy_pass
http :// localhost :8000;
p ro x y_ s et _ he a de r Host
$host ;
p ro x y_ s et _ he a de r X - Real - IP $remote_addr ;
}
2.30.3
Directives
proxy bind
syntax: proxy_bind address | off;
default
context: http, server, location
This directive appeared in version 0.8.22.
Sets the size of the buffer used for reading the first part of a response
received from the proxied server. This part usually contains a small response
header. By default, the buffer size is equal to the size of one buffer set by the
proxy buffers directive. It can be made smaller however.
proxy buffering
syntax: proxy_buffering on | off;
default on
context: http, server, location
Nginx, Inc.
p.138 of 242
When buffering is enabled, nginx receives a response from the proxied server
as soon as possible, saving it into the buffers set by the proxy buffer size and
proxy buffers directives. If the whole response does not fit into memory, a part
of it can be saved to a temporary file on the disk. Writing to temporary files
is controlled by the proxy max temp file size and proxy temp file write size
directives.
When buffering is disabled, a response is passed to a client synchronously,
immediately as it is received. nginx will not try to read the whole response
from the proxied server. The maximum size of the data that nginx can receive
from the server at a time is set by the proxy buffer size directive.
Buffering can also be enabled or disabled by passing yes or no in the
X-Accel-Buffering response header field. This capability can be disabled using
the proxy ignore headers directive.
proxy buffers
syntax: proxy_buffers number size;
default 8 4k|8k
context: http, server, location
Sets the number and size of buffers used for reading a response from the
proxied server, for a single connection. By default, the buffer size is equal to
one memory page. This is either 4K or 8K, depending on a platform.
proxy busy buffers size
syntax: proxy_busy_buffers_size size;
default 8k|16k
context: http, server, location
When buffering of responses from the proxied server is enabled, limits the
total size of buffers that can be busy sending a response to the client while the
response is not yet fully read. In the mean time, the rest of the buffers can be
used for reading a response and, if needed, buffering part of a response to a
temporary file. By default, size is limited by the size of two buffers set by the
proxy buffer size and proxy buffers directives.
proxy cache
syntax: proxy_cache zone | off;
default off
context: http, server, location
Defines a shared memory zone used for caching. The same zone can be
used in several places. The off parameter disables caching inherited from the
previous configuration level.
Nginx, Inc.
p.139 of 242
Defines conditions under which the response will not be taken from a cache.
If at least one value of the string parameters is not empty and is not equal to
0 then the response will not be taken from the cache:
p r o x y _ c a c h e _ b y p a s s $ coo kie_ noca che $ a r g _ n o c a c h e $ a r g _ c o m m e n t ;
p r o x y _ c a c h e _ b y p a s s $http_pragma
$http_authorization ;
When enabled, only one request at a time will be allowed to populate a new
cache element identified according to the proxy cache key directive by passing
a request to a proxied server. Other requests of the same cache element will
either wait for a response to appear in the cache or the cache lock for this
element to be released, up to the time set by the proxy cache lock timeout
directive.
proxy cache lock timeout
syntax: proxy_cache_lock_timeout time;
default 5s
context: http, server, location
This directive appeared in version 1.1.12.
p.140 of 242
If the client request method is listed in this directive then the response will
be cached. GET and HEAD methods are always added to the list, though it is
recommended to specify them explicitly. See also the proxy no cache directive.
proxy cache min uses
syntax: proxy_cache_min_uses number;
default 1
context: http, server, location
Sets the number of requests after which the response will be cached.
proxy cache path
syntax:
Sets the path and other parameters of a cache. Cache data are stored in
files. Both the key and file name in a cache are a result of applying the MD5
function to the proxied URL.
The levels parameter defines hierarchy levels of a cache. For example, in
the following configuration
p ro x y_ c ac h e_ p at h / data / nginx / cache levels =1:2 keys_zone = one :10 m ;
A cached response is first written to a temporary file, and then the file is
renamed. Starting from version 0.8.9, temporary files and the cache can be put
on different file systems. However, be aware that in this case a file is copied
across two file systems instead of the cheap renaming operation. It is thus
recommended that for any given location both cache and a directory holding
temporary files, set by the proxy temp path directive, are put on the same file
system.
In addition, all active keys and information about data are stored in a
shared memory zone, whose name and size are configured by the keys_zone
parameter. Cached data that are not accessed during the time specified by the
Nginx, Inc.
p.141 of 242
inactive parameter get removed from the cache regardless of their freshness.
By default, inactive is set to 10 minutes.
The special cache manager process monitors the maximum cache size set
by the max_size parameter. When this size is exceeded, it removes the least
recently used data.
A minute after the start the special cache loader process is activated. It
loads information about previously cached data stored on file system into a
cache zone. The loading is done in iterations. During one iteration no more
than loader_files items are loaded (by default, 100). Besides, the duration of
one iteration is limited by the loader_threshold parameter (by default, 200
milliseconds). Between iterations, a pause configured by the loader_sleep
parameter (by default, 50 milliseconds) is made.
proxy cache purge
syntax: proxy_cache_purgestring . . . ;
default
context: http, server, location
This directive appeared in version 1.5.7.
Defines conditions under which the request will be considered a cache purge
request. If at least one value of the string parameters is not empty and
is not equal to 0 then the cache entry with a corresponding cache key is
removed. The result of successful operation is indicated by returning the 204
No Content response.
If the cache key of a purge request ends with an asterisk (*), all cache
entries matching the wildcard key will be removed from the cache.
Example configuration:
p ro x y_ c ac h e_ p at h / data / nginx / cache keys_zone = cache_zone :10 m ;
map $re ques t_m etho d $purge_method {
PURGE
1;
default 0;
}
server {
...
location / {
proxy_pass http :// backend ;
proxy_cache cache_zone ;
pro xy_ cach e_ke y $uri ;
p r o x y _ c a c h e _ p u r g e $purge_method ;
}
}
Nginx, Inc.
p.142 of 242
Sets caching time for different response codes. For example, the following
directives
p r o x y _ c a c h e _ v a l i d 200 302 10 m ;
p r o x y _ c a c h e _ v a l i d 404
1m;
set 10 minutes of caching for responses with codes 200 and 302 and 1 minute
for responses with code 404.
If only caching time is specified
proxy_cache_valid 5m;
Nginx, Inc.
p.143 of 242
Parameters of caching can also be set directly in the response header. This
has higher priority than setting of caching time using the directive. The XAccel-Expires header field sets caching time of a response in seconds. The zero
value disables caching for a response. If a value starts with the @ prefix, it
sets an absolute time in seconds since Epoch, up to which the response may
be cached. If header does not include the X-Accel-Expires field, parameters of
caching may be set in the header fields Expires or Cache-Control. If a header
includes the Set-Cookie field, such a response will not be cached. Processing of
one or more of these response header fields can be disabled using the proxy ignore headers directive.
proxy connect timeout
syntax: proxy_connect_timeout time;
default 60s
context: http, server, location
proxy_cookie_domain off;
proxy_cookie_domain domain replacement;
off
http, server, location
Sets a text that should be changed in the domain attribute of the SetCookie header fields of a proxied server response. Suppose a proxied server
returned the Set-Cookie header field with the attribute domain=localhost.
The directive
p r o x y _ c o o k i e _ d o m a i n localhost example . org ;
The directive can also be specified using regular expressions. In this case,
domain should start from the ~ symbol. A regular expression can contain
named and positional captures, and replacement can reference them:
p r o x y _ c o o k i e _ d o m a i n ~\.(? P < sl_domain >[ -0 -9 a - z ]+\.[ a - z ]+) $ $sl_domain ;
p.144 of 242
proxy_cookie_path off;
proxy_cookie_path path replacement;
off
http, server, location
Sets a text that should be changed in the path attribute of the Set-Cookie
header fields of a proxied server response. Suppose a proxied server returned
the Set-Cookie header field with the attribute path=/two/some/uri/. The
directive
p r o x y _ c o o k i e _ p a t h / two / /;
The directive can also be specified using regular expressions. In this case,
path should either start from the ~ symbol for a case-sensitive matching, or
from the ~* symbols for case-insensitive matching. A regular expression can
contain named and positional captures, and replacement can reference them:
p r o x y _ c o o k i e _ p a t h ~*^/ user /([^/]+) / u / $1 ;
Nginx, Inc.
p.145 of 242
Sets the bucket size for hash tables used by the proxy hide header and
proxy set header directives. The details of setting up hash tables are provided
in a separate document.
proxy headers hash max size
syntax: proxy_headers_hash_max_size size;
default 512
context: http, server, location
Sets the maximum size of hash tables used by the proxy hide header and
proxy set header directives. The details of setting up hash tables are provided
in a separate document.
proxy hide header
syntax: proxy_hide_header field;
default
context: http, server, location
By default, nginx does not pass the header fields Date, Server, X-Pad, and
X-Accel-. . . from the response of a proxied server to a client. The proxy_hide_header directive sets additional fields that will not be passed. If, on the
contrary, the passing of fields needs to be permitted, the proxy pass header
directive can be used.
proxy http version
syntax: proxy_http_version 1.0 | 1.1;
default 1.0
context: http, server, location
This directive appeared in version 1.1.4.
Sets the HTTP protocol version for proxying. By default, version 1.0 is
used. Version 1.1 is recommended for use with keepalive connections.
proxy ignore client abort
syntax: proxy_ignore_client_abort on | off;
default off
context: http, server, location
Nginx, Inc.
p.146 of 242
Disables processing of certain response header fields from the proxied server.
The following fields can be ignored: X-Accel-Redirect, X-Accel-Expires, XAccel-Limit-Rate (1.1.6), X-Accel-Buffering (1.1.6), X-Accel-Charset (1.1.6),
Expires, Cache-Control, and Set-Cookie (0.8.44).
If not disabled, processing of these header fields has the following effect:
X-Accel-Expires, Expires, Cache-Control, and Set-Cookie set the
parameters of response caching;
X-Accel-Redirect performs an internal redirect to the specified URI;
X-Accel-Limit-Rate sets the rate limit for transmission of a response to
a client;
X-Accel-Buffering enables or disables buffering of a response;
X-Accel-Charset sets the desired charset of a response.
proxy intercept errors
syntax: proxy_intercept_errors on | off;
default off
context: http, server, location
When buffering of responses from the proxied server is enabled, and the
whole response does not fit into the memory buffers set by the proxy buffer size and proxy buffers directives, a part of the response can be saved to a
temporary file. This directive sets the maximum size of a temporary file. The
size of data written to a temporary file at a time is set by the proxy temp file write size directive.
The zero value disables buffering of responses to temporary files.
Nginx, Inc.
p.147 of 242
proxy method
syntax: proxy_method method;
default
context: http, server, location
p.148 of 242
Defines conditions under which the response will not be saved to a cache.
If at least one value of the string parameters is not empty and is not equal to
0 then the response will not be saved:
proxy_no_cache $ cook ie_n oca che $ a r g _ n o c a c h e $ a r g _ c o m m e n t ;
proxy_no_cache $http_pragma
$http_authorization ;
Sets the protocol and address of a proxied server and an optional URI to
which a location should be mapped. As a protocol, http or https can be
specified. The address can be specified as a domain name or IP address, and
an optional port:
proxy_pass http :// localhost :8000/ uri /;
Nginx, Inc.
p.149 of 242
In this case, the URI specified in the directive is ignored and the full
changed request URI is passed to the server.
A server name, its port and the passed URI can also be specified using
variables:
proxy_pass http :// $host$uri ;
In this case, the server name is searched among the described server groups,
and, if not found, is determined using a resolver.
WebSocket proxying requires special configuration and is supported since
version 1.3.13.
Nginx, Inc.
p.150 of 242
Defines a timeout for reading a response from the proxied server. A timeout
is set only between two successive read operations, not for the transmission of
the whole response. If a proxied server does not transmit anything within this
time, a connection is closed.
proxy pass request body
syntax: proxy_pass_request_body on | off;
default on
context: http, server, location
Indicates whether the original request body is passed to the proxied server.
location /x - accel - redirect - here / {
proxy_method GET ;
p r o x y _ p a s s _ r e q u e s t _ b o d y off ;
p ro x y_ s et _ he a de r Content - Length "";
proxy_pass ...
}
See also the proxy set header and proxy pass request headers directives.
proxy pass request headers
syntax: proxy_pass_request_headers on | off;
default on
context: http, server, location
Indicates whether the header fields of the original request are passed to the
proxied server.
location /x - accel - redirect - here / {
proxy_method GET ;
p r o x y _ p a s s _ r e q u e s t _ h e a d e r s off ;
p r o x y _ p a s s _ r e q u e s t _ b o d y off ;
proxy_pass ...
}
Nginx, Inc.
p.151 of 242
See also the proxy set header and proxy pass request body directives.
proxy redirect
syntax:
syntax:
syntax:
default
context:
proxy_redirect default;
proxy_redirect off;
proxy_redirect redirect replacement;
default
http, server, location
Sets the text that should be changed in the Location and Refresh header
fields of a proxied server response. Suppose a proxied server returned the
header field Location: http://localhost:8000/two/some/uri/. The
directive
proxy_redirect http :// localhost :8000/ two / http :// frontend / one /;
will
rewrite
this
string
to
http://frontend/one/some/uri/.
A server name may be omitted in the replacement string:
Location:
then the primary servers name and port, if different from 80, will be
inserted.
The default replacement specified by the default parameter uses the
parameters of the location and proxy pass directives. Hence, the two
configurations below are equivalent:
location / one / {
proxy_pass
http :// upstream : port / two /;
proxy_redirect default ;
location / one / {
proxy_pass
http :// upstream : port / two /;
proxy_redirect http :// upstream : port / two / / one /;
p.152 of 242
expression can contain named and positional captures, and replacement can
reference them:
proxy_redirect ~^( http ://[^:]+) :\ d +(/.+) $ $1$2 ;
proxy_redirect ~*/ user /([^/]+) /(.+) $
http :// $1 . example . com / $2 ;
off ;
default ;
http :// localhost :8000/ /;
http :// www . example . com / /;
Using this directive, it is also possible to add host names to relative redirects
issued by a proxied server:
proxy_redirect / /;
If the directive is set to a non-zero value, nginx will try to minimize the
number of send operations on outgoing connections to a proxied server by
using either NOTE_LOWAT flag of the kqueue method, or the SO_SNDLOWAT socket
option, with the specified size.
This directive is ignored on Linux, Solaris, and Windows.
proxy send timeout
syntax: proxy_send_timeout time;
default 60s
context: http, server, location
Nginx, Inc.
p.153 of 242
Allows redefining the request body passed to the proxied server. A value
can contain text, variables, and their combination.
proxy set header
syntax:
default
default
context:
$http_host ;
However, if this field is not present in a client request header then nothing
will be passed. In such a case it is better to use the $host variable - its value
equals the server name in the Host request header field or the primary server
name if this field is not present:
p ro x y_ s et _ he a de r Host
$host ;
In addition, the server name can be passed together with the port of the
proxied server:
p ro x y_ s et _ he a de r Host
$host : $proxy_port ;
If the value of a header field is an empty string then this field will not be
passed to a proxied server:
p ro x y_ s et _ he a de r Accept - Encoding "";
Nginx, Inc.
p.154 of 242
Specifies the enabled ciphers for requests to a proxied HTTPS server. The
ciphers are specified in the format understood by the OpenSSL library.
The full list can be viewed using the openssl ciphers command.
proxy ssl session reuse
syntax: proxy_ssl_session_reuse on | off;
default on
context: http, server, location
Determines whether SSL sessions can be reused when working with the
proxied server. If the errors SSL3_GET_FINISHED:digest check failed
appear in the logs, try disabling session reuse.
proxy ssl protocols
syntax: proxy_ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2];
default SSLv3 TLSv1 TLSv1.1 TLSv1.2
context: http, server, location
This directive appeared in version 1.5.6.
Enables saving of files to a disk. The on parameter saves files with paths
corresponding to the directives alias or root. The off parameter disables saving
of files. In addition, the file name can be set explicitly using the string with
variables:
proxy_store / data / w w w$ or i gi n al _ ur i ;
Nginx, Inc.
p.155 of 242
root
error_page
/ data / www ;
404 = / fetch$uri ;
}
location / fetch / {
internal ;
proxy_pass
proxy_store
proxy_store_access
pr oxy_ temp _pat h
alias
/ data / www /;
or like this:
location / images / {
root
error_page
}
/ data / www ;
404 = @fetch ;
location @fetch {
internal ;
proxy_pass
proxy_store
proxy_store_access
pr oxy_ temp _pat h
root
/ data / www ;
Sets access permissions for newly created files and directories, e.g.:
p r o x y _ s t o r e _ a c c e s s user : rw group : rw all : r ;
If any group or all access permissions are specified then user permissions
may be omitted:
p r o x y _ s t o r e _ a c c e s s group : rw all : r ;
Limits the size of data written to a temporary file at a time, when buffering
of responses from the proxied server to temporary files is enabled. By default,
Nginx, Inc.
p.156 of 242
size is limited by two buffers set by the proxy buffer size and proxy buffers
directives. The maximum size of a temporary file is set by the proxy max temp file size directive.
proxy temp path
syntax: proxy_temp_path path [level1 [level2 [level3]]];
default proxy_temp
context: http, server, location
Defines a directory for storing temporary files with data received from
proxied servers. Up to three-level subdirectory hierarchy can be used
underneath the specified directory. For example, in the following configuration
pr oxy_ temp _pat h / spool / nginx / proxy_temp 1 2;
2.30.4
Embedded Variables
Nginx, Inc.
p.157 of 242
CHAPTER 2. HTTP SERVER MODULES 2.31. MODULE NGX HTTP RANDOM INDEX MODULE
2.31
2.31.1
Summary
2.31.2
Example Configuration
location / {
random_index on ;
}
2.31.3
Directives
random index
syntax: random_index on | off;
default off
context: location
Nginx, Inc.
p.158 of 242
2.32
2.32.1
Summary
2.32.2
Example Configuration
s et _ re a l_ i p_ f ro m
s et _ re a l_ i p_ f ro m
s et _ re a l_ i p_ f ro m
real_ip_header
real_ip_recursive
2.32.3
Directives
real ip header
syntax:
Defines a request header field used to send the address for a replacement.
The proxy_protocol parameter (1.5.12) changes the client address to
the one from the PROXY protocol header. The PROXY protocol must be
previously enabled by setting the proxy_protocol parameter in the listen
directive.
Nginx, Inc.
p.159 of 242
real ip recursive
syntax: real_ip_recursive on | off;
default off
context: http, server, location
This directive appeared in versions 1.3.0 and 1.2.1.
If recursive search is disabled, the original client address that matches one of
the trusted addresses is replaced by the last address sent in the request header
field defined by the real ip header directive. If recursive search is enabled, the
original client address that matches one of the trusted addresses is replaced by
the last non-trusted address sent in the request header field.
Nginx, Inc.
p.160 of 242
2.33
2.33.1
Summary
2.33.2
Example Configuration
2.33.3
Directives
Sets the bucket size for the valid referers hash tables. The details of setting
up hash tables are provided in a separate document.
referer hash max size
syntax: referer_hash_max_size size;
default 2048
context: server, location
This directive appeared in version 1.0.5.
Sets the maximum size of the valid referers hash tables. The details of
setting up hash tables are provided in a separate document.
valid referers
syntax: valid_referers none | blocked | server_names | string . . . ;
default
context: server, location
Nginx, Inc.
p.161 of 242
Specifies the Referer request header field values that will cause the
embedded $invalid referer variable to be set to an empty string. Otherwise,
the variable will be set to 1. Search for a match is case-insensitive.
Parameters can be as follows:
none
the Referer field is missing in the request header;
blocked
the Referer field is present in the request header, but its value has been
deleted by a firewall or proxy server; such values are strings that do not
start with http:// or https://;
server_names
the Referer request header field contains one of the server names;
arbitrary string
defines a server name and an optional URI prefix. A server name can
have an * at the beginning or end. During the checking, the servers
port in the Referer field is ignored;
regular expression
the first symbol should be a~. It should be noted that an expression will
be matched against the text starting after the http:// or https://.
Example:
valid_referers none blocked server_names
*. example . com example .* www . example . org / galleries /
~\. google \.;
Nginx, Inc.
p.162 of 242
2.34
2.34.1
Summary
2.34.2
Directives
break
syntax: break;
default
context: server, location, if
if
syntax: if (condition) { . . . }
default
context: server, location
p.163 of 242
A value of the $invalid referer embedded variable is set by the valid referers directive.
return
syntax:
syntax:
syntax:
default
context:
Nginx, Inc.
server, location, if
p.164 of 242
Stops processing and returns the specified code to a client. The nonstandard code 444 closes a connection without sending a response header.
Starting from version 0.8.42, it is possible to specify either a redirect URL
(for codes 301, 302, 303, and 307), or the response body text (for other codes).
A response body text and redirect URL can contain variables. As a special
case, a redirect URL can be specified as a URI local to this server, in which
case the full redirect URL is formed according to the request scheme ($scheme)
and the server name in redirect and port in redirect directives.
In addition, a URL for temporary redirect with the code 302 can be specified
as the sole parameter. Such a parameter should start with the http://,
https://, or $scheme string. A URL can contain variables.
Only the following codes could be returned before version 0.7.51: 204,
400, 402 406, 408, 410, 411, 413, 416, and 500 504.
The code 307 was not treated as a redirect until versions 1.1.16 and 1.0.13.
See also the error page directive.
rewrite
syntax: rewrite regex replacement [flag];
default
context: server, location, if
p.165 of 242
server {
...
rewrite ^(/ download /.*) / media /(.*) \..* $ $1 / mp3 / $2 . mp3 last ;
rewrite ^(/ download /.*) / audio /(.*) \..* $ $1 / mp3 / $2 . ra last ;
return 403;
...
}
But if these directives are put inside the /download/ location, the last
flag should be replaced by break, or otherwise nginx will make 10 cycles and
return the 500 error:
location / download / {
rewrite ^(/ download /.*) / media /(.*) \..* $ $1 / mp3 / $2 . mp3 break ;
rewrite ^(/ download /.*) / audio /(.*) \..* $ $1 / mp3 / $2 . ra break ;
return 403;
}
Sets a value for the specified variable. A value can contain text, variables,
and their combination.
uninitialized variable warn
syntax: uninitialized_variable_warn on | off;
default on
context: http, server, location, if
p.166 of 242
2.34.3
Internal Implementation
Note that there are no instructions for the limit rate directive above as it is
unrelated to the ngx_http_rewrite_module module. A separate configuration
is created for the if block. If the condition holds true, a request is assigned
this configuration where limit_rate equals to 10k.
The directive
rewrite ^/( download /.*) / media /(.*) \..* $ / $1 / mp3 / $2 . mp3 break ;
can be made smaller by one instruction if the first slash in the regular
expression is put inside the parentheses:
rewrite ^(/ download /.*) / media /(.*) \..* $ $1 / mp3 / $2 . mp3 break ;
Nginx, Inc.
p.167 of 242
2.35
2.35.1
Summary
2.35.2
Directives
secure link
syntax: secure_link expression;
default
context: http, server, location
Defines a string with variables from which the checksum value and lifetime
of a link will be extracted.
Variables used in an expression are usually associated with a request; see
example below.
The checksum value extracted from the string is compared with the MD5
hash value of the expression defined by the secure link md5 directive. If the
checksums are different, the $secure link variable is set to an empty string.
If the checksums are the same, the link lifetime is checked. If the link has a
limited lifetime and the time has expired, the $secure link variable is set to
0. Otherwise, it is set to 1. The MD5 hash value passed in a request is
encoded in base64url.
If a link has a limited lifetime, the expiration time is set in seconds
since Epoch (Thu, 01 Jan 1970 00:00:00 GMT). The value is specified in the
expression after the MD5 hash, and is separated by a comma. The expiration
time passed in a request is available through the $secure link expires variable
for a use in the secure link md5 directive. If the expiration time is not specified,
a link has the unlimited lifetime.
Nginx, Inc.
p.168 of 242
Defines an expression for which the MD5 hash value will be computed and
compared with the value passed in a request.
The expression should contain the secured part of a link (resource) and a
secret ingredient. If the link has a limited lifetime, the expression should also
contain $secure link expires.
To prevent unauthorized access, the expression may contain some
information about the client, such as its address and browser version.
Example:
location / s / {
secure_link $arg_md5 , $arg_expires ;
se cure _lin k_md 5 " $ s e c u r e _ l i n k _ e x p i r e s $ u r i $ r e m o t e _ a d d r secret ";
if ( $secure_link = "") {
return 403;
}
if ( $secure_link = "0") {
return 410;
}
...
}
Nginx, Inc.
p.169 of 242
If the requested link passes the authenticity check, the $secure link variable
is set to the link extracted from the request URI. Otherwise, the $secure link
variable is set to an empty string.
Example:
location / p / {
s e c u r e _ l i n k _ s e c r e t secret ;
if ( $secure_link = "") {
return 403;
}
rewrite ^ / secure / $secure_link ;
}
location / secure / {
internal ;
}
2.35.3
Embedded Variables
$secure link
The status of a link check. The specific value depends on the selected
operation mode.
$secure link expires
The lifetime of a link passed in a request; intended to be used only in
the secure link md5 directive.
Nginx, Inc.
p.170 of 242
2.36
2.36.1
Summary
2.36.2
Example Configuration
2.36.3
Directives
Specifies the output format of a log. The value of the $body bytes sent
variable is aggregated across all requests in a session. The values of all other
variables available for logging correspond to the first request in a session.
session log zone
syntax:
Sets the path to a log file and configures the shared memory zone that is
used to store currently active sessions.
A session is considered active for as long as the time elapsed since the last
request in the session does not exceed the specified timeout (by default, 30
seconds). Once a session is no longer active, it is written to the log.
The id parameter identifies the session to which a request is mapped. The
id parameter is set to the hexadecimal representation of an MD5 hash (for
Nginx, Inc.
p.171 of 242
Enables the use of the specified session log. The special value off cancels
all session_log directives inherited from the previous configuration level.
2.36.4
Embedded Variables
Nginx, Inc.
id
session ID;
binary id
session ID in binary form (16 bytes).
p.172 of 242
2.37
2.37.1
Summary
2.37.2
Known Bugs
2.37.3
Example Configuration
server {
listen 443 ssl spdy ;
ss l_ce rtif icat e server . crt ;
s s l _ c e r t i f i c a t e _ k e y server . key ;
...
}
2.37.4
Directives
Sets the maximum size of chunks into which the response body is sliced. A
too low value results in higher overhead. A too high value impairs prioritization
due to HOL blocking.
Nginx, Inc.
p.173 of 242
2.37.5
Embedded Variables
Nginx, Inc.
p.174 of 242
2.38
2.38.1
Summary
2.38.2
Example Configuration
http {
split_clients " $ { remote_addr } AAA "
0.5%
2.0%
*
}
$variant {
. one ;
. two ;
"";
server {
location / {
index index$ { variant }. html ;
2.38.3
Directives
split clients
syntax: split_clients string $variable { . . . }
default
context: http
$variant {
. one ;
. two ;
"";
Nginx, Inc.
p.175 of 242
2.39
2.39.1
Summary
2.39.2
Example Configuration
location / {
ssi on ;
...
}
2.39.3
Directives
ssi
syntax: ssi on | off;
default off
context: http, server, location, if in location
Allows preserving the Last-Modified header field from the original response
during SSI processing to facilitate response caching.
By default, the header field is removed as contents of the response are
modified during processing and may contain dynamically generated elements
or parts that are changed independently of the original response.
ssi min file chunk
syntax: ssi_min_file_chunk size;
default 1k
context: http, server, location
Sets the minimum size for parts of a response stored on disk, starting from
which it makes sense to send them using sendfile.
Nginx, Inc.
p.176 of 242
2.39.4
SSI Commands
config
Sets some parameters used during SSI processing, namely:
Nginx, Inc.
p.177 of 242
errmsg
a string that is output if an error occurs during SSI processing. By
default, the following string is output:
[ an error occurred while processing the directive ]
timefmt
a format string passed to the strftime function used to output date
and time. By default, the following format is used:
"% A , %d -% b -% Y % H :% M :% S % Z "
var
the variable name.
encoding
the encoding method. Possible values include none, url, and
entity. By default, entity is used.
default
a non-standard parameter that sets a string to be output if a variable
is undefined. By default, none is output. The command
<! - -# echo var =" name " default ="no " -->
if
Performs a conditional inclusion.
supported:
<! - -#
...
<! - -#
...
<! - -#
...
<! - -#
Only one level of nesting is currently supported. The command has the
following parameter:
expr
expression. An expression can be:
Nginx, Inc.
p.178 of 242
include
Includes the result of another request into a response. The command has
the following parameters:
file
specifies an included file, for example:
<! - -# include file =" footer . html " -->
virtual
specifies an included request, for example:
<! - -# include virtual ="/ remote / body . php ? argument = value " -->
p.179 of 242
wait
a non-standard parameter that instructs to wait for a request to
fully complete before continuing with SSI processing, for example:
<! - -# include virtual ="/ remote / body . php ? argument = value " wait ="
yes " -->
set
a non-standard parameter that instructs to write a successful result
of request processing to the specified variable, for example:
<! - -# include virtual ="/ remote / body . php ? argument = value " set ="
one " -->
2.39.5
Embedded Variables
Nginx, Inc.
p.180 of 242
2.40
2.40.1
Summary
2.40.2
Example Configuration
443 ssl ;
ssl_protocols
SSLv3 TLSv1 TLSv1 .1 TLSv1 .2;
ssl_ciphers
AES128 - SHA : AES256 - SHA : RC4 - SHA : DES - CBC3 - SHA : RC4
- MD5 ;
ssl _ce rtif icat e
/ usr / local / nginx / conf / cert . pem ;
s s l _ c e r t i f i c a t e _ k e y / usr / local / nginx / conf / cert . key ;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
...
}
2.40.3
Directives
ssl
syntax: ssl on | off;
default off
context: http, server
p.181 of 242
ssl certificate
syntax: ssl_certificate file;
default
context: http, server
Specifies a file with the certificate in the PEM format for the given virtual
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.
It should be kept in mind that due to the HTTPS protocol limitations
virtual servers should listen on different IP addresses:
server {
listen
1 9 2. 1 68 . 1. 1 :4 4 3;
server_name
one . example . com ;
ss l_ce rtif icat e / usr / local / nginx / conf / one . example . com . cert ;
...
}
server {
listen
1 9 2. 1 68 . 1. 2 :4 4 3;
server_name
two . example . com ;
ss l_ce rtif icat e / usr / local / nginx / conf / two . example . com . cert ;
...
}
otherwise the first servers certificate will be issued for the second site.
ssl certificate key
syntax: ssl_certificate_key file;
default
context: http, server
Nginx, Inc.
p.182 of 242
Specifies a file with the secret key in the PEM format for the given virtual
server.
ssl ciphers
syntax: ssl_ciphers ciphers;
default HIGH:!aNULL:!MD5
context: http, 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 openssl ciphers command.
The previous versions of nginx used different ciphers by default.
Specifies a file with revoked certificates (CRL) in the PEM format used to
verify client certificates.
ssl dhparam
syntax: ssl_dhparam file;
default
context: http, server
This directive appeared in version 0.7.2.
Nginx, Inc.
p.183 of 242
Specifies that server ciphers should be preferred over client ciphers when
using the SSLv3 and TLS protocols.
ssl protocols
syntax: ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2];
default SSLv3 TLSv1 TLSv1.1 TLSv1.2
context: http, server
Sets the types and sizes of caches that store session parameters. A cache
can be of any of the following types:
off
the use of a session cache is strictly prohibited: nginx explicitly tells a
client that sessions may not be reused.
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.
builtin
Nginx, Inc.
p.184 of 242
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.
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 virtual servers.
Both cache types can be used simultaneously, for example:
s s l _ s e s s i o n _ c a c h e builtin :1000 shared : SSL :10 m ;
but using only shared cache without the built-in cache should be more
efficient.
ssl session ticket key
syntax: ssl_session_ticket_key file;
default
context: http, server
This directive appeared in version 1.5.7.
Sets a 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 to configure key rotation, for example:
s s l _ s e s s i o n _ t i c k e t _ k e y current . key ;
s s l _ s e s s i o n _ t i c k e t _ k e y previous . key ;
The file must contain 48 bytes of random data and can be created using
the following command:
openssl rand 48 > ticket . key
Nginx, Inc.
p.185 of 242
Specifies a time during which a client may reuse the session parameters
stored in a cache.
ssl stapling
syntax: ssl_stapling on | off;
default off
context: http, server
This directive appeared in version 1.3.7.
For the OCSP stapling to work, the certificate of the server certificate
issuer should be known. If the ssl certificate file does not contain intermediate
certificates, the certificate of the server certificate issuer should be present in
the ssl trusted certificate file.
For a resolution of the OCSP responder hostname, the resolver directive
should also be specified.
ssl stapling file
syntax: ssl_stapling_file file;
default
context: http, server
This directive appeared in version 1.3.7.
When set, the stapled OCSP response will be taken from the specified file
instead of querying the OCSP responder specified in the server certificate.
The file should be in the DER format as produced by the openssl ocsp
command.
ssl stapling responder
syntax: ssl_stapling_responder url;
default
context: http, server
This directive appeared in version 1.3.7.
Nginx, Inc.
p.186 of 242
Nginx, Inc.
p.187 of 242
2.40.4
Error Processing
2.40.5
Embedded Variables
Nginx, Inc.
p.188 of 242
Nginx, Inc.
p.189 of 242
2.41
2.41.1
Summary
2.41.2
Example Configuration
server {
location = / status {
status ;
}
status_zone example_server ;
}
2.41.3
Directives
status
syntax: status;
default
context: location
status_format json;
status_format jsonp [callback];
json
http, server, location
Nginx, Inc.
p.190 of 242
2.41.4
Data
p.191 of 242
received
The total number of bytes received from clients.
sent
The total number of bytes sent to clients.
upstreams
For each server in the dynamically configurable group, the following data
are provided:
server
An address of the server.
backup
A boolean value indicating whether the cache loader process is
still loading data from disk into the cache.
weight
Weight of the server.
state
Current state, which may be one of up, down, unavail, or
unhealthy.
active
The current number of active connections.
keepalive
The current number of idle keepalive connections.
requests
The total number of client requests forwarded to this server.
responses
total
The total number of responses obtained from this server.
1xx, 2xx, 3xx, 4xx, 5xx
The number of responses with status codes 1xx, 2xx, 3xx, 4xx,
and 5xx.
sent
The total number of bytes sent to this server.
received
The total number of bytes received from this server.
fails
The total number of unsuccessful attempts to communicate with
the server.
unavail
How many times the server became unavailable for client requests
(state unavail) due to the number of unsuccessful attempts
reaching the max_fails threshold.
health_checks
checks
The total number of health check requests made.
fails
Nginx, Inc.
p.192 of 242
Nginx, Inc.
p.193 of 242
2.42
2.42.1
Summary
2.42.2
Example Configuration
location / {
sub_filter
</ head >
</ head > < script language =" javascript " src =" $script " > </ script > ;
su b_fi lter _onc e on ;
}
2.42.3
Directives
sub filter
syntax: sub_filter string replacement;
default
context: http, server, location
Allows preserving the Last-Modified header field from the original response
during replacement to facilitate response caching.
By default, the header field is removed as contents of the response are
modified during processing.
sub filter once
syntax: sub_filter_once on | off;
default on
context: http, server, location
Nginx, Inc.
p.194 of 242
Nginx, Inc.
p.195 of 242
2.43
2.43.1
Summary
2.43.2
Example Configuration
upstream backend {
server backend1 . example . com
weight =5;
server backend2 . example . com :8080;
server unix :/ tmp / backend3 ;
server backup1 . example . com :8080
server backup2 . example . com :8080
backup ;
backup ;
}
server {
location / {
proxy_pass http ://backend ;
}
}
Dynamically configurable
commercial subscription:
group,
available
as
part
of
our
upstream appservers {
zone appservers 64 k ;
server appserv1 . example . com
weight =5;
server appserv2 . example . com :8080 fail_timeout =5 s slow_start =30 s ;
server 192.0.2.1
max_fails =3;
server reserve1 . example . com :8080 backup ;
server reserve2 . example . com :8080 backup ;
}
server {
location / {
proxy_pass http ://appservers ;
health_check ;
}
location / upstream_conf {
upstream_conf ;
allow 127.0.0.1;
deny all ;
}
}
2.43.3
Directives
upstream
syntax: upstream name { . . . }
default
context: http
Nginx, Inc.
p.196 of 242
backup ;
Defines the address and other parameters of a server. The address can
be specified as a domain name or IP address, with an optional port, or as
a UNIX-domain socket path specified after the unix: prefix. If a port is
not specified, the port 80 is used. A domain name that resolves to several IP
addresses defines multiple servers at once.
The following parameters can be defined:
weight=number
sets the weight of the server, by default, 1.
max_fails=number
sets the number of unsuccessful attempts to communicate with the
server that should happen in the duration set by the fail_timeout
parameter to consider the server unavailable for a duration also set by
the fail_timeout parameter. By default, the number of unsuccessful
attempts is set to 1. The zero value disables the accounting of attempts.
What is considered an unsuccessful attempt is defined by the proxy next upstream, fastcgi next upstream, and memcached next upstream
directives.
fail_timeout=time
sets
the time during which the specified number of unsuccessful attempts
to communicate with the server should happen to consider the server
unavailable;
Nginx, Inc.
p.197 of 242
route=string
sets the server route name.
slow_start=time
sets the time during which the server will recover its weight from zero
to a nominal value, when unhealthy server becomes healthy, or when
the server becomes available after a period of time it was considered
unavailable. Default value is zero, i.e. slow start is disabled.
If there is only a single server in a group, max_fails, fail_timeout
and slow_start parameters are ignored, and such a server will never be
considered unavailable.
zone
syntax: zone name size;
default
context: upstream
Nginx, Inc.
p.198 of 242
Defines the name and size of the shared memory zone that keeps the groups
configuration and run-time state that are shared between worker processes.
Such groups allow changing the group membership or modifying the settings
of a particular server without the need of restarting nginx. The configuration
is accessible via a special location handled by upstream conf.
This directive is available as part of our commercial subscription.
ip hash
syntax: ip_hash;
default
context: upstream
Specifies that a group should use a load balancing method where requests
are distributed between servers based on client IP addresses. The first three
octets of the client IPv4 address, or the entire IPv6 address, are used as a
hashing key. The method ensures that requests from the same client will
always be passed to the same server except when this server is unavailable. In
the latter case client requests will be passed to another server. Most probably,
it will always be the same server as well.
IPv6 addresses are supported starting from versions 1.3.2 and 1.2.2.
If one of the servers needs to be temporarily removed, it should be marked
with the down parameter in order to preserve the current hashing of client IP
addresses.
Example:
upstream backend {
ip_hash ;
server
server
server
server
Until versions 1.3.1 and 1.2.2, it was not possible to specify a weight for
servers using the ip_hash load balancing method.
keepalive
syntax: keepalive connections;
default
context: upstream
This directive appeared in version 1.1.4.
Nginx, Inc.
p.199 of 242
For HTTP, the proxy http version directive should be set to 1.1 and the
Connection header field should be cleared:
upstream http_backend {
server 12 7.0 .0.1 :808 0;
keepalive 16;
}
server {
...
location / http / {
proxy_pass http :// http_backend ;
p r o x y _ h t t p _ v e r s i o n 1.1;
p ro x y_ s et _ he ad e r Connection "";
...
}
}
p.200 of 242
When using load balancer methods other than the default round-robin
method, it is necessary to activate them before the keepalive directive.
SCGI and uwsgi protocols do not have a notion of keepalive connections.
least conn
syntax: least_conn;
default
context: upstream
This directive appeared in versions 1.3.1 and 1.2.2.
Specifies that a group should use a load balancing method where a request
is passed to the server with the least number of active connections, taking into
account weights of servers. If there are several such servers, they are tried
using a weighted round-robin balancing method.
health check
syntax:
health_check [interval=time]
[fails=number] [passes=number] [uri=uri] [match=name];
default
context: location
Nginx, Inc.
p.201 of 242
will send/requests to each server in the backend group every five seconds.
If any communication error or timeout occurs, or a proxied server responds
with the status code other than 2xx or 3xx, the health check will fail, and
the server will be considered unhealthy. Client requests are not passed to
unhealthy servers.
Health checks can be configured to test the status code of a response,
presence of certain header fields and their values, and the body contents. Tests
are configured separately using the match directive and referenced in the match
parameter. For example:
http {
server {
...
location / {
proxy_pass http :// backend ;
health_check match = welcome ;
}
}
match welcome {
status 200;
header Content - Type = text / html ;
body ~ " Welcome to nginx !";
}
}
This configuration tells that for a health check to pass, the response
to a health check request should succeed, have status 200, content type
text/html, and contain Welcome to nginx! in the body.
The server group must reside in the shared memory.
If several health checks are defined for the same group of servers, a single
failure of any check will make the corresponding server be considered unhealthy.
This directive is available as part of our commercial subscription.
Nginx, Inc.
p.202 of 242
match
syntax: match name { . . . }
default
context: http
Defines the named test set used to verify responses to health check requests.
The following items can be tested in a response:
status 200;
status is 200
status ! 500;
status is not 500
status 200 204;
status is 200 or 204
status ! 301 302;
status is neither 301 nor 302
status 200-399;
status is in the range from 200 to 399
status ! 400-599;
status is not in the range from 400 to 599
status 301-303 307;
status is either 301, 302, 303, or 307
header Content-Type = text/html;
header contains Content-Type with value text/html
header Content-Type != text/html;
header contains Content-Type with value other than text/html
header Connection ~ close;
header contains Connection with value matching regular expression
close
header Connection !~ close;
header contains Connection with value not matching regular expression
close
header Host;
header contains Host
header ! X-Accel-Redirect;
header lacks X-Accel-Redirect
body ~ "Welcome to nginx!";
body matches regular expression Welcome to nginx!
body !~ "Welcome to nginx!";
body does not match regular expression Welcome to nginx!
If several tests are specified, the response matches only if it matches all
tests.
Nginx, Inc.
p.203 of 242
# status is not one of 301 , 302 , 303 , or 307 , and header does not have "
Refresh :"
match not_redirect {
status ! 301 -303 307;
header ! Refresh ;
}
queue
syntax: queue number [timeout=time];
default
context: upstream
This directive appeared in version 1.5.12.
Nginx, Inc.
p.204 of 242
sticky
syntax:
syntax:
default
context:
upstream
Enables session affinity, which causes requests from the same client to be
passed to the same server in a group of servers. Two methods are available,
cookie and route.
When the cookie method is used, information about the designated server
is passed in an HTTP cookie:
upstream backend {
server backend1 . example . com ;
server backend2 . example . com ;
sticky cookie srv_id expires =1 h domain =. example . com path =/;
}
A request that comes from a client not yet bound to a particular server
is passed to the server selected by the configured balancing method. Further
requests from the same client are passed to the same server. If the designated
server cannot process a request, the new server is selected as if the client has
not been bound yet.
The first parameter sets the name of the cookie to be set or inspected.
Additional parameters may be as follows:
expires
Sets the time for which a browser should keep the cookie. The special
value max will cause the cookie to expire on 31 Dec 2037 23:55:55
GMT. This is the maximum time understood by old browsers. If the
parameter is not specified, it will cause the cookie to expire at the end
of a browser session.
domain
Defines the domain for which the cookie is set.
path
Defines the path for which the cookie is set.
If any parameters are omitted, the corresponding cookie fields are not set.
When the route method is used, proxied server assigns client a route on
receipt of the first request. All subsequent requests from this client will carry
routing information in a cookie or URI. This information is compared with the
route parameter of the server directive to identify the server to which the
request should be proxied. If the designated server cannot process a request,
the new server is selected by the configured balancing method as if there is no
routing information in the request.
The parameters of the route method specify variables that may contain
routing information. The first non-empty variable is used to find the matching
server.
Nginx, Inc.
p.205 of 242
Example:
map $ c o o k i e _ j s e s s i o n i d $route_cookie {
~.+\.(? P < route >\ w +) $ $route ;
}
map $request_uri $route_uri {
~ jsessionid =.+\.(? P < route >\ w +) $ $route ;
}
upstream backend {
server backend1 . example . com route = a ;
server backend2 . example . com route = b ;
sticky route $route_cookie $route_uri ;
}
upstream conf
syntax: upstream_conf;
default
context: location
p.206 of 242
Nginx, Inc.
p.207 of 242
To add a new primary or backup server to the group, specify its address
in the server= parameter. Without other parameters specified, a server
will be added with other parameters set to their default values (see the server
directive).
For example, to add a new primary server to the group, send:
http ://127.0.0.1/ upstream_conf ? add =& upstream = appservers & server
=1 27.0 .0.1 :808 0
To add a new primary server to the group, set its parameters to non-default
values and mark it as down, send:
http ://127.0.0.1/ upstream_conf ? add =& upstream = appservers & server
= 12 7 .0 . 0. 1 :8 0 80 & weight =2& max_fails =3& fail_timeout =3 s & down =
p.208 of 242
http ://127.0.0.1/ upstream_conf ? upstream = appservers & backup =& id =42& server
=1 92.0 .2.3 :812 3
2.43.4
Embedded Variables
p.209 of 242
rules of converting header field names to variable names are the same
as for the variables that start with the $http prefix. Only the last
servers response header fields are saved.
Nginx, Inc.
p.210 of 242
2.44
2.44.1
Summary
2.44.2
Example Configuration
userid
userid_name
userid_domain
userid_path
userid_expires
userid_p3p
2.44.3
on ;
uid ;
example . com ;
/;
365 d ;
policyref ="/ w3c / p3p . xml " , CP =" CUR ADM OUR NOR STA NID " ;
Directives
userid
syntax: userid on | v1 | log | off;
default off
context: http, server, location
userid domain
syntax: userid_domain name | none;
default none
context: http, server, location
Defines a domain for which the cookie is set. The none parameter disables
setting of a domain for the cookie.
Nginx, Inc.
p.211 of 242
userid expires
syntax: userid_expires time | max | off;
default off
context: http, server, location
Sets a time during which a browser should keep the cookie. The parameter
max will cause the cookie to expire on 31 Dec 2037 23:55:55 GMT. This is
the maximum time understood by old browsers. The parameter off will cause
the cookie to expire at the end of a browser session.
userid mark
syntax: userid_mark letter | digit | = | off;
default off
context: http, server, location
If the parameter is not off, enables the cookie marking mechanism and sets
the character used as a mark. This mechanism is used to add or change userid p3p and/or a cookie expiration time while preserving the client identifier. A
mark can be any letter of the English alphabet (case-sensitive), digit, or the
= character.
If the mark is set, it is compared with the first padding symbol in the
base64 representation of the client identifier passed in a cookie. If they do not
match, the cookie is resent with the specified mark, expiration time, and P3P
header.
userid name
syntax: userid_name name;
default uid
context: http, server, location
Sets a value for the P3P header field that will be sent along with the cookie.
If the directive is set to the special value none, the P3P header will not be
sent in a response.
userid path
syntax: userid_path path;
default /
context: http, server, location
Nginx, Inc.
p.212 of 242
2.44.4
Embedded variables
Nginx, Inc.
p.213 of 242
2.45
2.45.1
Summary
2.45.2
Example Configuration
location / {
xml_entities
/ site / dtd / entities . dtd ;
xs lt_s tyle shee t / site / xslt / one . xslt param = value ;
xs lt_s tyle shee t / site / xslt / two . xslt ;
}
2.45.3
Directives
xml entities
syntax: xml_entities path;
default
context: http, server, location
Specifies the DTD file that declares character entities. This file is compiled
at the configuration stage. For technical reasons, the module is unable to
use the external subset declared in the processed XML, so it is ignored and a
specially defined file is used instead. This file should not describe the XML
structure. It is enough to declare just the required character entities, for
example:
<! ENTITY nbsp "&# xa0 ;" >
Allows preserving the Last-Modified header field from the original response
during XSLT transformations to facilitate response caching.
By default, the header field is removed as contents of the response are
modified during transformations and may contain dynamically generated
elements or parts that are changed independently of the original response.
Nginx, Inc.
p.214 of 242
xslt param
syntax: xslt_param parameter value;
default
context: http, server, location
This directive appeared in version 1.1.18.
The parameters description can contain variables, for example, the whole
line of parameters can be taken from a single variable:
location / {
xs lt_s tyle shee t / site / xslt / one . xslt
$ ar g _x s lt _ pa ra m s
param1 = $value1 : param2 = value2
param3 = value3 ;
}
Nginx, Inc.
p.215 of 242
Nginx, Inc.
p.216 of 242
Chapter 3
Mail server modules
3.1
3.1.1
3.1.2
Example configuration
w or k er _ pr o ce s se s 1;
error_log / var / log / nginx / error . log info ;
mail {
server_name
auth_http
217
3.1.3
Directives
listen
syntax: listen address:port [bind];
default
context: server
Sets the address and port for the socket on which the server will accept
requests. It is possible to specify just the port. The address can also be a
hostname, for example:
listen
listen
listen
listen
127.0.0.1:110;
*:110;
110;
# same as *:110
localhost :110;
The optional bind parameter instructs to make a separate bind call for a
given address:port pair. The fact is that if there are several listen directives
with the same port but different addresses, and one of the listen directives
listens on all addresses for the given port (*:port), nginx will bind only to
*:port. It should be noted that the getsockname system call will be made in
this case to determine the address that accepted the connection.
Different servers must listen on different address:port pairs.
mail
syntax: mail { . . . }
default
context: main
Provides the configuration file context in which the mail server directives
are specified.
protocol
syntax: protocol imap | pop3 | smtp;
default
context: server
Sets the protocol for a proxied server. Supported protocols are IMAP,
POP3, and SMTP.
If the directive is not set, the protocol can be detected automatically based
on the well-known port specified in the listen directive:
Nginx, Inc.
p.218 of 242
Configures name servers used to find the clients hostname to pass it to the
authentication server, and in the XCLIENT command when proxying SMTP.
For example:
resolver 127.0.0.1 [::1]:5353;
Before version 1.1.9, tuning of caching time was not possible, and nginx
always cached answers for the duration of 5 minutes.
The special value off disables resolving.
resolver timeout
syntax: resolver_timeout time;
default 30s
context: mail, server
Nginx, Inc.
p.219 of 242
server
syntax: server { . . . }
default
context: mail
Sets the timeout that is used before proxying to the backend starts.
Nginx, Inc.
p.220 of 242
3.2
3.2.1
pop3 auth
syntax: pop3_auth method . . . ;
default plain
context: mail, server
pop3 capabilities
syntax: pop3_capabilities extension . . . ;
default TOP USER UIDL
context: mail, server
Sets the POP3 protocol extensions list that is passed to the client in
response to the CAPA command.
The authentication methods specified in the pop3 auth and (SASL
extension) and STLS directives, are automatically added to this list if the
starttls directive is enabled.
It makes sense to specify the extensions supported by the POP3 backends
to which the clients are proxied (if these extensions are related to commands
used after the authentication, when nginx transparently proxies the client
connection to the backend).
The current list of standardized extensions is published at www.iana.org.
Nginx, Inc.
p.221 of 242
3.3
3.3.1
imap auth
syntax: imap_auth method . . . ;
default plain
context: mail, server
imap capabilities
syntax: imap_capabilities extension . . . ;
default IMAP4 IMAP4rev1 UIDPLUS
context: mail, server
Sets the IMAP protocol extensions list that is passed to the client in
response to the CAPABILITY command. The authentication methods specified
in the imap auth and STARTTLS directives are automatically added to this
list if the starttls directive is enabled.
It makes sense to specify the extensions supported by the IMAP backends to
which the clients are proxied (if these extensions are related to commands used
after the authentication, when nginx transparently proxies a client connection
to the backend).
The current list of standardized extensions is published at www.iana.org.
imap client buffer
syntax: imap_client_buffer size;
default 4k|8k
context: mail, server
Sets the IMAP commands read buffer size. By default, the buffer size is
equal to one memory page. This is either 4K or 8K, depending on a platform.
Nginx, Inc.
p.222 of 242
3.4
3.4.1
smtp auth
syntax: smtp_auth method . . . ;
default login plain
context: mail, server
smtp capabilities
syntax: smtp_capabilities extension . . . ;
default
context: mail, server
Sets the SMTP protocol extensions list that is passed to the client in
response to the EHLO command. Authentication methods specified in the
smtp auth directive are automatically added to this list.
It makes sense to specify the extensions supported by the MTA to which
the clients are proxied (if these extensions are related to commands used after
the authentication, when nginx transparently proxies the client connection to
the backend).
The current list of standardized extensions is published at www.iana.org.
Nginx, Inc.
p.223 of 242
3.5
3.5.1
auth http
syntax: auth_http URL;
default
context: mail, server
Sets the URL of the HTTP authentication server. The protocol is described
below.
auth http header
syntax: auth_http_header header value;
default
context: mail, server
3.5.2
Protocol
Good response:
Nginx, Inc.
p.224 of 242
Bad response:
HTTP /1.0 200 OK
Auth - Status : Invalid login or password
Auth - Wait : 3
Good response:
HTTP /1.0 200 OK
Auth - Status : OK
Auth - Server : 198.51.100.1
Auth - Port : 143
Auth - Pass : plain - text - pass
p.225 of 242
Nginx, Inc.
p.226 of 242
3.6
3.6.1
proxy buffer
syntax: proxy_buffer size;
default 4k|8k
context: mail, server
Sets the size of the buffer used for proxying. By default, the buffer size is
equal to one memory page. Depending on a platform, it is either 4K or 8K.
proxy pass error message
syntax: proxy_pass_error_message on | off;
default off
context: mail, server
Defines a timeout used after the proxying to the backend had started.
xclient
syntax: xclient on | off;
default on
context: mail, server
Nginx, Inc.
p.227 of 242
XCLIENT
Nginx, Inc.
p.228 of 242
3.7
3.7.1
3.7.2
Directives
ssl
syntax: ssl on | off;
default off
context: mail, server
Specifies a 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.
ssl certificate key
syntax: ssl_certificate_key file;
default
context: mail, server
Specifies a file with the secret key in the PEM format for the given server.
ssl prefer server ciphers
syntax: ssl_prefer_server_ciphers on | off;
default off
context: mail, server
Specifies that server ciphers should be preferred over client ciphers when
the SSLv3 and TLS protocols are used.
Nginx, Inc.
p.229 of 242
ssl protocols
syntax: ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2];
default SSLv3 TLSv1 TLSv1.1 TLSv1.2
context: mail, server
Sets the types and sizes of caches that store session parameters. A cache
can be of any of the following types:
off
the use of a session cache is strictly prohibited: nginx explicitly tells a
client that sessions may not be reused.
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.
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.
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.
Both cache types can be used simultaneously, for example:
s s l _ s e s s i o n _ c a c h e builtin :1000 shared : SSL :10 m ;
but using only shared cache without the built-in cache should be more
efficient.
Nginx, Inc.
p.230 of 242
Sets a 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 to configure key rotation, for example:
s s l _ s e s s i o n _ t i c k e t _ k e y current . key ;
s s l _ s e s s i o n _ t i c k e t _ k e y previous . key ;
The file must contain 48 bytes of random data and can be created using
the following command:
openssl rand 48 > ticket . key
Specifies a time during which a client may reuse the session parameters
stored in a cache.
starttls
syntax: starttls on | off | only;
default off
context: mail, server
on
allow usage of the STLS command for the POP3 and the STARTTLS
command for the IMAP;
off
deny usage of the STLS and STARTTLS commands;
only
require preliminary TLS transition.
Nginx, Inc.
p.231 of 242
Appendix A
Changelog for NGINX Plus
1.5.12, released Apr 2, 2014
SPDY protocol updated to version 3.1. SPDY/2 is no longer supported.
Added PROXY protocol support (the proxy_protocol parameter of the
listen directive).
IPv6 support added to resolver.
DNS names in upstream groups are periodically re-resolved (the resolve
parameter of the server directive).
Introduced limiting connections to upstream servers (the max_conns
parameter) with optional support for connections queue.
1.5.7, released Dec 12, 2013
Enhanced sticky routing support.
Additional status metrics for virtual hosts and cache zones.
Cache purge support (also available for FastCGI).
Added support for cache revalidation.
New module: ngx http auth request module (authorization based on the
result of a subrequest).
1.5.3, released Aug 12, 2013
232
Nginx, Inc.
p.233 of 242
Appendix B
High Availability support
How to set up simple High Availability environment on generic Linux (RHEL/CentOS or
Debian/Ubuntu based systems) in an Active/Passive manner:
1. Install nginx-ha package on both nodes by running yum install nginx-ha
(RHEL/CentOS) or apt-get install nginx-ha (Debian/Ubuntu).
2. Run nginx-ha-setup on both nodes and follow on-screen instructions. You will
need to run this script under root privileges.
The script will guide you through the interactive setup process, enabling an easy way to:
Install Corosync and Pacemaker packages
Configure management IP addresses
Create configuration for Corosync (generate authkey)
Start Corosync and check connectivity between nodes
Start Pacemaker and check cluster membership
Create basic cluster configuration (cluster IP, Active/Passive preferences)
Upon the successful completion, you will have two nodes running NGINX Plus in a highly
available Active/Passive pair:
Active (primary node for nginx and cluster IP address), and
Passive (standby node for nginx + cluster IP; resources will be transferred to this
node on failover from primary).
You can always check your cluster status on both nodes by running:
# crm status bynode
Further configuration may be required following your specific needs and environment.
Please check Pacemaker documentation for additional details: http://clusterlabs.org/doc/
234
Appendix C
Legal Notices
At the release moment of this document, there are three versions of NGINX Plus package
in distribution:
NGINX Plus (package name is nginx-plus)
NGINX Plus/Lua (package name is nginx-plus-lua)
NGINX Plus/Extras (package name is nginx-plus-extras)
These distributions contain a different set of various open source software components
described below.
Open source components included in NGINX Plus, NGINX Plus/Lua and NGINX
Plus/Extras are:
nginx/OSS, distributed under 2-clause BSD license.
Copyright 2002-2014 Igor Sysoev
Copyright 2011-2014 Nginx, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS
AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
MurmurHash algorithm, distributed under MIT license.
Copyright Austin Appleby
235
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the Software), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Open source components included in NGINX Plus/Lua and NGINX Plus/Extras are:
Nginx Development Kit (NDK) module, distributed under BSD license.
Copyright Marcus Clyne
lua-nginx-module, distributed under 2-clause BSD license.
Copyright 2009-2014, by Xiaozhe Wang (chaoslawful)
Copyright 2009-2014, by Yichun agentzh Zhang ()
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Open source components included in NGINX Plus/Extra are:
headers-more-nginx-module, distributed under 2-clause BSD license.
Copyright 2009-2014, Yichun agentzh Zhang ()
Copyright 2010-2013, Bernd Dorn
This module is licensed under the terms of the BSD license.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Nginx, Inc.
p.236 of 242
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
set-misc-nginx-module, distributed under 2-clause BSD license.
Copyright 2009-2014, Yichun agentzh Zhang ()
This module is licensed under the terms of the BSD license.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Nginx, Inc.
p.237 of 242
Index
accept mutex, 18
accept mutex delay, 18
access log, 119
add after body, 64
add before body, 64
add header, 106
addition types, 64
aio, 29
alias, 30
allow, 63
ancient browser, 70
ancient browser value, 71
auth basic, 65
auth basic user file, 65
auth http, 224
auth http header, 224
auth http timeout, 224
auth request, 67
auth request set, 67
autoindex, 69
autoindex exact size, 69
autoindex localtime, 69
break, 163
charset, 72
charset map, 73
charset types, 73
chunked transfer encoding, 31
client body buffer size, 31
client body in file only, 32
client body in single buffer, 32
client body temp path, 32
client body timeout, 32
client header buffer size, 33
client header timeout, 33
client max body size, 33
connection pool size, 33
create full put path, 76
daemon, 19
dav access, 75
dav methods, 76
debug connection, 19
debug points, 19
default type, 34
deny, 63
directio, 34
directio alignment, 34
disable symlinks, 34
empty gif, 77
env, 21
error log, 20
error page, 35
etag, 36
events, 21
expires, 106
f4f, 93
f4f buffer size, 93
fastcgi bind, 78
fastcgi buffer size, 78
fastcgi buffering, 79
fastcgi buffers, 79
fastcgi busy buffers size, 79
fastcgi cache, 79
fastcgi cache bypass, 80
fastcgi cache key, 80
fastcgi cache lock, 80
fastcgi cache lock timeout, 80
fastcgi cache methods, 81
fastcgi cache min uses, 81
fastcgi cache path, 81
fastcgi cache purge, 82
fastcgi cache revalidate, 83
fastcgi cache use stale, 83
fastcgi cache valid, 83
fastcgi catch stderr, 84
fastcgi connect timeout, 84
238
INDEX
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
fastcgi
flv, 94
INDEX
hide header, 84
ignore client abort, 85
ignore headers, 85
index, 85
intercept errors, 86
keep conn, 86
max temp file size, 86
next upstream, 86
no cache, 87
param, 87
pass, 88
pass header, 88
pass request body, 89
pass request headers, 89
read timeout, 89
send lowat, 89
send timeout, 89
split path info, 90
store, 90
store access, 91
temp file write size, 91
temp path, 91
geo, 98
geoip city, 95
geoip country, 95
geoip org, 96
geoip proxy, 97
geoip proxy recursive, 97
gunzip, 101
gunzip buffers, 101
gzip, 102
gzip buffers, 102
gzip comp level, 102
gzip disable, 103
gzip http version, 103
gzip min length, 103
gzip proxied, 103
gzip static, 105
gzip types, 104
gzip vary, 104
health check, 201
hls, 108
hls buffers, 108
hls fragment, 109
Nginx, Inc.
INDEX
INDEX
INDEX
proxy
proxy
proxy
proxy
proxy
proxy
proxy
proxy
proxy
INDEX
queue, 204
random index, 158
read ahead, 49
real ip header, 159
real ip recursive, 160
recursive error pages, 49
referer hash bucket size, 161
referer hash max size, 161
request pool size, 49
reset timedout connection, 50
resolver, 50, 219
resolver timeout, 51, 219
return, 164
rewrite, 165
rewrite log, 166
root, 51
satisfy, 51
satisfy any, 52
secure link, 168
secure link md5, 169
secure link secret, 169
send lowat, 52
send timeout, 52
sendfile, 52
sendfile max chunk, 52
server, 53, 197, 220
server name, 53, 220
server name in redirect, 55
server names hash bucket size, 55
server names hash max size, 55
server tokens, 55
session log, 172
session log format, 171
session log zone, 171
set, 166
Nginx, Inc.
INDEX
INDEX
p.242 of 242