
In this tutorial, you will learn how to install and configure Supabase on Ubuntu 20.04. You will also learn how to secure your Supabase instance with secure secrets and a reverse proxy.
Supabase is a Firebase alternative that offers a PostgreSQL database, user authentication, storage, and a real-time API through a web interface. Supabase also has open-source API libraries that allow for easy interaction with other applications.
Before you begin, you should:
You will also need a domain name that points to your server. This is because the SSL certificate generator Certbot/Let's Encrypt) does not offer SSL certificates for IP addresses. You will need to create a domain name that points to your server. It is also possible to use HTTP instead, but this is not recommended.
Install Nginx and Git.
Uninstall any old versions of Certbot and Docker.
Update the snap installer.
Install Certbot using snap.
Run Certbot and follow the prompts to enter your domain name and redirect all traffic to HTTPS.
Take note of your certificate and private key paths when provided. It will be different depending on the domain used.
If you used a different SSL provider, ensure the certificate and private key files are stored somewhere on your system and that you know the full file path to them.
Install Docker using snap.
Clone the Supabase repository.
Open the docker folder.
Copy the .env.example file to .env.
Open the .env file in your text editor.
Open a strong password generator like Bitwarden in your browser, and generate a new password. It should contain more than 25 characters.
Replace the POSTGRES_PASSWORD value in the .env file with the password you generated.
Generate another password with more than 32 characters and no special characters. Replace the JWT_SECRET value in the .env file with the newly generated password.
Use your JWT_SECRET to generate an ANON_KEY on the Supabase website. Copy and paste your JWT_SECRET, switch the Preconfigured Payload type to ANON_KEY, press Generate JWT, and copy the Generated Token result into the ANON_KEY value in the .env file.
Do the same for the SERVICE_KEY value while using the same JWT_SECRET. Paste it as the SERVICE_ROLE_KEY value in the .env file.
Close your text editor and save your changes by using Control + X, then Y, followed by Enter.
Navigate to the volumes/api folder and open kong.yml in your text editor.
Under consumers, replace the anon user's key with the ANON_KEY value from the .env file.
Replace the service_role user's key with the SERVICE_ROLE_KEY value from the .env file.
Close your text editor again by using Control + X, then Y, followed by Enter.
Run Supabase by using docker-compose in detached mode. This may take 10-15 minutes.
Check that Supabase is running by using docker. The status should be Up.
You have now successfully installed Supabase and have obtained a signed SSL certificate.
You can now use your SSL certificate and Nginx to secure your Supabase installation. Make sure to replace example.com with your chosen domain name or IP address.
Remove the Nginx default configuration file.
Create and open the new configuration file in Nginx's sites-available directory in your text editor.
Paste the following into the file and replace example.com with your domain name or IP address. Ensure that the ssl_certificate and ssl_certificate_key lines point to your SSL certificate.
This Nginx configuration will serve Supabase on port 443, and will use the SSL certificate and private key you generated earlier. It will also point the /rest/v1/, /auth/v1/ and /realtime/v1/ routes to the Kong API server.
Exit your text editor and save changes by pressing Control + X, then Y, followed by Enter.
Create a link to the new configuration file in Nginx's sites-enabled directory.
Test the configuration file. If the test is successful, you will see the syntax is ok, and the test is successful messages.
Reload Nginx to apply your changes.
You should now navigate to your Supabase installation.
From there you can configure your database, authentication, and file storage.
Congratulations, you have successfully installed Supabase and secured it using an SSL certificate and an Nginx reverse proxy.
0 Comments
Be the first to comment and share your perspective with the community.