hifi / heisenbridge

a bouncer-style Matrix IRC bridge
MIT License
244 stars 34 forks source link

Add ability to configure the media path for reverse proxies #267

Closed hashworks closed 1 year ago

hashworks commented 1 year ago

Resolves #266.

Includes #238.

img-2023-09-25-194456

img-2023-09-25-194514

Nginx config used in the example above:

upstream synapse {
  server 127.0.0.1:8008;
  keepalive 20;
}

map $upstream_http_content_type $matrix_media {
    "text/plain"            "inline";
    "text/css"              "inline";

    "application/pdf"       "inline";

    "image/gif"             "inline";
    "image/jpeg"            "inline";
    "image/avif"            "inline";
    "image/png"             "inline";
    "image/tiff"            "inline";
    "image/vnd.wap.wbmp"    "inline";
    "image/webp"            "inline";
    "image/x-icon"          "inline";
    "image/x-jng"           "inline";
    "image/x-ms-bmp"        "inline";

    "audio/basic"           "inline";
    "audio/midi"            "inline";
    "audio/mpeg"            "inline";
    "audio/ogg"             "inline";
    "audio/x-m4a"           "inline";
    "audio/x-realaudio"     "inline";

    "video/3gpp"            "inline";
    "video/mp2t"            "inline";
    "video/mp4"             "inline";
    "video/mpeg"            "inline";
    "video/quicktime"       "inline";
    "video/webm"            "inline";
    "video/x-flv"           "inline";
    "video/x-m4v"           "inline";
    "video/x-matroska"      "inline";
    "video/x-mng"           "inline";
    "video/x-ms-asf"        "inline";
    "video/x-ms-wmv"        "inline";
    "video/x-msvideo"       "inline";

    default                 "attachement";
}

server {
  listen       *:443 ssl http2;
  listen       [::]:443 ssl http2 ;

  server_name  irc.hash.works;

  ssl_certificate           /etc/letsencrypt/live/irc.hash.works/fullchain.pem;
  ssl_certificate_key       /etc/letsencrypt/live/irc.hash.works/privkey.pem;

  location / {
    proxy_pass            http://synapse/_matrix/media/v3/download/kromlinger.eu/;
    proxy_http_version    1.1;
    proxy_set_header      Host $http_host;
    proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header      X-Forwarded-Proto $scheme;

    proxy_hide_header Content-Disposition;
    add_header Content-Disposition $matrix_media;
  }
}
hifi commented 1 year ago

LGTM!