Roots Discourse

Nginx url rewrites WPML multi domains

Hi there,

We’re currently re-doing an existing WPML multi-domain (for every language a separate domain) website to Trellis and I would like to add 301 redirects for old post slugs to new posts/pages.

In my /group_vars/production/wordpress_sites.yml I added the domains like this:

wordpress_sites:
  main-domain.nl:
    site_hosts:
      - canonical: main-domain.nl
        redirects:
          - www.main-domain.nl
          - english-domain.eu
          - www.english-domain.eu
          - german-domain.de
          - www.german-domain.de

I want to target every domain for a different set of rewrites so I included the file:
nginx-includes/main-domain.nl/rewrites.conf.j2

with something like this:

# Main Domain
server {
	server_name main-domain.nl *.main-domain.nl main-domain.test;

	rewrite ^/some-old-page-slug/?$ https://main-domain.nl/some-new-page-slug permanent;
	# ... etc

	location ~ ^/post-slug-1|post-slug-2/(.*)$ {
		rewrite https://main-domain.nl/new-page/ permanent;
	}
}

# English Domain
server {
	server_name english-domain.eu *.english-domain.eu english-domain.test;

	rewrite ^/some-old-page-slug/?$ https://english-domain.eu/some-new-page-slug permanent;
	# ... etc

	location ~ ^/post-slug-1|post-slug-2/(.*)$ {
		rewrite https://english-domain.eu/new-page/ permanent;
	}
}

# German Domain
server {
	server_name german-domain.de *.german-domain.de german-domain.test;

	rewrite ^/some-old-page-slug/?$ https://german-domain.de/some-new-page-slug permanent;
	# ... etc

	location ~ ^/post-slug-1|post-slug-2/(.*)$ {
		rewrite https://german-domain.de/new-page/ permanent;
	}
}

When I re-provision locally I get an error:
nginx: [emerg] "server" directive is not allowed here

Should I make a folder for each domain in nginx-includes per language instead and add the rewrites in there? I thought the folder name represents the wordpress site_name and not the redirects?

If so, how could I test my rewrites locally since I only have my main-domain.test added in /group_vars/development/wordpress_sites.yml?

If not, how else can I target the redirects domains in my rewrites.conf.j2?
Thanks a lot!

Should I use a child template of roles/wordpress-setup/templates/wordpress-site.conf.j2 and overwrite the {%- block redirects_domains %} block so I can use something like this:

server {
  {% if ssl_enabled -%}
  listen [::]:443 ssl http2;
  listen 443 ssl http2;
  {% endif -%}
  listen [::]:80;
  listen 80;
  server_name main-domain.nl *.main-domain.nl main-domain.test;

  rewrite ^/some-old-page-slug/?$ https://main-domain.nl/some-new-page-slug permanent;
  # ... etc

  location ~ ^/(post-slug-1|post-slug-2)/(.*)$ {
    rewrite https://main-domain.nl/new-page/ permanent;
  }
}

That doesn’t seem to work either…
Any help would be appreciated, thanks!