server {
    listen 80;
    server_name xiexianbin.cn;
    # logging
    access_log  /var/log/tengine/xiexianbin.cn.access.log main;
    error_log   /var/log/tengine/xiexianbin.cn.error.log warn;
    location / {
        return 301 http://$arg_host-$arg_port.xiexianbin.cn;
    }
}

server {
    listen       80;
    server_name  *.xiexianbin.cn;
    # logging
    access_log  /var/log/tengine/xiexianbin.cn.access.log;
    error_log   /var/log/tengine/xiexianbin.cn.error.log warn;
    location / {
        if ($http_host ~* ^(.*)-(.*).xiexianbin.cn(.*)) {
            set $jupyter_host  $1;
            set $jupyter_port  $2;
        }
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Credentials true;
        add_header Access-Control-Allow-Methods *;
        add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_pass http://$jupyter_host:$jupyter_port;
    }
}
