Help: Serving SilverBullet.md using Nginx

Hi all!
I’m pretty new to this project and I’m very excited about it.
Right now my main obstacle is that I want to run SB on my existing server that serves other projects of mine using Nginx.
Setting up the reverse proxy was pretty easy, however I’m having trouble directing all of the subsequent requests to the same single endpoint. The server just looks for these files as static files and can’t find them an so I get 404 responses.
After examining these failing requests I notices they are directed either to /.client/... or !silverbullet.md/.... It’s pretty hacky but I tried adding these paths to my Nginx config and I saw partial success.
All requests resolved successfully except for one: https://my-domain.com/.client/client.js. Does anyone have any idea about how I can make this work? Or is there a less hacky way to go about it?

For reference, this is the relevant chunk of Nginx config:

        location /sb {
                proxy_pass       http://127.0.0.1:8080/;
                add_header Cache-Control no-cache;
                expires 0;
        }

        location /.client {
                proxy_pass       http://127.0.0.1:8080/;
                add_header Cache-Control no-cache;
                expires 0;
        }

        location /!silverbullet.md {
                proxy_pass       http://127.0.0.1:8080/;
                add_header Cache-Control no-cache;
                expires 0;
        }

I’m serving it on https://my-domain.com/sb.
Cache configuration on these might not be necessary.

Thanks in advance! Any help would be appreciated.

Did you try serving it on a subdomain like https://sb.my-domain.com/?

It looks like SB expects to be served on the domain root.

To confirm: SilverBullet needs to be served at the root otherwise it won’t work. Until this lands: Feature: URL base/URL subpath support by Shihira · Pull Request #1131 · silverbulletmd/silverbullet · GitHub

1 Like

Thank you so much for the tips! I managed to get this working :slightly_smiling_face:
For the sake of documenting, this is the working relevant chunk of Nginx config:

server {
        server_tokens off;

        server_name sb.my-domain.com;
        location / {
                proxy_set_header Host $host;
                proxy_pass       http://127.0.0.1:8080;
                proxy_set_header Host $host;
                proxy_redirect off;
                add_header Cache-Control no-cache;
                expires 0;
        }
}

Again, not everything there strictly necessary.
Importantly, I also had to register a new DNS record for this new subdomain through my hosting provider.

Do you feel like there’s reason to add a guide page for serving with Nginx to the official documentation? If so I’ll be happy to write an explanation with cleaner config example and make a pull request.

Is this config works still?

I am trying it and not working. Also why it is set t port 8080? isn’t it on port 3000?

P.S.: I figured it out.
changing
proxy_set_header Host $host;
to
proxy_set_header Host localhost;
makes it work

1 Like

Glad to hear it worked, and thanks for adding what worked for you.
In my case my server already has a process serving on port 3000 so I had to change it for SB through the command line parameters and in the Nginx config.

1 Like