server {
        listen   443 ssl;
        server_name ~^(?<ville>.+)\.collectivites-hautes-alpes-test\.entrouvert\.org$;

        include includes/ssl.conf;
        include includes/wildcard.test.entrouvert.org.conf;


        access_log  /var/log/nginx/wildcard-collectivites-hautes-alpes-test.entrouvert.org-access.log combined_full;
        error_log  /var/log/nginx/wildcard-collectivites-hautes-alpes-test.entrouvert.org-error.log;


        location ~ ^/static/(.+)$ {
            root /;
            try_files /var/lib/combo/tenants/portail-usager-hautes-alpes.test.entrouvert.org/static/$1
                      /var/lib/combo/tenants/portail-usager-hautes-alpes.test.entrouvert.org/theme/static/$1
                      /var/lib/combo/collectstatic/$1
                      =404;
            add_header Access-Control-Allow-Origin *;
        }


        location ~ ^/media/(.+)$ {
            alias /var/lib/combo/tenants/portail-usager-hautes-alpes.test.entrouvert.org/media/$1;
        }

        location /robots.txt {
            alias /var/lib/combo/www/robots.txt;
        }

        location ~ ^/$ {
            proxy_pass         http://unix:/var/run/combo/combo.sock:/$ville/; 
            proxy_set_header   Host portail-usager-hautes-alpes.test.entrouvert.org; 
            proxy_set_header   X-Forwarded-SSL on; 
            proxy_set_header   X-Forwarded-Protocol ssl; 
            proxy_set_header   X-Forwarded-Proto https; 
            proxy_set_header   X-Real-IP       $remote_addr; 
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 
        } 
 
        location / { 
            proxy_pass         http://unix:/var/run/combo/combo.sock:/; 
            proxy_set_header   Host portail-usager-hautes-alpes.test.entrouvert.org; 
            proxy_set_header   X-Forwarded-SSL on; 
            proxy_set_header   X-Forwarded-Protocol ssl; 
            proxy_set_header   X-Forwarded-Proto https; 
            proxy_set_header   X-Real-IP       $remote_addr; 
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 
        } 

}

server {
        listen   80;
        server_name *.collectivites-hautes-alpes-test.entrouvert.org;

        access_log  /var/log/nginx/wildcard-collectivites-hautes-alpes-test.entrouvert.org-access.log combined_full;
        error_log  /var/log/nginx/wildcard-collectivites-hautes-alpes-test.entrouvert.org-error.log;

        return 302 https://$host$request_uri;
}

