server {
    listen %%interface%%:%%port%% default_server;
    include /etc/nginx/includes/server_params.conf;
    include /etc/nginx/includes/proxy_params.conf;

    proxy_buffering off;
    auth_basic_user_file /home/pi/.htpasswd;

    location / {
      # Proxy pass
      proxy_pass http://localhost:8082;

      # Next three lines allow websockets
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      # Adjust any Location headers in backend redirects
      absolute_redirect off;
      proxy_redirect /stats %%ingress_entry%%/stats;
      proxy_redirect /log %%ingress_entry%%/log;
      proxy_redirect /terminal %%ingress_entry%%/terminal;

      # Correct base_url
      proxy_set_header Accept-Encoding "";
      sub_filter_once off;
      sub_filter_types *;
      sub_filter /spectrogram %%ingress_entry%%/spectrogram;
      sub_filter /By_Date/ %%ingress_entry%%/By_Date/;
      sub_filter /Charts/ %%ingress_entry%%/Charts/;
      sub_filter /stats/ %%ingress_entry%%/stats/;
      sub_filter /log/ %%ingress_entry%%/log/;
      sub_filter /terminal/ %%ingress_entry%%/terminal/;
      sub_filter "url = '/" "url = '%%ingress_entry%%/";
      sub_filter /todays %%ingress_entry%%/todays;
      sub_filter href=\"/ href=\"%%ingress_entry%%/;
      sub_filter src=\"/ src=\"%%ingress_entry%%/;
      sub_filter hx-get=\"/ hx-get=\"%%ingress_entry%%/;
      sub_filter action=\"/ action=\"%%ingress_entry%%/;
      }
}
