I have created sveltekit/pocketbase project that I would like to deploy to Linode to run under subdomains:
backend.mydomain.com for pocketbase appname.mydomain.com for sveltekit
First I deployed pocketbase and I'm running it with systemd service which is working fine. But there's problem when I want to deploy and run sveltekit app. I was following this article on how to run svelte app on linode using pm2 and caddy. But there's problem because 443 address is already in use. When I turn off the pocketbase.service I can run my svelte app.
Now I know I should probably use reverse proxy for pocketbase, but I'm new in this and a bit lost in all the information. Any tips on how could I achieve this?
                        
You are right, you need a reverse proxy. I'm familiar with
nginxand so I will use that to answer your question. You are also right that you usesystemdto run your app in the background.I am assuming you are running your
pocketbaseat http://localhost:8001 and yoursveltekitat http://localhost:8002. Now, all you have to do is reverse proxy http://backend.mydomain.com to http://localhost:8001 and http://appname.mydomain.com to http://localhost:8002. Optionally, force https only. Both can be accomplished bynginxandcertbot.Install
nginxreading the documentation for your distro. Some distros enable thenginxsystemd service automatically, if yours does not, enablenginxwithThe config file will be found at
/etc/nginx/nginx.conf.Then add
serverunderhttpin thenginxconfig for both backend and the frontend. The config will look somewhat like this.Reload
nginx.nginxlooks at the http headers and matches it with theserver_nameand reverse proxies to the appropriate backends.Now, there is only one problem. Your site serves everything under http, which is not secure. Any modern site should upgrade http request at port 80 to https at port 443. We are lucky,
nginxcan do this and you don't even have to manually get certificates.LetsEncrypt is a non-profit organization, which gives ssl certificates for free and they have a easy to use bot which can automatically edit the
nginxconfig files for you.Install
certbotandcertbot-nginxfor your distro. The package names could vary.Point the domains of
backend.mydomain.comandappname.mydomain.comto the IP address of your linode machine. Use a service like https://www.whatsmydns.net/ to check if DNS has propagated. Now, runcertbot.and follow the instructions on screen.
certbotwill get the required certificates from letsencrypt, modify thenginxconfiguration to upgrade all requests to https.Reload
nginxagain.And congrats, you have deployed your sveltekit / pocketbase apps in a production ready way.