From f9190f397883c694b6ca91afcc53c2b41aba472c Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 22 Aug 2018 09:16:54 +0100 Subject: [PATCH] Add LOCAL_DOMAIN variable. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I wanted to use Mastodon on a server whose hostname didn’t match the domain to be used. --- group_vars/all.sample | 2 ++ roles/mastodon-config/templates/.env.production.sample | 2 +- roles/mastodon-nginx/tasks/main.yml | 6 +++--- roles/mastodon-nginx/templates/mastodon-nginx.conf | 8 ++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/group_vars/all.sample b/group_vars/all.sample index 5cd8ecc..eadf175 100644 --- a/group_vars/all.sample +++ b/group_vars/all.sample @@ -2,3 +2,5 @@ # Please note that the playbook will drop this database in preparation for Mastodon's # database setup process. DB_NAME: +# Specify the hostname you wish to use (in case it doesn't match the server's name). +LOCAL_DOMAIN: diff --git a/roles/mastodon-config/templates/.env.production.sample b/roles/mastodon-config/templates/.env.production.sample index 5d56041..766ae78 100644 --- a/roles/mastodon-config/templates/.env.production.sample +++ b/roles/mastodon-config/templates/.env.production.sample @@ -16,7 +16,7 @@ DB_PASS= DB_PORT=5432 # Your instance's domain (Don't modify this, we get this from a variable) -LOCAL_DOMAIN={{ ansible_nodename }} +LOCAL_DOMAIN={{ LOCAL_DOMAIN }} # We have HTTPS enabled LOCAL_HTTPS=true diff --git a/roles/mastodon-nginx/tasks/main.yml b/roles/mastodon-nginx/tasks/main.yml index 2d36f3a..362eb99 100644 --- a/roles/mastodon-nginx/tasks/main.yml +++ b/roles/mastodon-nginx/tasks/main.yml @@ -18,11 +18,11 @@ - name: Copy Mastodon nginx vhost template to sites-available template: src: mastodon-nginx.conf - dest: /etc/nginx/sites-available/{{ ansible_nodename }}.conf + dest: /etc/nginx/sites-available/{{ LOCAL_DOMAIN }}.conf - name: Enable Mastodon nginx vhost template file: - src: /etc/nginx/sites-available/{{ ansible_nodename }}.conf - dest: /etc/nginx/sites-enabled/{{ ansible_nodename }}.conf + src: /etc/nginx/sites-available/{{ LOCAL_DOMAIN }}.conf + dest: /etc/nginx/sites-enabled/{{ LOCAL_DOMAIN }}.conf state: link - name: Start nginx service: name=nginx state=started diff --git a/roles/mastodon-nginx/templates/mastodon-nginx.conf b/roles/mastodon-nginx/templates/mastodon-nginx.conf index a28cdfd..7b1c12c 100644 --- a/roles/mastodon-nginx/templates/mastodon-nginx.conf +++ b/roles/mastodon-nginx/templates/mastodon-nginx.conf @@ -6,7 +6,7 @@ map $http_upgrade $connection_upgrade { server { listen 80; listen [::]:80; - server_name {{ ansible_nodename }}; + server_name {{ LOCAL_DOMAIN }}; # Useful for Let's Encrypt location /.well-known/acme-challenge/ { allow all; } location / { return 301 https://$host$request_uri; } @@ -15,15 +15,15 @@ server { server { listen 443 ssl http2; listen [::]:443 ssl http2; - server_name {{ ansible_nodename }}; + server_name {{ LOCAL_DOMAIN }}; ssl_protocols TLSv1.2; ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; - ssl_certificate /etc/letsencrypt/live/{{ ansible_nodename }}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/{{ ansible_nodename }}/privkey.pem; + ssl_certificate /etc/letsencrypt/live/{{ LOCAL_DOMAIN }}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/{{ LOCAL_DOMAIN }}/privkey.pem; keepalive_timeout 70; sendfile on;