How To Setup Metabase with Nginx and Ubuntu

Nginx Installation

Step 1: Install Nginx

sudo apt-get install nginx

Step 2: Check Status

sudo systemctl status nginx

Install Java

sudo apt install default-jre

Check Java Version

java -version

Output:

openjdk version "17.0.10" 2024-01-16
OpenJDK Runtime Environment (build 17.0.10+7-Ubuntu-123.10.1)
OpenJDK 64-Bit Server VM (build 17.0.10+7-Ubuntu-123.10.1, mixed mode, sharing)

Metabase Installation and Configuration

Step 1: Update packages:

sudo apt update -y && sudo apt upgrade -y

Step 2: Download Metabase

Make sure to move this file to /var/www/html/metabase

wget https://downloads.metabase.com/v0.48.8/metabase.jar

Step 3: Create user & group

sudo groupadd -r metabase
sudo useradd -r -s /bin/false -g metabase metabase

Step 4: Create folder and set permissions

sudo mkdir /var/www/html/metabase
sudo chown -R metabase:metabase /var/www/html/metabase

Step 5: Create log file and set permissions

sudo touch /var/log/metabase.log
sudo chown syslog:adm /var/log/metabase.log

Step 6: Create metabase configuration file and set permissions

sudo touch /etc/default/metabase
sudo chmod 640 /etc/default/metabase

Step 7: Create a Metabase Service

sudo touch /etc/systemd/system/metabase.service
sudo vi /etc/systemd/system/metabase.service

Copy and Paste below content in metabase.service

[Unit]
Description=Metabase server
After=syslog.target
After=network.target

[Service]
WorkingDirectory=/var/www/html/metabase
ExecStart=/usr/bin/java -jar /var/www/html/metabase/metabase.jar
EnvironmentFile=/etc/default/metabase
User=metabase
Type=simple
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=metabase
SuccessExitStatus=143
TimeoutStopSec=120
Restart=always

[Install]
WantedBy=multi-user.target

Step 8: Create Syslog Config

sudo touch /etc/rsyslog.d/metabase.conf
sudo vi /etc/rsyslog.d/metabase.conf

Add following code in metabase.conf

if $programname == 'metabase' then /var/log/metabase.log
& stop

Restart the syslog service to apply new changes

sudo systemctl restart rsyslog.service

Step 9: Create environment variables

sudo vi /etc/default/metabase

Add the following content and save

NOTE: This tutorial assumes you have PostgreSQL setup. Below configurations are required for Metabase to create its own tables and configuration in PostgreSQL DB.

MB_PASSWORD_COMPLEXITY=strong
MB_PASSWORD_LENGTH=10
#MB_JETTY_HOST=<0.0.0.0>
#MB_JETTY_PORT=<12345>
MB_DB_TYPE=postgres
MB_DB_DBNAME=<your_metabase_db_name>
MB_DB_PORT=<5432>
MB_DB_USER=<your_metabase_db_user>
MB_DB_PASS=<ssshhhh>
MB_DB_HOST=<localhost>
MB_EMOJI_IN_LOGS=false
# any other env vars you want available to Metabase

Step 10: Move Metabase jar file

sudo mv ~/metabase.jar /var/www/html/metabase
sudo chown -R metabase:metabase metabase.jar

Nginx configuration

Create nginx conf for metabase

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

Copy and paste below content and save the file

server {
  listen 80;
  listen [::]:80;
  server_name your.domain.com;
  location / {
    proxy_pass http://127.0.0.1:3000;
  }
}

Create a symbolic link

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

Check for configuration

sudo nginx -t

Reload Nginx configuration

sudo systemctl reload nginx

Restart Metabase Service

sudo systemctl daemon-reload
sudo systemctl start metabase.service
sudo systemctl status metabase.service

Enable Metabase service on reboot

sudo systemctl enable metabase.service

Thats it! you have successfully configured metabase with nginx on Ubuntu server.

Next, I would recommend configuring LetsEncrypt SSL to secure Metabase over secure HTTPS connection. Follow this guide on how to setup SSL for Metabase.

Scroll to Top