Roots Discourse

Proxy a separate domain to a single page

I’m currently using Trellis to serve a WP instance on domain1.com. I want domain2.com to proxy to a single page on domain1.com/page, so without any redirections. I’ve found a WP plugin that’s supposed to do this:

But I have trouble instructing Trellis to achieve this. I’ve come up with the following definitions in wordpress_sites.yml:

wordpress_sites:
  domain1.com:
    site_hosts:
      - canonical: domain1.com
        redirects:
          - www.domain1.com
      - canonical: domain2.com
        redirects:
          - www.domain2.com

This correctly links the complete domain2.com to domain1.com, without any redirections. I can access the same content on both sites. This is bad for SEO though, and I want to only use domain2.com for a single domain1.com/page.

I’ve tried using the plugin above in combination with this, but that doesn’t seem to have any effect.

I’ve also tried to disable the plugin and use NGINX config instead. I’ve put this file into the folder nginx-includes/domain2.com:

server {
	listen 80;
	listen [::]:80;
	server_name domain2.com;

	location / {
		proxy_redirect off;
		proxy_set_header Host $http_host;
		proxy_set_header X-Forwarded-Host $http_host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

		proxy_pass https://domain1.com/page/;
	}
}

This doesn’t seem to do anything either.

I’ve seen separate topics on this forum asking for the same setup, but without any solutions.

It looks like this isn’t possible to achieve with Trellis alone. Any ideas?

2 Likes

Doesn’t the canonical link in the head take care of the double content SEO problem? With Yoast I think you can set the canonical url per page.

The nginx-includes folder should match your site name in wordpress_sites, in this case domain1.com, so that explains the not working redirect

Indeed, it looks like Yoast handles that by setting the default canonical url to the WP permalink, so the duplicate content is OK.

I’ve tried putting the NGINX redirect under domain1.com before, but then it complains about the server directive not being allowed in that place. But I do think I need to listen to the server directive, as I only need to proxy for server_name domain2.com

Then you need to make a child template file if you want to use the server block: https://roots.io/trellis/docs/nginx-includes/

Yeah, that’s a good pointer. I’ve dived deep into nginx-includes and have something half-working. But I’m also running into bugs causing double request headers, and unreliable requests (every other request fails). Either I just don’t understand it or Trellis isn’t made for this thing. It feels like I’m going against the principles of Trellis.

Nobody on this forum seems to have made it work yet: pointing a single domain to a page on another domain. Maybe this is just too complicated for Trellis?