# NGINX single file redirect on a single domain

**URL:** <https://discourse.mailinabox.email/t/nginx-single-file-redirect-on-a-single-domain/12471>\
**Category:** Maintenance\
**Created:** [November 24, 2024, 2:32am UTC](https://discourse.mailinabox.email/t/nginx-single-file-redirect-on-a-single-domain/12471 "2024-11-24T02:32:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikeintx](https://discourse.mailinabox.email/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@mikeintx](https://discourse.mailinabox.email/u/mikeintx)\
**Post date:** [November 24, 2024, 2:32am UTC](https://discourse.mailinabox.email/t/nginx-single-file-redirect-on-a-single-domain/12471/1 "2024-11-24T02:32:40Z")

</div>

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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![vele](https://discourse.mailinabox.email/letter_avatar_proxy/v4/letter/v/e5b9ba/32.png) [@vele](https://discourse.mailinabox.email/u/vele)\
**Post date:** [November 24, 2024, 12:06pm UTC](https://discourse.mailinabox.email/t/nginx-single-file-redirect-on-a-single-domain/12471/2 "2024-11-24T12:06:00Z")

</div>

Just redirect

> [@mikeintx](#):
>
> http(s)://mydomain.com/

to

> [@mikeintx](#):
>
> `some.otherhost.com/`

Go to MIAB Admin panel \>\> Custom DNS\>\> Make A record \>\> IPV4 of [some.otherhost.com](http://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.

---

<div class="post-metadata">

**Author:** ![mikeintx](https://discourse.mailinabox.email/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@mikeintx](https://discourse.mailinabox.email/u/mikeintx)\
**Post date:** [November 24, 2024, 4:29pm UTC](https://discourse.mailinabox.email/t/nginx-single-file-redirect-on-a-single-domain/12471/3 "2024-11-24T16:29:57Z")

</div>

Thank you!

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

> [@mikeintx](#):
>
> http(s)://mydomain.com/mydomainrss.xml

is what I’m trying to redirect. Not the entire domain. I don’t want to lose access to [mydomain.com/mail](http://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.

---

<div class="post-metadata">

**Author:** ![mikeintx](https://discourse.mailinabox.email/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@mikeintx](https://discourse.mailinabox.email/u/mikeintx)\
**Post date:** [November 24, 2024, 4:34pm UTC](https://discourse.mailinabox.email/t/nginx-single-file-redirect-on-a-single-domain/12471/4 "2024-11-24T16:34:15Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![vele](https://discourse.mailinabox.email/letter_avatar_proxy/v4/letter/v/e5b9ba/32.png) [@vele](https://discourse.mailinabox.email/u/vele)\
**Post date:** [November 24, 2024, 7:24pm UTC](https://discourse.mailinabox.email/t/nginx-single-file-redirect-on-a-single-domain/12471/5 "2024-11-24T19:24:23Z")

</div>

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](http://mydomian.com/mail)  
[box.mydomain.com/mail](http://box.mydomain.com/mail)  
[box.mydomain.com/cloud/contacts](http://box.mydomain.com/cloud/contacts)  
[box.mydomain.com/cloud/calendar](http://box.mydomain.com/cloud/calendar)  
[box.mydomain.com/cloud](http://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.

---

<div class="post-metadata">

**Author:** ![system](https://discourse.mailinabox.email/uploads/default/original/2X/4/4d0933d13c456b7e57f296aa6cc344525b6f0c70.png) [@system](https://discourse.mailinabox.email/u/system)\
**Post date:** [January 3, 2025, 7:25pm UTC](https://discourse.mailinabox.email/t/nginx-single-file-redirect-on-a-single-domain/12471/6 "2025-01-03T19:25:03Z")

</div>

This topic was automatically closed 40 days after the last reply. New replies are no longer allowed.
