From 2aa9dd5f069f803c44859de0a96950039baca36e Mon Sep 17 00:00:00 2001 From: Robert O'Connor Date: Mon, 4 Sep 2017 22:41:29 -0400 Subject: [PATCH] Fixes #86 -- Add ipv6 support --- README.md | 5 +++++ defaults/main.yml | 4 ++++ templates/vhost.j2 | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 1c00cab..566d1ae 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,11 @@ None. Available variables are listed below, along with default values (see `defaults/main.yml`): + + nginx_listen_ipv6: true + + Whether or not we want to listen on IPv6, this is enabled by default. + nginx_vhosts: [] A list of vhost definitions (server blocks) for Nginx virtual hosts. Each entry will create a separate config file named by `server_name`. If left empty, you will need to supply your own virtual host configuration. See the commented example in `defaults/main.yml` for available server options. If you have a large number of customizations required for your server definition(s), you're likely better off managing the vhost configuration file yourself, leaving this variable set to `[]`. diff --git a/defaults/main.yml b/defaults/main.yml index 0509dbe..fa4a153 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -57,6 +57,10 @@ nginx_extra_http_options: "" # proxy_set_header Host $http_host; nginx_remove_default_vhost: false + +# Listen on IPv6 (default: true) +nginx_listen_ipv6: true + nginx_vhosts: [] # Example vhost below, showing all available options: # - listen: "80" # default: "80" diff --git a/templates/vhost.j2 b/templates/vhost.j2 index 0feb602..69cb838 100644 --- a/templates/vhost.j2 +++ b/templates/vhost.j2 @@ -2,6 +2,9 @@ {% if item.server_name_redirect is defined %} server { listen {{ item.listen | default('80') }}; + {% if nginx_listen_ipv6 %} + listen [::]:{{item.listen | default('80') }}; + {% endif %} server_name {{ item.server_name_redirect }}; return 301 $scheme://{{ item.server_name.split(' ')[0] }}$request_uri; } @@ -13,6 +16,9 @@ server { {% block server_basic -%} listen {{ item.listen | default('80') }}; +{% if nginx_listen_ipv6 %} + listen [::]:{{item.listen | default('80') }}; +{% endif %} {% if item.server_name is defined %} server_name {{ item.server_name }};