Skip to content

Commit

Permalink
Use http2 directive depending on nginx version
Browse files Browse the repository at this point in the history
  • Loading branch information
bviktor committed Nov 8, 2024
1 parent b43a479 commit 2e6d717
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
14 changes: 14 additions & 0 deletions tasks/nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
- nginx
- openssl

- name: Determine nginx version
shell:
cmd: nginx -v
changed_when: false
register: noobient_nginx_ng_check

# Example output:
# nginx version: nginx/1.26.2
- set_fact:
noobient_nginx_ng_ver: "{{ noobient_nginx_ng_check.stderr_lines[0].split(':')[1].split('/')[1] }}"

- set_fact:
noobient_nginx_http2_new_syntax: "{% if noobient_nginx_ng_ver is version('1.25.1', '>=') %}true{% else %}false{% endif %}"

- name: Enable nginx service
systemd:
name: nginx.service
Expand Down
12 changes: 8 additions & 4 deletions templates/host.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
server
{
{% if not eff_ssl_disabled | bool %}
listen {{ eff_host_port }} ssl;
listen [::]:{{ eff_host_port }} ssl;
listen {{ eff_host_port }} ssl{% if not noobient_nginx_http2_new_syntax | bool %} http2{% endif %};
listen [::]:{{ eff_host_port }} ssl{% if not noobient_nginx_http2_new_syntax | bool %} http2{% endif %};
{% if noobient_nginx_http2_new_syntax | bool %}
http2 on;
{% endif %}
include ssl.conf;
ssl_certificate {{ eff_ssl_cert }};
ssl_certificate_key {{ eff_ssl_key }};
Expand Down Expand Up @@ -34,9 +36,11 @@ upstream appserver
server
{
{% if not eff_ssl_disabled | bool %}
listen {{ eff_host_port }} ssl;
listen [::]:{{ eff_host_port }} ssl;
listen {{ eff_host_port }} ssl{% if not noobient_nginx_http2_new_syntax | bool %} http2{% endif %};
listen [::]:{{ eff_host_port }} ssl{% if not noobient_nginx_http2_new_syntax | bool %} http2{% endif %};
{% if noobient_nginx_http2_new_syntax | bool %}
http2 on;
{% endif %}
include ssl.conf;
ssl_certificate {{ eff_ssl_cert }};
ssl_certificate_key {{ eff_ssl_key }};
Expand Down

0 comments on commit 2e6d717

Please sign in to comment.