#####################################
### someone"s ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2025 by someone <someone@somenet.org>
#
---
vhost_custom_pre_server: |-
    upstream backend {
        server localhost:8065;
        keepalive 32;
    }

vhost_custom: |-
    # MM-Hack: https://.../@user -> redirect to "default"-team and @user message
    #location ~ ^/@(.*)$ { return 301 /somenet/messages/$request_uri; }


    # websocket
    location ~ ^/api/v[0-9]+/(users/)?websocket$ {
        gzip on;
        gzip_types "*";
        gzip_proxied any;
        gzip_comp_level 5;
        proxy_set_header Accept-Encoding "";

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_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 $scheme;
        proxy_set_header X-Frame-Options SAMEORIGIN;
        proxy_connect_timeout 90;
        proxy_send_timeout 300;
        proxy_read_timeout 90s;
        proxy_http_version 1.1;
        proxy_buffers 256 16k;
        proxy_buffer_size 16k;
        client_max_body_size 50M;
        client_body_timeout 60;
        send_timeout 300;
        lingering_timeout 5;
        proxy_pass http://backend;
    }


    # api
    location ~ /api/ {
        if (-f /var/www/maintenance.html) {
            return 503;
        }

        gzip on;
        gzip_types "*";
        gzip_proxied any;
        gzip_comp_level 5;
        proxy_set_header Accept-Encoding "";

        proxy_set_header Connection "";
        proxy_set_header Host $http_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 $scheme;
        proxy_set_header X-Frame-Options SAMEORIGIN;
        proxy_read_timeout 600s;
        proxy_buffers 256 16k;
        proxy_buffer_size 16k;
        client_max_body_size 1024M;
        proxy_http_version 1.1;
        proxy_pass http://backend;
    }


    # static files + everything else
    location / {
        if (-f /var/www/maintenance.html) {
            return 503;
        }

        gzip on;
        gzip_types "*";
        gzip_proxied any;
        gzip_comp_level 5;
        proxy_set_header Accept-Encoding "";

        proxy_set_header Connection "";
        proxy_set_header Host $http_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 $scheme;
        proxy_set_header X-Frame-Options SAMEORIGIN;
        proxy_read_timeout 600s;
        proxy_buffers 256 16k;
        proxy_buffer_size 16k;
        client_max_body_size 1024M;
        proxy_http_version 1.1;
        proxy_pass http://backend;

        # <MM-Hack: make mm google-indexable (at least some pages)>
        sub_filter '<meta name="robots" content="noindex, nofollow">' '<meta name="robots" content="index, follow">';
        sub_filter '<title>Mattermost</title>' '<title>SomeNet Mattermost Chat</title>';
        sub_filter_last_modified on;
        sub_filter_once off;
        #sub_filter_types text/html;
        # </MM-Hack: make mm google-indexable (at least some pages)>
    }
