Skip to main content

Replacing nginx With CommandBox In ColdFusion Dev Environment

By Web Design6 min read

Many years ago, when I converted the local ColdFusion development site (for this blog) over to Docker, I started off by proxying my CFML container with an nginx container. I did this because I needed both URL rewriting and SSL certificates in order for my blog’s “search engine safe (SES) URLs” to work correctly. At the time, I didn’t know much about Docker or nginx or servers; but, I came across an article by George “Gavin” Pickin on how to use nginx to generate self-signed certificates and implement URL rewriting. So, that’s what I did.

In the years since, the Ortus Solutions team has continued to jam-out projects that support the ColdFusion community. And it seems that everything that I needed nginx for has since been rolled directly into the CommandBox Docker image.

And, as of this morning, I’m no longer using nginx locally! Simplification for the win!

predicate support now fully replaces my nginx container.

My docker-compose.yaml file no longer has an nginx service; and the existing cfml service now maps public ports 80 and 443 to internal ports:

services:

  # CFML website.
  cfml:
    build:
      context: "./cfml/docker/"
      dockerfile: "Dockerfile"
    ports:
      - "80:8080"
      - "443:8443" # SSL certificate provided via server.json
    volumes:
      - "./cfml/app:/app"

The SSL certificate and the URL rewriting is now handled by the server.json file, which is what CommandBox uses to setup the running container. The web.bindings entry sets up the SSL certificate (automagically) and the web.rules entry sets up the URL rewriting:

{
	"name": "bennadel-dev",
	"app": {
		"cfengine": "adobe@2025.0.7"
	},
	"profile": "development",
	"web": {
		"host": "127.0.0.1",
		"bindings": {
			"HTTP": {
				"enable": true,
				"listen": 8080
			},
			"SSL": {
				"enable": true,
				"listen": 8443
			}
		},
		"rules": [
			"not is-file and not is-directory -> rewrite('/index.cfm%U')"
		],
		"blockCFAdmin": false,
		"blockSensitivePaths": true,
		"blockFlashRemoting": true
	},
	"scripts": {
		"onServerInitialInstall": "cfpm install debugger,graphqlclient,image,mail,scheduler"
	}
}

In this case, the %U in the "rules" is the same as %{REQUEST_URL}, which maps to the Requested URL path.

And that’s all I needed! My CommandBox image has successfully collapsed my nginx service and my cfml service into a single service. Less complexity, more simplicity, maximum awesome!

Check out the license.


https://bennadel.com/4891


Source link