library/roles/nginx: More changes to the unified virtualhost template.

This commit is contained in:
Andrea Dell'Amico 2016-11-09 14:27:00 +01:00
parent ddb60cf945
commit 6b6fb1c24f
3 changed files with 95 additions and 90 deletions

View File

@ -64,6 +64,7 @@ nginx_ldap_base_dn: "dc=example,dc=org"
# nginx_ldap_pam_groupdn: # nginx_ldap_pam_groupdn:
nginx_letsencrypt_managed: True nginx_letsencrypt_managed: True
nginx_websockets_support: False nginx_websockets_support: False
nginx_use_common_virthost: False
# Virtualhost example # Virtualhost example
# nginx_virthosts: # nginx_virthosts:

View File

@ -1,8 +1,8 @@
--- ---
- include: nginx.yml - include: nginx.yml
- include: nginx-config.yml - include: nginx-config.yml
#- include: nginx-virtualhosts.yml - include: nginx-virtualhosts.yml
# when: nginx_virthosts|length > 0 when: nginx_use_common_virthost
- include: nginx-letsencrypt.yml - include: nginx-letsencrypt.yml
when: letsencrypt_acme_install is defined and letsencrypt_acme_install when: letsencrypt_acme_install is defined and letsencrypt_acme_install
- include: pam-ldap.yml - include: pam-ldap.yml

View File

