Tim Habersack

Where I put my things..

Setting up Laradock for multiple projects with Nginx

Jun 7th 2020

Laradock is a handy tool. Basically it has a ton of pre-configured docker containers, and you can pick and choose for the dev environment you need. However, every time I set up laradock on a new system I forget how to set up the directories and configure nginx to properly serve them up.

For example, assume directory structure like:


The default env-example (that you copy and rename to .env) has this info at the top:


This means laradock thinks anything in the directory above it is data it should access. Within containers, /var/www points to the host o/s ../, the directory that the laradock directory sits in.

So! When configuring laradocks nginx to have multiple sites, you just point the root accordingly.

For example, assume directory structure like:


In the laradock/nginx/sites directory, you'd cp default.conf project_1.conf. (Or anything, the name of the conf file doesn't matter). Edit the project_1.conf like so:

server_name project_1.test;
root /var/www/project_1;

Now (assuming you've altered your /etc/hosts to have project_1.test), when laradock/nginx serves up the project1 site, it will look at your project1 directory for the content!

Let's say project_2 has a structure in it like:


You'd want nginx to serve up the project_2/public directory.

server_name project_2.test;
root /var/www/project_2/public;

This always trips me up and costs me a little time. Hopefully I'll remember it for next time, and also maybe it will help others.

#laradock #nginx #docker