---
- name: Prepare
  hosts: all
  vars: 
    service_url: "hedgedocs"
    nginx_extra_http_options: |
      map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
      }   

    nginx_vhosts:
      - listen: "80"
        server_name: "{{ service_url }}"
        access_log: "/var/log/nginx/{{ service_url }}_access.log"
        error_log: "/var/log/nginx/{{ service_url }}_error.log"
        state: "present"
        template: "{{ nginx_vhost_template }}"
        filename: "{{ service_url }}.http.conf"
        extra_parameters: |          
          location / {
                    proxy_pass http://127.0.0.1:3003;
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header X-Forwarded-Proto $scheme;
                  }

                  location /socket.io/ {
                    proxy_pass http://127.0.0.1:3003;
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header X-Forwarded-Proto $scheme;
                    proxy_set_header Upgrade $http_upgrade;
                    proxy_set_header Connection $connection_upgrade;
                  }
  roles:
    - geerlingguy.nginx
    - geerlingguy.nodejs
    - geerlingguy.postgresql
