Two WordPress Admins on a Single Domain?

1. Output of caddy version:

v2.2.1 h1:Q62GWHMtztnvyRU+KPOpw6fNfeCD3SkwH7SfT1Tgt2c=

2. How I run Caddy:

Using Caddy to serve two reverse proxies to a single domain. We have two instances of WordPress: 1 is the main site and, 2 is a secondary instance used for a forum/community section that’s on the /townhouse subdirectory.

a. System environment:

  • DigitalOcean container app
  • Ubuntu 18.04.5 LTS
  • systemd 237

b. Command:

Currently used via a service — see: c.

c. Service/unit/compose file:

#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddy config:

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace the line below with your
# domain name.
dev.jerichowriters.com

# Set this path to your site's directory.
# root * /var/www/html

# Enable the static file server.
# file_server

# Another common task is to set up a reverse proxy:
encode gzip

handle /townhouse* {
	uri replace /townhouse/wp-content/ /wp-content/
	uri replace /townhouse/wp-includes/ /wp-includes/
	uri replace /townhouse/wp-admin/ /wp-admin/
	uri replace /townhouse/wp-login.php /wp-login.php

	reverse_proxy https://jwcommunity.wpengine.com {
		flush_interval -1
		header_up X-Real-IP {remote}
		header_up X-Forwarded-Proto {scheme}
		header_up Cache-Control "public, max-age=604800, must-revalidate, no-cache"
		header_up Host {upstream_hostport}
		header_up X-Forwarded-Host {host}
		header_down -server
	}
}

handle /tw-admin* {
	@prefix path_regexp prefix ^/tw-admin(.*)$
	rewrite * /wp-admin{re.prefix.1}

	reverse_proxy https://jwcommunity.wpengine.com {
		flush_interval -1
		header_up X-Real-IP {remote}
		header_up X-Forwarded-Proto {scheme}
		header_up Cache-Control "public, max-age=604800, must-revalidate, no-cache"
		header_up Host {upstream_hostport}
		header_up X-Forwarded-Host {host}
		header_down -server
	}
}

handle {
	reverse_proxy https://jerichodevelop.wpengine.com {
		header_up X-Real-IP {remote}
		header_up X-Forwarded-Proto {scheme}
		header_up Cache-Control "public, max-age=604800, must-revalidate, no-cache"
		header_up Host {upstream_hostport}
		header_up X-Forwarded-Host {remote}
		header_down -server
	}
}

# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

3. The problem I’m having:

We’re trying to rename one of the /wp-admin subdirectories to /tw-admin as visiting /townhouse/wp-admin redirects us back to the main site.

Alternatively we would be fine to setup a secondary subdomain as the admin for the /townhouse/wp-admin URL.

4. Error messages and/or full log output:

None

5. What I already tried:

  • Accessing the original jwcommunity.wpengine.com/wp-admin site but this redirects us back to the main site /wp-admin as we can only have one domain setup at WPEngine — hence the reverse proxies.
  • A uri replace for /townhouse/wp-admin. This will get us into the backend but the URL will change to /wp-admin immediately.
  • A rewrite on the /townhouse/wp-admin as well as the uri replace.
  • Both handle and handle_path for the /tw-admin directory. This is being used in tandem with some apply_filters on the WordPress install and we are redirected to the correct wp-login screen but upon logging in are redirected to /wp-admin and not /tw-admin. When we navigate to /tw-admin after, the login screen is just displayed again.

6. Links to relevant resources:

N/A

I strongly suggest using subdomains instead. Your config is much more complicated than it needs to be, and would be simplified by simply using subdomains for each part.

Remember that you need to use braces when using multiple site blocks in the Caddyfile. See the docs:

This is a very outdated version. Please update to v2.5.2. There have been many important fixes.

You don’t need these, Caddy sets the appropriate proxy headers automatically:

There’s no benefit whatsoever to removing the Server header.

Remove all this comment cruft from your config. It’s confusing to read because it’s not accurate to what your config is actually doing.

Thank you, I’ll clean things up, this is much appreciated!

I’ve contacted WPEngine support to see if we can setup a second domain there so it doesn’t redirect us away and will then setup the second subdomain for the admin.

I think you misunderstood. I mean you should use your own subdomain like townhouse.jerichowriters.com or whatever.

Got ya, thank you

This topic was automatically closed after 30 days. New replies are no longer allowed.