NGINX single file redirect on a single domain

I have hosted a podcast from my MIAB static file service. It’s great, but I’m moving the files to a commercial host. I receive mail to this domain and use the calendar and contacts. I cannot do a full redirect of the domain.

I’m trying to redirect a single file.

http(s)://mydomain.com/mydomainrss.xml to some.otherhost.com/mydomainrss

This is all that I want to achieve - 301 that request for domainrss.xml to the new host.

/home/user-data/www contains all of the site content directories for my domains, including mydomain.com. I created a file /home/user-data/www/mydomain.com.conf with the line:

rewrite ^(.*)/mydomainrss.xml some.otherhost.com/mydomainrss permanent;

My understanding is that this new mydomain.com.conf should NOT contain a sever block, but can contain a subset of directives that are normally found in an NGINX server block.

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

sudo /installlocation/mailinabox/tools/web_update

I then did sudo systemctl restart nginx and that results in an unexpected redirection to https://mydomain.com/some.otherhost.com/mydomainrss.

Thanks in advance for any advice.

Just redirect

to

Go to MIAB Admin panel >> Custom DNS>> Make A record >> IPV4 of some.otherhost.com.
Refrain from messing up the nginx config. MIAB is supposed to handle external hosts this way. I am not sure when your permanent redirect will expire now that it propagated. Even if you delete it. This is why a temp redirect is used.

Thank you!

However, I was thinking to only redirect a single file to the other domain:

is what I’m trying to redirect. Not the entire domain. I don’t want to lose access to mydomain.com/mail to access web mail on the MIAB host.

My understanding is that the mydomain.com.conf file in the /home/user-data/www is a supported feature, but is not documented.

Here’s what I ended up doing:

in /home/user-data/www, I created a new file mydomain.com.conf containing a single location block:

location / {
            return 302 https://some.otherdomain.com/mydomain;
}

After things settle a bit, I’ll change that from 302 to 301 to change it from a temporary to permanent redirection.

I checked to see if I can reach mydomain.com/mail, and by some MIAB magic, I believe, I can still reach the webmail.

That’s all I need!

– Mike

OK. But this is not the way to do it.
The Custum DNS A record redirects only the domain you host on MIAB Admin Page>> Web.

mydomian.com/mail
box.mydomain.com/mail
box.mydomain.com/cloud/contacts
box.mydomain.com/cloud/calendar
box.mydomain.com/cloud
All these will not redirect and will be accessible with the A record.

Please note that with the automatic Certificate renewal and provisioning Let’s Encrypt when it hits the redirect will not provision or renew the certificate on the other host. You must provision the https certificate on the other host yourself manually, depending on the other host setup.