Compare commits

...

10 commits

Author SHA1 Message Date
Lee
a607a41a81
Merge pull request #116 from leev/auto-reload-segfault
Fix #90: segfault on bad auto reload value
2023-06-14 10:44:05 -05:00
Lee Valentine
df09bbb10a Fix #90: segfault on bad auto reload value 2023-06-14 10:17:41 -05:00
Lee
cbaa35461c
Merge pull request #110 from hnakamur/update_for_nginx_1_23_0
Update xfwd type changed in nginx 1.23.0 (Fixes #109)
2022-06-21 23:30:42 -05:00
Hiroaki Nakamura
8cba01cd27 Update xfwd type changed in nginx 1.23.0 2022-06-22 12:49:42 +09:00
Lee
58b92befd7
Merge pull request #102 from cloudwindy/patch-1
Update README.md
2022-03-05 15:02:59 -06:00
cloudwindy
cb416a68c1
Update README.md
master branch was renamed to main
2021-12-05 23:54:27 +08:00
Lee
a26c6beed7
Merge pull request #96 from leev/proxy-commands-readme
Add documentation for geoip2_proxy commands
2020-12-02 15:54:57 -06:00
Lee
8c780510ea
Merge pull request #95 from leev/with-stream
Document building --with-stream
2020-12-02 15:54:37 -06:00
Lee
1f216031a9
Add documentation for geoip2_proxy commands
Fixes #60
2020-12-01 17:48:13 -06:00
Lee
d66d89b4d7
Document building --with-stream
Fixes #86
2020-12-01 17:35:49 -06:00
2 changed files with 35 additions and 2 deletions

View file

@ -7,7 +7,7 @@ The module now supports nginx streams and can be used in the same way the http m
## Installing
First install [libmaxminddb](https://github.com/maxmind/libmaxminddb) as described in its [README.md
file](https://github.com/maxmind/libmaxminddb/blob/master/README.md#installing-from-a-tarball).
file](https://github.com/maxmind/libmaxminddb/blob/main/README.md#installing-from-a-tarball).
#### Download nginx source
```
@ -37,6 +37,14 @@ make
make install
```
##### If you need stream support, make sure to compile with stream:
```
./configure --add-dynamic-module=/path/to/ngx_http_geoip2_module --with-stream
OR
./configure --add-module=/path/to/ngx_http_geoip2_module --with-stream
```
## Download Maxmind GeoLite2 Database (optional)
The free GeoLite2 databases are available from [Maxminds website](http://dev.maxmind.com/geoip/geoip2/geolite2/) (requires signing up)
@ -128,3 +136,18 @@ This translates to:
```
$country_name "default=United States" source=$remote_addr country names en
```
##### Additional Commands:
These commands works the same as the original ngx_http_geoip_module documented here: http://nginx.org/en/docs/http/ngx_http_geoip_module.html#geoip_proxy.
However, if you provide the `source=$variable_with_ip` option on a variable, these settings will be ignored for that particular variable.
```
geoip2_proxy < cidr >
```
Defines trusted addresses. When a request comes from a trusted address, an address from the "X-Forwarded-For" request header field will be used instead.
```
geoip2_proxy_recursive < on | off >
```
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.

View file

@ -146,7 +146,11 @@ ngx_http_geoip2_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
MMDB_entry_data_s entry_data;
ngx_http_geoip2_conf_t *gcf;
ngx_addr_t addr;
#if defined(nginx_version) && nginx_version >= 1023000
ngx_table_elt_t *xfwd;
#else
ngx_array_t *xfwd;
#endif
u_char *p;
ngx_str_t val;
@ -169,9 +173,15 @@ ngx_http_geoip2_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
addr.sockaddr = r->connection->sockaddr;
addr.socklen = r->connection->socklen;
#if defined(nginx_version) && nginx_version >= 1023000
xfwd = r->headers_in.x_forwarded_for;
if (xfwd != NULL && gcf->proxies != NULL) {
#else
xfwd = &r->headers_in.x_forwarded_for;
if (xfwd->nelts > 0 && gcf->proxies != NULL) {
#endif
(void) ngx_http_get_forwarded_addr(r, &addr, xfwd, NULL,
gcf->proxies, gcf->proxy_recursive);
}
@ -441,7 +451,7 @@ ngx_http_geoip2_parse_config(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
if (interval == (time_t) NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid interval for auto_reload \"%V\"",
value[1]);
&value[1]);
return NGX_CONF_ERROR;
}