Skip to content

Hosting a space

Sidney San Martín edited this page Sep 24, 2020 · 2 revisions

I've been hosting spaces on Linux with nginx. This process could be improved!

  1. rsync your local repo, and a built copy of space, to the server. You'll do this when you make changes, too:

    (cd space/server && GOOS=linux GOARCH=amd64 go build -o ../../server.prod ./main) && rsync -av . --delete --exclude .git user@server:space/
    
  2. Make a systemd job to run space. Create this file as .config/systemd/user/space.service (you can also name it something else):

    [Unit]
    Description=Space!
    
    [Service]
    ExecStart=%h/space/server.prod -static ../../static/ -p
    WorkingDirectory=%h/space/space/server
    Restart=on-failure
    
    [Install]
    WantedBy=default.target
    

    Note that the -p flag in the systemd job disables automatic hot reloading. You can use the management UI instead; see below.

  3. Start the job: systemctl --user start space. If you want it to start at boot, use systemctl --user enable space. You might also need to run sudo loginctl enable-linger "$USER" so that your account's jobs start automatically.

  4. Install nginx, and configure it like this (by editing /etc/nginx/sites-available/default, or by creating a new file in that folder and symlinking it to /etc/nginx/sites-enabled/):

    server {
      server_name space.example.com;
    
      charset utf-8;
    
      location / {
              proxy_pass http://127.0.0.1:8031;
    
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection "Upgrade";
              proxy_set_header        X-Forwarded-For   $remote_addr;
              proxy_set_header        X-Real-IP         $remote_addr;
              proxy_set_header        Host              $host;
              proxy_read_timeout 900;
       }
    
      listen [::]:80 ipv6only=on;
      listen 80;
    }
    

    You might need to reload nginx's config with something like sudo systemctl reload nginx.

  5. For browsers to enable video, you'll need HTTPS. I'd use Let's Encrypt. Install certbot: sudo apt install python3-certbot-nginx. Then just run certbot and, when prompted, select to redirect all traffic to HTTPS. If you'd just like to enable HTTPS for Space, run certbot -d space.example.com instead. The certificate should get installed and renewed automatically going forward.

To manage the space, I'll generally forward the management server to my local machine over SSH, like this: ssh -L 8044:127.0.0.1:8034 user@server. Then visit http://127.0.0.1:8044 in a browser. You can use the buttons to reload just the renderer (i.e. static/party/index.html) or the whole site for everyone.

Clone this wiki locally