From fc23daf5b5090a956fe1c7403bc1ac011d921ecb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <j.l.k@gmx.com>
Date: Wed, 2 Sep 2020 13:58:05 +0200
Subject: [PATCH] nginx: move the fastcgi cache configuration to the archwiki
 role

This is much cleaner because the nginx role does not have to set the
fastcgi_cache variable to "false" by default, which was overridden by
host_vars/apollo.archlinux.org to "wiki", but the value was still
hardcoded in the config.

At first, I was wondering that the cache "zone" name should be
generalized to improve the configuration (from the original per-host to
per-service), but that would be an overkill since the fastcgi cache is
used only for the wiki...
---
 host_vars/apollo.archlinux.org           | 2 --
 roles/archwiki/templates/nginx.d.conf.j2 | 3 +++
 roles/nginx/defaults/main.yml            | 1 -
 roles/nginx/templates/nginx.conf.j2      | 5 -----
 4 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/host_vars/apollo.archlinux.org b/host_vars/apollo.archlinux.org
index 5e15da463..deef677d1 100644
--- a/host_vars/apollo.archlinux.org
+++ b/host_vars/apollo.archlinux.org
@@ -36,5 +36,3 @@ fail2ban_jails:
   sshd: true
   postfix: true
   dovecot: false
-
-fastcgi_cache: wiki
diff --git a/roles/archwiki/templates/nginx.d.conf.j2 b/roles/archwiki/templates/nginx.d.conf.j2
index 89688e839..d775e20c3 100644
--- a/roles/archwiki/templates/nginx.d.conf.j2
+++ b/roles/archwiki/templates/nginx.d.conf.j2
@@ -1,3 +1,6 @@
+fastcgi_cache_path /etc/nginx/wikicache levels=1:2 keys_zone=wiki:100m inactive=60m;
+fastcgi_cache_key "$scheme$request_method$host$request_uri";
+
 upstream archwiki {
     server unix://{{ archwiki_socket }};
 }
diff --git a/roles/nginx/defaults/main.yml b/roles/nginx/defaults/main.yml
index ce608684f..00cd5b829 100644
--- a/roles/nginx/defaults/main.yml
+++ b/roles/nginx/defaults/main.yml
@@ -1,3 +1,2 @@
 ---
 letsencrypt_validation_dir: "/var/lib/letsencrypt"
-fastcgi_cache: false
diff --git a/roles/nginx/templates/nginx.conf.j2 b/roles/nginx/templates/nginx.conf.j2
index 03f61ebf7..0940ba039 100644
--- a/roles/nginx/templates/nginx.conf.j2
+++ b/roles/nginx/templates/nginx.conf.j2
@@ -72,11 +72,6 @@ http {
 
     index index.php index.html index.htm;
 
-{% if fastcgi_cache %}
-    fastcgi_cache_path /etc/nginx/wikicache levels=1:2 keys_zone=wiki:100m inactive=60m;
-    fastcgi_cache_key "$scheme$request_method$host$request_uri";
-
-{% endif %}
     access_log syslog:server=unix:/dev/log,nohostname,tag=nginx_http main;
 
     include snippets/sslsettings.conf;
-- 
GitLab