Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add geoip module support #66

Merged
merged 1 commit into from
Nov 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ nginx_source_modules_included:
http_perl_module: "--with-http_perl_module"
naxsi_module: "--add-module=/tmp/naxsi-{{nginx_naxsi_version}}/naxsi_src"
ngx_pagespeed: "--add-module=/tmp/ngx_pagespeed-release-{{nginx_ngx_pagespeed_version}}-beta"
geopip: "--with-http_geoip_module"
```

##### Sites
Expand Down Expand Up @@ -193,6 +194,11 @@ You can put Nginx under monit monitoring protection, by setting `monit_protectio
###### naxsi module
- `nginx_naxsi_version` - version of the naxsi module

###### geoip module
- `nginx_geoip: 'on'`
- `nginx_geoip_country: "{{nginx_dir}}/geoip/GeoIP.dat"`
- `nginx_geoip_city: "{{nginx_dir}}/geoip/GeoLiteCity.dat"`

#### Thanks

To the contributors:
Expand Down
5 changes: 5 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ nginx_source_modules_included:
http_perl_module: "--with-http_perl_module"
naxsi_module: "--add-module=/tmp/naxsi-{{nginx_naxsi_version}}/naxsi_src"
ngx_pagespeed: "--add-module=/tmp/ngx_pagespeed-release-{{nginx_ngx_pagespeed_version}}-beta"
http_geoip_module: "--with-http_geoip_module"

nginx_source_modules_excluded:
- mail_pop3_module
Expand Down Expand Up @@ -117,6 +118,10 @@ nginx_gzip_types:
- image/svg+xml
nginx_gzip_disable: "MSIE [1-6]\\."

# geoip_module
nginx_geoip: 'off'
nginx_geoip_country: "{{nginx_dir}}/geoip/GeoIP.dat"
nginx_geoip_city: "{{nginx_dir}}/geoip/GeoLiteCity.dat"

# http_stub_status_module configuration
nginx_remote_ip_var: "remote_addr"
Expand Down
3 changes: 3 additions & 0 deletions tasks/modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@

- include: modules/ngx_pagespeed.yml
when: nginx_source_modules_included.ngx_pagespeed is defined

- include: modules/http_geoip_module.yml
when: nginx_source_modules_included.http_geoip_module is defined
37 changes: 37 additions & 0 deletions tasks/modules/http_geoip_module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# file: nginx/tasks/modules/http_geoip_module.yml
# configure flag: --with-http_geoip_module

- name: Nginx | Modules | Install GeoIp lib
apt: pkg={{ item }} state=latest
with_items:
- libgeoip1
- libgeoip-dev
when: nginx_source_modules_included.http_geoip_module is defined

- name: Nginx | Modules | Create directory inside nginx
file: path={{nginx_dir}}/geoip state=directory
when: nginx_source_modules_included.http_geoip_module is defined

- name: Nginx | Modules | Download GeoIP database files
get_url: url=http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz dest={{nginx_dir}}/geoip/GeoIP.dat.gz
when: nginx_source_modules_included.http_geoip_module is defined

- name: Nginx | Modules | Download GeoLiteCity database files
get_url: url=http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz dest={{nginx_dir}}/geoip/GeoLiteCity.dat.gz
when: nginx_source_modules_included.http_geoip_module is defined

- name: Nginx | Modules | Check if the GeoIP file exists
stat: path={{nginx_dir}}/geoip/GeoIP.dat
register: geoip_file

- name: Nginx | Modules | Unarchive GeoIP files
shell: gunzip -c {{nginx_dir}}/geoip/GeoIP.dat.gz > {{nginx_dir}}/geoip/GeoIP.dat
when: not geoip_file.stat.exists

- name: Nginx | Modules | Check if the GeoLiteCity file exists
stat: path={{nginx_dir}}/geoip/GeoLiteCity.dat
register: geolitecity_file

- name: Nginx | Modules | Unarchive GeoLiteCity files
shell: gunzip -c {{nginx_dir}}/geoip/GeoLiteCity.dat.gz > {{nginx_dir}}/geoip/GeoLiteCity.dat
when: not geolitecity_file.stat.exists
7 changes: 7 additions & 0 deletions templates/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ http {
gzip_disable "{{nginx_gzip_disable}}";
{% endif %}

{% if nginx_install_method == "source" %}
{% if nginx_geoip == 'on' %}
geoip_country {{nginx_geoip_country}};
geoip_city {{nginx_geoip_city}};
{% endif %}
{% endif %}

{% if nginx_buffers == 'on' %}
client_body_buffer_size {{nginx_client_body_buffer_size}};
client_header_buffer_size {{nginx_client_header_buffer_size}};
Expand Down