Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nginx
GitHub Repository: nginx/nginx.org
Path: blob/main/xml/en/docs/http/ngx_http_realip_module.xml
1 views
1
<?xml version="1.0"?>
2
3
<!--
4
Copyright (C) Igor Sysoev
5
Copyright (C) Nginx, Inc.
6
-->
7
8
<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
9
10
<module name="Module ngx_http_realip_module"
11
link="/en/docs/http/ngx_http_realip_module.html"
12
lang="en"
13
rev="8">
14
15
<section id="summary">
16
17
<para>
18
The <literal>ngx_http_realip_module</literal> module is used
19
to change the client address and optional port
20
to those sent in the specified header field.
21
</para>
22
23
<para>
24
This module is not built by default, it should be enabled with the
25
<literal>--with-http_realip_module</literal>
26
configuration parameter.
27
</para>
28
29
</section>
30
31
32
<section id="example" name="Example Configuration">
33
34
<para>
35
<example>
36
set_real_ip_from 192.168.1.0/24;
37
set_real_ip_from 192.168.2.1;
38
set_real_ip_from 2001:0db8::/32;
39
real_ip_header X-Forwarded-For;
40
real_ip_recursive on;
41
</example>
42
</para>
43
44
</section>
45
46
47
<section id="directives" name="Directives">
48
49
<directive name="set_real_ip_from">
50
<syntax>
51
<value>address</value> |
52
<value>CIDR</value> |
53
<literal>unix:</literal></syntax>
54
<default/>
55
<context>http</context>
56
<context>server</context>
57
<context>location</context>
58
59
<para>
60
Defines trusted addresses that are known to send correct
61
replacement addresses.
62
If the special value <literal>unix:</literal> is specified,
63
all UNIX-domain sockets will be trusted.
64
Trusted addresses may also be specified using a hostname (1.13.1).
65
<note>
66
IPv6 addresses are supported starting from versions 1.3.0 and 1.2.1.
67
</note>
68
</para>
69
70
</directive>
71
72
73
<directive name="real_ip_header">
74
<syntax>
75
<value>field</value> |
76
<literal>X-Real-IP</literal> |
77
<literal>X-Forwarded-For</literal> |
78
<literal>proxy_protocol</literal></syntax>
79
<default>X-Real-IP</default>
80
<context>http</context>
81
<context>server</context>
82
<context>location</context>
83
84
<para>
85
Defines the request header field
86
whose value will be used to replace the client address.
87
</para>
88
89
<para>
90
The request header field value that contains an optional port
91
is also used to replace the client port (1.11.0).
92
The address and port should be specified according to
93
<link url="https://datatracker.ietf.org/doc/html/rfc3986">RFC 3986</link>.
94
</para>
95
96
<para>
97
The <literal>proxy_protocol</literal> parameter (1.5.12) changes
98
the client address to the one from the PROXY protocol header.
99
The PROXY protocol must be previously enabled by setting the
100
<literal>proxy_protocol</literal> parameter
101
in the <link doc="ngx_http_core_module.xml" id="listen"/> directive.
102
</para>
103
104
</directive>
105
106
107
<directive name="real_ip_recursive">
108
<syntax><literal>on</literal> | <literal>off</literal></syntax>
109
<default>off</default>
110
<context>http</context>
111
<context>server</context>
112
<context>location</context>
113
<appeared-in>1.3.0</appeared-in>
114
<appeared-in>1.2.1</appeared-in>
115
116
<para>
117
If recursive search is disabled, the original client address that
118
matches one of the trusted addresses is replaced by the last
119
address sent in the request header field defined by the
120
<link id="real_ip_header"/> directive.
121
If recursive search is enabled, the original client address that
122
matches one of the trusted addresses is replaced by the last
123
non-trusted address sent in the request header field.
124
</para>
125
126
</directive>
127
128
</section>
129
130
131
<section id="variables" name="Embedded Variables">
132
133
<para>
134
<list type="tag">
135
136
<tag-name id="var_realip_remote_addr"><var>$realip_remote_addr</var></tag-name>
137
<tag-desc>
138
keeps the original client address (1.9.7)
139
</tag-desc>
140
141
<tag-name id="var_realip_remote_port"><var>$realip_remote_port</var></tag-name>
142
<tag-desc>
143
keeps the original client port (1.11.0)
144
</tag-desc>
145
146
</list>
147
</para>
148
149
</section>
150
151
</module>
152
153