pid ${root}/nginx.pid;
daemon off;

error_log /dev/stderr warn;

events {}
http {
    include /etc/nginx/mime.types;
    client_body_temp_path /tmp/nginx;
    proxy_temp_path /tmp/nginx;

    gzip on;
    gzip_vary on;
    gzip_min_length 100;

    gzip_types *;
    upstream django {
        server 127.0.0.1:${DJANGO_PORT} fail_timeout=0;
    }
    # upstream mqtt {
    #     server 127.0.0.1:${MQTT_WEBSOCKET_PORT} fail_timeout=0;
    # }
    upstream vue {
        server 127.0.0.1:${VUE_PORT} fail_timeout=0;
    }


    # server {
    #     access_log /dev/stdout;
    #     charset utf-8;
    #     listen 127.0.0.1:${DJANGO_PORT};
    #     location / {
    #         client_max_body_size 10M;
    #         # we don't want nginx trying to do something clever with
    #         # redirects, we set the Host: header above already.
    #         proxy_pass http://django;
    #         proxy_redirect off;
    #         proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for;
    #         proxy_set_header X-Forwarded-Proto ${DOLLAR}scheme;
    #         proxy_set_header Host ${DOLLAR}http_host;
    #     }
    # }
    server {
        access_log /dev/stdout;
        #root /vue/dist;
        listen ${EVERYTHING_LISTEN}:${DBG_PORT};
        charset utf-8;

        
        # location = /django_auth {
        #     internal;
        #     proxy_pass http://django/auth/is_authorized/;
        #     proxy_pass_request_body off;
        #     proxy_set_header Content-Length "";
        #     proxy_set_header Host ${DOLLAR}http_host;
        #     proxy_set_header X-Original-URI ${DOLLAR}request_uri;
        # }

        location /frontend/ {
            # auth_request /django_auth;
            # error_page 403 = @error403;
            proxy_pass http://vue/;
            proxy_redirect off;
            proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto ${DOLLAR}scheme;
            proxy_set_header Host ${DOLLAR}http_host;
        }
        location /sockjs-node/ {
            proxy_pass http://vue;
            proxy_http_version 1.1;
            proxy_set_header Upgrade ${DOLLAR}http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto ${DOLLAR}scheme;
            proxy_set_header Host ${DOLLAR}http_host;
            proxy_read_timeout 3600s;
        }
        # location /backend/static/ {
        #     proxy_pass http://django/static/;
        #     proxy_set_header Host ${DOLLAR}http_host;
        #     proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for;
        # }
        location / {
            client_max_body_size 10M;
            proxy_pass http://django/;
            # set ${DOLLAR}sc_name ${DOLLAR}http_x_script_name/backend;
            # proxy_set_header X-Script-Name ${DOLLAR}sc_name;
            proxy_redirect off;
            proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto ${DOLLAR}scheme;
            proxy_set_header Host ${DOLLAR}http_host;
        }
        location /ws/ {
            # we don't want nginx trying to do something clever with
            # redirects, we set the Host: header above already.
            proxy_pass http://django/ws/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade ${DOLLAR}http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto ${DOLLAR}scheme;
            proxy_set_header Host ${DOLLAR}http_host;
            proxy_read_timeout 3600s;
        }
        location /${MEDIA_URL} {
            # auth_request /django_auth;
            # error_page 403 = @error403;
            alias ${MEDIA_ROOT};
        }

        location @error403 {
            absolute_redirect off;
            return 302 /;
        }

    }
}