@ -1,6 +1,9 @@
server { server {
listen {{ item.http_port }}; listen {{ item.http_port }};
server_name {{ item.server_name }} {% if item.serveraliases is defined %}{{ item.serveraliases }}{% endif %}; server_name {{ item.server_name }} {% if item.serveraliases is defined %}{{ item.serveraliases }}{% endif %};
{% if letsencrypt_acme_install %}
include /etc/nginx/snippets/letsencrypt-proxy.conf;
{% endif %}
{% if item.access_log is defined %} {% if item.access_log is defined %}
access_log {{ item.access_log }}; access_log {{ item.access_log }};
{% else %} {% else %}
@ -11,23 +14,16 @@ server {
{% else %} {% else %}
error_log /var/log/nginx/{{ item.server_name }}_error.log; error_log /var/log/nginx/{{ item.server_name }}_error.log;
{% endif %} {% endif %}
server_tokens {{ item.server_tokens | default('off') }};
{% if not item.ssl_enabled %} {% if item.ssl_enabled and item.ssl_only %}
location / {
return 301 https://{{ ansible_fqdn }}$request_uri;
}
{% else %}
# This is the default for nginx on Ubuntu 14.04 # This is the default for nginx on Ubuntu 14.04
{% if item.root is defined %} root {{ item.root | default('/usr/share/nginx/html/') }};
root {{ item.root }}; index {{ item.index | default('index.html index.htm') }};
{% else %} error_page 500 502 503 504 {{ item.error_page | default('/50x.html') }};
root /usr/share/nginx/html;
{% endif %}
{% if item.index is defined %}
index {{ item.index }};
{% else %}
index index.html index.htm;
{% endif %}
{% if item.error_page is defined %}
error_page 500 502 503 504 {{ item.error_page }};
{% else %}
error_page 500 502 503 504 /50x.html;
location = /50x.html { location = /50x.html {
root /usr/share/nginx/html; root /usr/share/nginx/html;
} }
@ -41,6 +37,13 @@ server {
log_not_found off; log_not_found off;
access_log off; access_log off;
} }
{% if haproxy_ips is defined %}
# We are behind haproxy
{% for ip in haproxy_ips %}
set_real_ip_from {{ ip }};
{% endfor %}
real_ip_header X-Forwarded-For;
{% endif %}
{% if item.max_body is defined %} {% if item.max_body is defined %}
client_max_body_size {{ item.max_body }}; client_max_body_size {{ item.max_body }};
{% else %} {% else %}
@ -51,106 +54,107 @@ server {
{% else %} {% else %}
client_body_timeout {{ nginx_client_body_timeout }}; client_body_timeout {{ nginx_client_body_timeout }};
{% endif %} {% endif %}
{% if item.server_tokens is defined %} server_tokens {{ item.server_tokens | default('off') }};
server_tokens {{ item.server_tokens }};
{% else %}
# don't send the nginx version number in error pages and Server header
server_tokens off;
{% endif %}
{% if item.websockets is defined and item.websockets %}
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
{% endif %}
{% if item.proxy_standard_setup is defined and item.proxy_standard_setup %} {% if item.proxy_standard_setup is defined and item.proxy_standard_setup %}
# Proxy stuff # Proxy stuff
proxy_set_header Host $host; include /etc/nginx/snippets/nginx-proxy-params.conf;
proxy_set_header X-Real-IP $remote_addr;
proxy_buffer_size {{ nginx_proxy_buffer_size }};
proxy_buffers {{ nginx_proxy_buffers }};
proxy_busy_buffers_size {{ nginx_proxy_busy_buffers_size }};
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_redirect {{ nginx_proxy_redirect }};
proxy_buffering {{ nginx_proxy_buffering }};
proxy_connect_timeout {{ nginx_proxy_connect_timeout }};
proxy_read_timeout {{ nginx_proxy_read_timeout }};
proxy_send_timeout {{ nginx_proxy_send_timeout }};
{% endif %}
{% if item.proxy_additional_options is defined %} {% if item.proxy_additional_options is defined %}
{% for popt in item.proxy_additional_options %} {% for popt in item.proxy_additional_options %}
{{ popt }} {{ popt }}
{% endfor %} {% endfor %}
location / { {% endif %}
proxy_pass http://localhost:{{ grafana_http_port }}/; {% if item.proxies is defined %}
{% for proxy in item.proxies %}
location {{ proxy.location }} {
proxy_pass {{ proxy.target }};
} }
{% else %} {% endfor %}
location / { {% endif %}
return 301 https://{{ ansible_fqdn }}$request_uri; {% endif %}
} {% if item.extra_parameters is defined %}
{{ item.extra_parameters }}
{% endif %} {% endif %}
} }
{% if http_ssl_enabled %} {% if item.ssl_enabled and item.ssl_only %}
server { server {
listen {{ https_port }} ssl; listen {{ https_port }} ssl;
server_name {{ item.server_name }} {% if item.serveraliases is defined %}{{ item.serveraliases }}{% endif %};
server_name {{ ansible_fqdn }}; {% if item.access_log is defined %}
client_max_body_size 100M; access_log {{ item.access_log }};
access_log /var/log/nginx/access_ssl.log; {% else %}
error_log /var/log/nginx/error_ssl.log; access_log /var/log/nginx/{{ item.server_name }}_ssl_access.log;
# This is the default for nginx on Ubuntu 14.04 {% endif %}
root /usr/share/nginx/html/; {% if item.error_log is defined %}
error_log {{ item.error_log }};
ssl_certificate {{ letsencrypt_acme_certs_dir }}/fullchain; {% else %}
ssl_certificate_key {{ letsencrypt_acme_certs_dir }}/privkey; error_log /var/log/nginx/{{ item.server_name }}_ssl_error.log;
ssl_session_cache shared:SSL:10m; {% endif %}
ssl_session_timeout 10m; root {{ item.root | default('/usr/share/nginx/html/') }};
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; index {{ item.index | default('index.html index.htm') }};
ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA"; error_page 500 502 503 504 {{ item.error_page | default('/50x.html') }};
ssl_prefer_server_ciphers on;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html { location = /50x.html {
root /usr/share/nginx/www; root /usr/share/nginx/html;
} }
{% endif %}
location = /favicon.ico { location = /favicon.ico {
log_not_found off; log_not_found off;
access_log off; access_log off;
} }
location = /robots.txt { location = /robots.txt {
allow all; allow all;
log_not_found off; log_not_found off;
access_log off; access_log off;
} }
{% if haproxy_ips is defined %}
# We are behind haproxy
{% for ip in haproxy_ips %}
set_real_ip_from {{ ip }};
{% endfor %}
real_ip_header X-Forwarded-For;
{% endif %}
{% if item.max_body is defined %}
client_max_body_size {{ item.max_body }};
{% else %}
client_max_body_size {{ nginx_client_max_body_size }};
{% endif %}
{% if item.body_timeout is defined %}
client_body_timeout {{ item.body_timeout }};
{% else %}
client_body_timeout {{ nginx_client_body_timeout }};
{% endif %}
server_tokens {{ item.server_tokens | default('off') }};
# don't send the nginx version number in error pages and Server header include /etc/nginx/snippets/nginx-server-ssl.conf;
server_tokens off;
{% if item.websockets is defined and item.websockets %}
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
{% endif %}
{% if item.proxy_standard_setup is defined and item.proxy_standard_setup %}
# Proxy stuff # Proxy stuff
proxy_set_header Host $host; include /etc/nginx/snippets/nginx-proxy-params.conf;
proxy_set_header X-Real-IP $remote_addr; {% if item.proxy_additional_options is defined %}
proxy_buffer_size {{ nginx_proxy_buffer_size }}; {% for popt in item.proxy_additional_options %}
proxy_buffers {{ nginx_proxy_buffers }}; {{ popt }}
proxy_busy_buffers_size {{ nginx_proxy_busy_buffers_size }}; {% endfor %}
proxy_set_header X-Forwarded-Host $host; {% endif %}
proxy_set_header X-Forwarded-Server $host; {% if item.proxies is defined %}
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; {% for proxy in item.proxies %}
proxy_http_version 1.1; location {{ proxy.location }} {
proxy_redirect {{ nginx_proxy_redirect }}; proxy_pass {{ proxy.target }};
proxy_buffering {{ nginx_proxy_buffering }};
proxy_connect_timeout {{ nginx_proxy_connect_timeout }};
proxy_read_timeout {{ nginx_proxy_read_timeout }};
proxy_send_timeout {{ nginx_proxy_send_timeout }};
location / {
proxy_pass http://localhost:{{ grafana_http_port }}/;
} }
{% endfor %}
{% endif %}
{% endif %}
{% if item.extra_parameters is defined %}
{{ item.extra_parameters }}
} }
{% endif %} {% endif %}