Meilisearch is a super fast search engine that's easy to self-host on your own infrastructure, avoiding the need for another Saas subscription.
If you're using Laravel Forge, setting up Meilisearch is super simple:
.env
to point at the private IP address of the Meilisearch server:MEILISEARCH_HOST=http://10.0.0.6:7700
MEILISEARCH_KEY=key_from_forge
MEILISEARCH_INDEX=your_application
You can then use something like Laravel Scout to push your Eloquent models into Meilisearch and everything "just works".
However, if you want to search Meilisearch directly from the frontend using something like instant-meilisearch
, you'll run into an issue: requests to the server's public IP address won't work.
There isn't really a straightforward way to fix it... you can't setup additional sites in order to connect a domain name.
However, there is a workaround...
If you can't connect directly to the Meilisearch server, you can connect via one of the servers in the same network.
search.yourdomain.com
.location
block with this:location / {
proxy_pass http://10.0.0.6:7700;
}
It'll tell Nginx that any requests to this site should be forwarded to the Meilisearch server. You should make sure Nginx is pointing to the server's private IP address.
Now, if you visit https://search.yourdomain.com
in a browser, you should get a successful response back.
For additional security, you may wish to configure CORS headers to prevent other websites sending requests to your Meilisearch server.