# Default 443 für unbekannte Subdomains
server {
    listen 443 ssl http2 default_server;
    server_name _;

    ssl_certificate /etc/letsencrypt/live/server.schooltech.ch/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/server.schooltech.ch/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;

    return 444;
}

# ------------------------------------------------------------
# portainer.server.schooltech.ch
# ------------------------------------------------------------
server {
    listen 443 ssl http2;
    server_name portainer.server.schooltech.ch;

    ssl_certificate /etc/letsencrypt/live/server.schooltech.ch/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/server.schooltech.ch/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;

    # Auth nur auf UI
    location / {
        auth_request /nginxauth;

        proxy_pass http://portainer:9000;
        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_set_header Host $host;
        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;

        # iFrame-freundlich
        proxy_hide_header X-Frame-Options;
        add_header X-Frame-Options "ALLOWALL" always;
        proxy_hide_header Content-Security-Policy;
        add_header Content-Security-Policy "frame-ancestors *" always;
    }

    location = /nginxauth {
        internal;
        proxy_pass http://appserverauth:3000/internal/auth;
        proxy_set_header Cookie $http_cookie;
        proxy_set_header X-Original-URI $request_uri;
        proxy_set_header X-Original-Host $host;
        proxy_set_header X-Forwarded-Host $host;
    }
}

# ------------------------------------------------------------
# abc.server.schooltech.ch
# ------------------------------------------------------------
server {
    listen 443 ssl http2;
    server_name abc.server.schooltech.ch;

    ssl_certificate /etc/letsencrypt/live/server.schooltech.ch/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/server.schooltech.ch/privkey.pem;

    root /usr/share/nginx/abc;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }
}

# ------------------------------------------------------------
# xyz.server.schooltech.ch
# ------------------------------------------------------------
server {
    listen 443 ssl http2;
    server_name xyz.server.schooltech.ch;

    ssl_certificate /etc/letsencrypt/live/server.schooltech.ch/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/server.schooltech.ch/privkey.pem;

    root /usr/share/nginx/xyz;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }
}

# ------------------------------------------------------------
# guacamole.server.schooltech.ch
# ------------------------------------------------------------
server {
    listen 443 ssl http2;
    server_name guacamole.server.schooltech.ch;

    ssl_certificate /etc/letsencrypt/live/server.schooltech.ch/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/server.schooltech.ch/privkey.pem;

    location / {
        proxy_pass http://guacamole:8080;
        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 https;

        # iFrame-freundlich
        proxy_hide_header X-Frame-Options;
        add_header X-Frame-Options "ALLOWALL" always;
        proxy_hide_header Content-Security-Policy;
        add_header Content-Security-Policy "frame-ancestors *" always;
    }
}

