How to Serve ColdFusion through Nginx on macOS (Using Laravel Herd)

Why Would You Need to Do This?

Chris Jones
3 min readJun 26, 2024

Setting up ColdFusion on a Mac can be tricky, especially when most tutorials require running an Apache server. As a Laravel developer, I prefer to use Laravel Herd for PHP development and wanted to avoid conflicts.

This tutorial will guide you on how to use Laravel Herd to serve ColdFusion pages locally.

Prerequisites

  • Laravel Herd (or standalone Nginx)
  • Basic knowledge of Nginx and ColdFusion

Step 1: Installing ColdFusion

Download the Installer:

Download the ColdFusion installer (Mac — GUI) from the Adobe website and then mount the DMG.

Bypass System Security:

Go to System Preferences > Privacy & Security and add the installer to the Developer Tools section.

Screenshot showing steps required to bypass macOS System Security.

Run the Installer:

Run the installer and select the Development server configuration. Leave all other settings at their defaults.

Post-Installation Cleanup:

Remove the installer from the Developer Tools section and unmount the DMG.

Step 2: Configuring Nginx with Laravel Herd

For this setup we are going to be running Nginx through Laravel Herd. However, the configuration should be mostly the same if you are running Nginx another way (e.g., through Homebrew).

Herd stores the main Nginx configuration in the following location:
~/Library/Application Support/Herd/config/nginx/herd.conf

Let’s edit this file to allow our server to proxy requests for .cfm files to ColdFusion. Add the following to the end of the server {} declaration.

server {
# ... snip ...

location ~ \.(cfm|cfml|cfc)$ {
set $subdomain "";
if ($host ~* "^([^.]+)\.test$") {
set $subdomain $1;
}
proxy_pass http://127.0.0.1:8500/$subdomain$request_uri;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

This change allows us to continue using Herd’s awesome Sites feature which allows us to access sites locally using <directory-name>.test domain.

Step 3: Configuring ColdFusion

The last step for us is to update the ColdFusion configuration to enable virtual directories for the paths we would like Nginx to serve.

For this we will need to edit the ColdFusion server.xml file located here:
/Applications/ColdFusion2023/cfusion/runtime/conf/server.xml

We need to uncomment the <Context /> block and add each of our Herd virtual sites as <PreResources /> . Here is an example of what that would look like:

<Server ...>
<Service ...>
<Engine ...>
<Host ...>
<!-- Start here -->
<Context path="" docBase="/Applications/ColdFusion2023/cfusion/wwwroot" WorkDir="/Applications/ColdFusion2023/cfusion/runtime/conf/Catalina/localhost/tmp">
<Resources>
<PreResources base="/Users/{user}/Sites/{example}" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/{example}"/>
</Resources>
</Context>
<!-- End -->
</Host>
</Engine>
</Service>
</Server>

Note: Be sure to change {user} to your macOS user and {example} to your Herd virtual site.

Step 4: Restart Services

After making configuration changes, it is necessary to restart both Nginx and ColdFusion servers.

Restart ColdFusion:

sudo /Applications/ColdFusion2023/cfusion/bin/coldfusion restart

Restart Herd using the Stop all/Start all menu items:

Screenshot showing the Laravel Herd menu dropdown.

Conclusion

By following these steps, you can successfully serve ColdFusion pages through Nginx on macOS using Laravel Herd. This approach allows you to maintain your existing PHP development environment without conflicts. Enjoy seamless development with both PHP and ColdFusion on your Mac!

--

--

Chris Jones
Chris Jones

Written by Chris Jones

Web developer with a passion for #html, #css, #js and a preference for #php and #laravel. I also have a small obsession with #devops and shell scripting.

No responses yet