worker_processes 1;

events {
    worker_connections 1024;
}

http {
    include             mime.types;
    sendfile            on;

    default_type        application/octet-stream;

    keepalive_timeout   65;
    access_log          off;

    server {
        # Device Website

        listen          80;
        server_tokens   off;

        root /www/web;

        location / {
            index       index.html;
            expires     -1;
            add_header  X-Frame-Options deny;
        }

        # static asset caching
        location ~* \.(?:png|woff2|ico|json|css|js)$ {
            expires     max;
            add_header  Cache-Control "public";
        }

        # firmware upload
        location /webservice/upload/v2 {
            rewrite    /webservice/upload/v2 /api/upload break;
            proxy_pass http://127.0.0.1:1080;

            client_body_temp_path      /opt/userdata/nginx;
            client_body_in_file_only   on;
            client_body_buffer_size    1M;
            client_max_body_size       100M;

            proxy_pass_request_headers on;
            proxy_set_header           X-File-Name $request_body_file;
            proxy_set_body             off;
            proxy_redirect             off;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        # Webservice
        location /webservice {
            rewrite /webservice(.*) /api$1  break;
            proxy_pass         http://127.0.0.1:1080;
            proxy_http_version 1.1;
            proxy_redirect     off;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        # Datavisu
        location /datavisu {
            add_header  X-Frame-Options "";
        }

        # SPA Router Fallback
        error_page 404 =200 /index.html;
    }

    server {
        listen        443 ssl;
        server_tokens off;

        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
        ssl_prefer_server_ciphers on;
        ssl_certificate     /opt/extparam/device.crt;
        ssl_certificate_key /opt/extparam/device.key;

        root /www/web;

        include /etc/nginx/server443/*.conf;

        # Everything else proxy default http services
        location / {
            proxy_http_version 1.1;
            proxy_pass         http://127.0.0.1/;
        }
    }
}
