map $host $cgit { default cgit; }
map $host $lam { default ldap-account-manager; }
map $host $kodi { default kodi.shore.co.il; }

server {
    listen              80 default_server;
    listen              [::]:80 default_server;
    server_name         www.shore.co.il;
    include             snippets/robots-allow-all.conf;
    include             snippets/ads-txt.conf;
    location = /        { return 301 https://$host/blog/; }
    location /repo/     {
        root            /var/www/www.shore.co.il/;
        autoindex       on;
    }
    location /          { return 301 https://$host$request_uri; }
}

server {
    listen                  443 ssl default_server;
    listen                  [::]:443 ssl default_server;
    server_name             www.shore.co.il;
    include                 snippets/robots-allow-all.conf;
    include                 snippets/ads-txt.conf;
    include                 snippets/ssl.conf;
    root                    /var/www/www.shore.co.il/;
    error_page 404          /;

    location /repo/         { autoindex on; }
    location = /resume      { try_files $uri /resume/resume.html; }
    location = /resume/     { index resume.html; }

    location = /            { return 301 https://$host/blog/; }
    location /about         { return 301 https://$host/blog/pages/about-me.html; }
    location /spam          { return 301 https://$host/blog/pages/spam.html; }
    location = /blog        {
        try_files $uri /blog/index.html;
        charset UTF-8;
    }

    location /cgit/ {
        proxy_pass          http://$cgit$uri;
        proxy_http_version  1.1;
        include             snippets/proxy-headers.conf;
    }

    location /git {
        rewrite             ^/git /cgit/;
    }

    location /git/ {
        rewrite             ^/git/(.*) /cgit/$1;
    }

    location /cgit-css/ {
        proxy_pass          http://$cgit$request_uri;
        proxy_http_version  1.1;
        include             snippets/proxy-headers.conf;
    }

    location /lam {
        proxy_pass          http://$lam$request_uri;
        proxy_http_version  1.1;
        include             snippets/proxy-headers.conf;
        include             snippets/allow-private-ips.conf;
    }

    location /jellyfin { return 302 $scheme://$host/jellyfin/; }
    location /jellyfin/ {
        proxy_pass          http://$kodi:8096/jellyfin/;
        proxy_http_version  1.1;
        include             snippets/proxy-headers.conf;
        include             snippets/common-headers.conf;

        proxy_set_header    Upgrade $http_upgrade;
        proxy_set_header    Connection $http_connection;

        # Disable buffering when the nginx proxy gets very resource heavy upon streaming
        proxy_buffering     off;
    }

    location /TRANSMISSION/ {
        proxy_pass http://kodi.shore.co.il:9091/;
        proxy_http_version 1.1;
        include             snippets/proxy-headers.conf;
    }
}
