From 99350ca17c7d6ffd2bd77750244a81e2d384e364 Mon Sep 17 00:00:00 2001 From: Mengyang Li Date: Thu, 28 Jun 2018 13:42:00 -0700 Subject: [PATCH] nginx: add hashbang-http --- ansible/tasks/nginx/main.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ansible/tasks/nginx/main.yml b/ansible/tasks/nginx/main.yml index 8ce1647..a0263f4 100644 --- a/ansible/tasks/nginx/main.yml +++ b/ansible/tasks/nginx/main.yml @@ -20,3 +20,33 @@ name={{ item }} with_items: - nginx + +- name: Setup sites-enabled/hashbang-http + register: nginxconf + copy: + dest: /etc/nginx/sites-enabled/hashbang-http + content: | + # Hashbang server configuration + # ref: https://gist.github.com/RyanSquared/e59c7e274abef06e63b0e47e46997b00 + # + server { + listen 80; + listen [::]:80; + + server_name "~^(?[a-zA-Z0-9]+)\.(?\w{2}\d{1})\.hashbang\.sh$"; + + location / { + proxy_pass http://unix:/home/$user/.nginx.sock; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + } + +- name: Remove default nginx site + file: + state: absent + path: /etc/nginx/sites-enabled/default + +- name: Restart nginx + when: nginxconf.chnaged + service: name=nginx state=restarted enabled=yes