How to Install Meilisearch on Ubuntu 24.04 and Set It Up with Nginx

Setting Up Meilisearch on Ubuntu 24.04 with Nginx

If you’re building a search feature for your app or website and want something fast, lightweight, and open-source–Meilisearch might just become your new best friend. In this tutorial, I’ll guide you through the process of installing Meilisearch using Ubuntu 24.04 and setting it up using Nginx as reverse proxy. If you’re a solo developer or running your own server this guide will keep it easy and user-friendly.

Let’s take a dive!

What Is Meilisearch and Why Use It?

Meilisearch is an open-source extremely fast search engine that was designed to work with modern web applications. Imagine it as an alternative that is self-hosted to Algolia or Elasticsearch but much more simple to use.

This is why it’s amazing:

  • Fast search speed and typo tolerance
  • Uses RESTful API out of the box.
  • Small resources — not large Java or clustering configuration
  • Optional API key support to allow safe usage
  • Ideal for documentation, blogs apps, internal tools and even e-commerce

When you’re creating a catalog or a blog that can be searched, Meilisearch will get the job done in just a few seconds.

What You’ll Need (Prerequisites)

Before starting be sure to have these items ready:

  • A server that runs Ubuntu 24.04 (fresh or a previous version)
  • A sudo user or root access
  • Nginx is installed (sudo the apt-install the nginx)
  • Unzip and curl installed
  • (Optional) Domain name that points to your server

Step 1: Install Meilisearch on Ubuntu 24.04

Installing Meilisearch is a breeze because of the installer that is one-liner.

Install Using Curl

curl -L https://install.meilisearch.com | sh

The download will install the most recent Meilisearch binary to the current folder.

Move Binary to a Global Location

sudo mv meilisearch /usr/local/bin/

Make Sure It’s Working

Try to run:

meilisearch --help

If you can see Help alternatives, you can use Meilisearch. set to start.

Also read: How do you redirect output in Linux?

Step 2: Create a Systemd Service

Meilisearch should be running in the background and start automatically upon start-up. To achieve this, we need to create the systemd service.

Create the Service File

sudo nano /etc/systemd/system/meilisearch.service

Paste the following text:

[Unit]
Description=Meilisearch
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/meilisearch --master-key=MySuperSecretKey
Restart=always

[Install]
WantedBy=multi-user.target

Replace MySuperSecretKey with a private API code.

Enable and Start the Service

sudo systemctl daemon-reexec
sudo systemctl enable meilisearch
sudo systemctl start meilisearch

Check Status

sudo systemctl status meilisearch

If all went well the report should read “active (running)”.

Step 3: Set Up Nginx as a Reverse Proxy

In default Meilisearch operates on port 7700. We’ll configure Nginx to route requests coming from port 80 to Meilisearch.

Create a New Nginx Config

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

Copy this configuration:

server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass http://localhost:7700;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Replacing yourdomain.com with your real DNS name, or IP address of your server.

Enable the Site

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

Test Nginx and Restart

sudo nginx -t
sudo systemctl restart nginx

Now visiting http://yourdomain.com should show the Meilisearch welcome page.

4. (Optional) Securing It by using HTTPS with Certbot

Want HTTPS? Use Let’sEncrypt to get no cost SSL.

Install Certbot

sudo apt install certbot python3-certbot-nginx

Generate SSL Certificate

sudo certbot --nginx -d yourdomain.com

Certbot will modify your Nginx configuration and then reload the server.

Enable Auto-Renew

sudo systemctl enable certbot.timer

Boom! You’ve got HTTPS.

Step 5: Test Meilisearch

Let’s see if Meilisearch is running correctly.

Open in Browser

Go to http://yourdomain.com — you should see the Meilisearch welcome JSON.

Add an Index (Optional)

Let’s see if we can push data with curl.

Create Index:

curl -X POST 'http://yourdomain.com/indexes' \
-H 'X-Meili-API-Key: MySuperSecretKey' \
-H 'Content-Type: application/json' \
--data ''

Add Documents:

curl -X POST 'http://yourdomain.com/indexes/movies/documents' \
-H 'X-Meili-API-Key: MySuperSecretKey' \
-H 'Content-Type: application/json' \
--data '[
,
]'

Search:

curl 'http://yourdomain.com/indexes/movies/search' \
-H 'X-Meili-API-Key: MySuperSecretKey' \
--data ''

You’ll receive a speedy fuzzy match.

Final Tips and Best Practices

Here are a few things to remember:

  • Make sure you use API keys that are strong Change the master-key default to
  • Make sure you use HTTPS to prevent people from sniffing your API’s traffic
  • Secure with a firewall Block access to 7700 port from outside
  • The Basic Auth feature can be added to Nginx An additional layer of protection
  • Monitor the Service Utilize systemctl’s status meilisearch or logs

Conclusion

Let’s quickly recap:

  • You have installed Meilisearch in Ubuntu 24.04
  • You set up a service in the system to automatically start it
  • You utilized Nginx as a reverse proxy to port 7700.
  • (Optional) You have added HTTPS using Let’s Encrypt.
  • You tried curl on your test and confirmed that it worked!

Meilisearch is now available to provide lightning-fast search capabilities within your apps.

What’s next? Perhaps you can add a frontend, such as Meilisearch website, or incorporate it into the Laravel, React, or Next.js application.

Let me let me know in the comments if there is anything you would like to know about. assistance with one of them!

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *