Craft CMS Multi-Site with Craft Nitro

Supporting a Craft multi-site installation with Craft Nitro requires using the `nitro alias` command.

Sup­port­ing a Craft mul­ti-site instal­la­tion with Craft Nitro relies sole­ly on the nitro alias command. 

The nitro alias com­mand allows you to choose an exist­ing site in your Nitro envi­ron­ment and then add a domain alias for it so any requests to that alias domain will be rout­ed to the main Craft installation. 

Craft mul­ti-site is a sin­gle Craft instal­la­tion and a sin­gle index.php in the web root that han­dles the request and boot­straps the application. 

Let’s set up a mul­ti-site instal­la­tion using the learnnitro project we cre­at­ed at the begin­ning of the course.

  1. Log in to the Con­trol Pan­el at learnnitro.nitro/admin
  2. Sites -> New Site
  3. Cre­ate new site called ​“Learn Dock­er”, https://learndocker.nitro (we’ll just hard code the URL into the set­tings field for now).
  4. Let’s copy the site han­dle so we can cre­ate a tem­plate fold­er for this site.
  5. In the templates direc­to­ry, cre­ate a direc­to­ry for learnDocker and one for default (the first/​primary created).
  6. Let’s cre­ate a sim­ple index tem­plate in each project. And place {{siteName}} at the top.

And now we can set up the alias in Nitro so an addi­tion­al domain points at the Dock­er con­tain­er for this project. Since we defined the Base URL in the Site Set­tings, Craft will route any requests via that Base URL to the cor­rect site.

		In the root of the main project:
➜ nitro alias

Enter the alias domain for learndocker.nitro with­out the protocol.

learndocker.nitro

Hit enter and then con­firm that you want to apply the changes. This updates Nitro so it can han­dle requests using that domain.

This is going to update our hosts file, so we’ll like­ly need to enter our password.

Now let’s try it out by vis­it­ing both domains!

Let’s update the learndocker.nitro index tem­plate just to con­firm that we’re point­ing at the right place.

And, we are!

Transcript

Premium

Follow along with the full transcript

Search every word, click any line to jump to that moment, and read along as you watch — a CraftQuest Premium feature.

Sign up for Premium
Instructor
Level
Beginner
Date Published
April 20, 2021