Skip to content

Instantly share code, notes, and snippets.

@vaibhavpandeyvpz
Last active December 1, 2021 20:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaibhavpandeyvpz/08905e65e9f2270c329b1f5317018d89 to your computer and use it in GitHub Desktop.
Save vaibhavpandeyvpz/08905e65e9f2270c329b1f5317018d89 to your computer and use it in GitHub Desktop.
Running Metabase + Nginx + SSL on Ubuntu

First get Docker installed and setup on machine. Once installed, create a new user e.g., metabase for your installation using following command:

sudo adduser metabase

Now add the newly created user to docker group, you won't need sudo for docker ... commands:

sudo usermod -aG docker metabase

Let's change to our recently created metabase user and setup Metabase:

# switch to metabase user
su metabase

# start postgres server
docker run -d -p 5432:5432 \
  -e POSTGRES_DB=metabase \
  -e POSTGRES_PASSWORD=postgres \
  -v postgres-data:/var/lib/postgresql/data \
  --name postgres postgres

# start metabase server
docker run -d -p 3000:3000 \
  -e JAVA_TIMEZONE=UTC \ # change to whatever you like
  -e MB_DB_TYPE=postgres \
  -e MB_DB_DBNAME=metabase \
  -e MB_DB_PORT=5432 \
  -e MB_DB_USER=postgres \
  -e MB_DB_PASS=postgres \
  -e MB_DB_HOST=localhost \
  -v metabase-data:/metabase-data \
  --network=host \
  --name metabase metabase/metabase

Metabase should now be up and listening on port 3000. Let's setup Nginx to proxy from port 80 to 3000. Firstly, install Nginx using below command:

sudo apt install nginx

Now create a virtual host file using below command:

sudo nano /etc/nginx/sites-available/metabase

Then paste below contents and save it Ctrl+O and Ctrl+X:

server {
  listen 80;
  listen [::]:80;
  server_name mb.example.com;

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

Create a symlink for our virtual host in sites-enabled using below command:

sudo ln -s /etc/nginx/sites-available/metabase /etc/nginx/sites-enabled/metabase

Now restart Nginx for your changes to take effect:

sudo systemctl restart nginx

Optionally, you can install free Let's Encrypt SSL certificate using Certbot by using below commands as you wish:

# install certbot package
sudo apt install python3-certbot-nginx

# run and follow instructions
sudo certbot --nginx

Finished. You should now have a Metabase instance ready to bake some data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment