# /etc/nginx/sites-available/shinken_ssl
# Shinken WebUI
#
server {
    # IPv4 support
    listen {{ modules.webui2.nginx.port }};
    # IPv6 support
    #listen [::]:443;

    server_name shinken;

    access_log           {{ nginx_log_dir }}/shinken_access.log;
    error_log            {{ nginx_log_dir }}/shinken_error.log;

    ssl on;
    ssl_certificate      {{ ini.server_cert }};
    ssl_certificate_key  {{ ini.server_key }};

    # Avoid robots
    location /robots.txt {
        return 200 "User-agent: *\nDisallow: /";
    }

    # Serve static content directly
    location /static/(.*\/)? {
        try_files htdocs/$uri plugins/$1/htdocs/$uri @webui;
    }
    location @webui {
        root {{ user.home }}/modules/webui2/;
    }

    # Redirection
    location / {
        # Set the adequate variables so that the WebUI will
        # know what hostname it has, this is useful for redirects
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;

        # Replace 7767 (default) by the port your shinken WebUI is listening on.
        proxy_pass http://localhost:{{ modules.webui2.config.port }};
        proxy_read_timeout  60;

        proxy_redirect http://localhost:{{ modules.webui2.config.port }} https://{{ host }}:{{ modules.webui2.nginx.port }};
    }
}
