Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

ReverseProxy

Preston edited this page Dec 7, 2019 · 14 revisions

It's common usage that runinng Simple Torrent on a server together with other services. It's nice to let them share the same web port or even domain.

A front web server is needed, and some tweak config to let to let the real time event stream goes through.

Nginx

Nginx needs to hold a long connection to backend to keep the EventStream connected. The key tweak is that path /sync needed these 2 lines.

        proxy_set_header Connection '';
        proxy_http_version 1.1;

Full Example: Nginx with dedicated domain

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name your.domain.tld;
    ssl_certificate /usr/local/nginx/ssl/wildcard.crt;
    ssl_certificate_key /usr/local/nginx/ssl/wildcard.key;

    location / {
        proxy_pass http://127.0.0.1:3000;
    }

    location /sync {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Connection '';
        proxy_http_version 1.1;
        chunked_transfer_encoding off;
        proxy_buffering off;
        proxy_cache off;
    }
}

Full Example: Nginx with shared domain, under a directory

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name your.domain.tld;
    ssl_certificate /usr/local/nginx/ssl/wildcard.crt;
    ssl_certificate_key /usr/local/nginx/ssl/wildcard.key;

    location / {
        # your default site config
    }

    location /ctorrent/ {
        proxy_pass http://127.0.0.1:3000/; # note the trailing slash here, it matters!
    }

    location /ctorrent/sync {
        proxy_pass http://127.0.0.1:3000/sync;
        proxy_set_header Connection '';
        proxy_http_version 1.1;
        chunked_transfer_encoding off;
        proxy_buffering off;
        proxy_cache off;
    }
}

Caddy

Everything gets easy when it comes with caddy!

Full Example: Caddy with dedicated domain

https://your.domain.tld {
  proxy / http://127.0.0.1:3000 {
    transparent
  }
}

Full Example: Caddy with shared domain, under directory

https://your.domain.tld {

  #default site config
  root /srv/http
  browse

  proxy /ctorrent http://127.0.0.1:3000 {
    transparent
    without /ctorrent
  }
}
Clone this wiki locally