comparison src/http/ngx_http_variables.c @ 5605:3a72b1805c52

Added server-side support for PROXY protocol v1 (ticket #355). Client address specified in the PROXY protocol header is now saved in the $proxy_protocol_addr variable and can be used in the realip module. This is currently not implemented for mail.
author Roman Arutyunyan <arut@nginx.com>
date Mon, 17 Mar 2014 17:41:24 +0400
parents 30e806b8636a
children 3a48775f1535
comparison
equal deleted inserted replaced
5604:22d485944c20 5605:3a72b1805c52
51 static ngx_int_t ngx_http_variable_binary_remote_addr(ngx_http_request_t *r, 51 static ngx_int_t ngx_http_variable_binary_remote_addr(ngx_http_request_t *r,
52 ngx_http_variable_value_t *v, uintptr_t data); 52 ngx_http_variable_value_t *v, uintptr_t data);
53 static ngx_int_t ngx_http_variable_remote_addr(ngx_http_request_t *r, 53 static ngx_int_t ngx_http_variable_remote_addr(ngx_http_request_t *r,
54 ngx_http_variable_value_t *v, uintptr_t data); 54 ngx_http_variable_value_t *v, uintptr_t data);
55 static ngx_int_t ngx_http_variable_remote_port(ngx_http_request_t *r, 55 static ngx_int_t ngx_http_variable_remote_port(ngx_http_request_t *r,
56 ngx_http_variable_value_t *v, uintptr_t data);
57 static ngx_int_t ngx_http_variable_proxy_protocol_addr(ngx_http_request_t *r,
56 ngx_http_variable_value_t *v, uintptr_t data); 58 ngx_http_variable_value_t *v, uintptr_t data);
57 static ngx_int_t ngx_http_variable_server_addr(ngx_http_request_t *r, 59 static ngx_int_t ngx_http_variable_server_addr(ngx_http_request_t *r,
58 ngx_http_variable_value_t *v, uintptr_t data); 60 ngx_http_variable_value_t *v, uintptr_t data);
59 static ngx_int_t ngx_http_variable_server_port(ngx_http_request_t *r, 61 static ngx_int_t ngx_http_variable_server_port(ngx_http_request_t *r,
60 ngx_http_variable_value_t *v, uintptr_t data); 62 ngx_http_variable_value_t *v, uintptr_t data);
181 183
182 { ngx_string("remote_addr"), NULL, ngx_http_variable_remote_addr, 0, 0, 0 }, 184 { ngx_string("remote_addr"), NULL, ngx_http_variable_remote_addr, 0, 0, 0 },
183 185
184 { ngx_string("remote_port"), NULL, ngx_http_variable_remote_port, 0, 0, 0 }, 186 { ngx_string("remote_port"), NULL, ngx_http_variable_remote_port, 0, 0, 0 },
185 187
188 { ngx_string("proxy_protocol_addr"), NULL,
189 ngx_http_variable_proxy_protocol_addr, 0, 0, 0 },
190
186 { ngx_string("server_addr"), NULL, ngx_http_variable_server_addr, 0, 0, 0 }, 191 { ngx_string("server_addr"), NULL, ngx_http_variable_server_addr, 0, 0, 0 },
187 192
188 { ngx_string("server_port"), NULL, ngx_http_variable_server_port, 0, 0, 0 }, 193 { ngx_string("server_port"), NULL, ngx_http_variable_server_port, 0, 0, 0 },
189 194
190 { ngx_string("server_protocol"), NULL, ngx_http_variable_request, 195 { ngx_string("server_protocol"), NULL, ngx_http_variable_request,
1198 } 1203 }
1199 1204
1200 if (port > 0 && port < 65536) { 1205 if (port > 0 && port < 65536) {
1201 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; 1206 v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
1202 } 1207 }
1208
1209 return NGX_OK;
1210 }
1211
1212
1213 static ngx_int_t
1214 ngx_http_variable_proxy_protocol_addr(ngx_http_request_t *r,
1215 ngx_http_variable_value_t *v, uintptr_t data)
1216 {
1217 v->len = r->connection->proxy_protocol_addr.len;
1218 v->valid = 1;
1219 v->no_cacheable = 0;
1220 v->not_found = 0;
1221 v->data = r->connection->proxy_protocol_addr.data;
1203 1222
1204 return NGX_OK; 1223 return NGX_OK;
1205 } 1224 }
1206 1225
1207 1226