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 #46

Closed
wants to merge 19 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Icon
.Trashes
.vagrant
test
inventory
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,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 @@ -187,14 +188,19 @@ 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:
- [Jean-Denis Vauguet](https://github.com/chikamichi)


#### Testing
This project comes with a VagrantFile, this is a fast and easy way to test changes to the role, fire it up with `vagrant up`.
This project comes with a VagrantFile, this is a fast and easy way to test changes to the role, fire it up with `vagrant up`.

See [vagrant docs](https://docs.vagrantup.com/v2/) for getting setup with vagrant

Expand Down
9 changes: 7 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# file: nginx/defaults/main.yml

nginx_install_method: "source"
nginx_source_version: "1.6.2"
nginx_source_version: "1.8.0"

nginx_user: www-data
nginx_group: www-data
Expand Down 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"
geoip: "--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: 'on'
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 Expand Up @@ -164,4 +169,4 @@ nginx_naxsi_url: "https://github.com/nbs-system/naxsi/archive/{{nginx_naxsi_vers
nginx_ngx_pagespeed_version: 1.9.32.3

# OpenSSL configuration
openssl_version: "1.0.2c"
openssl_version: "1.0.2d"
2 changes: 1 addition & 1 deletion tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
name: nginx
state: started
register: nginx_first_start
when: not nginx_config.stat.exists
when: not nginx_config.stat.exists
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.geoip 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.geoip is defined

- name: Nginx | Modules | Create directory inside nginx
file: path={{nginx_dir}}/geoip state=directory
when: nginx_source_modules_included.geoip 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.geoip 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.geoip 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 @@ -72,6 +72,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
1 change: 1 addition & 0 deletions test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- hosts: all
vars_files:
- 'defaults/main.yml'

tasks:
- name: install the dependencies
apt:
Expand Down