mail-in-a-box / mailinabox

Mail-in-a-Box helps individuals take back control of their email by defining a one-click, easy-to-deploy SMTP+everything else server: a mail server in a box.
https://mailinabox.email/
Creative Commons Zero v1.0 Universal
13.98k stars 1.44k forks source link

Allow configuration of web redirects #608

Open ariejan opened 8 years ago

ariejan commented 8 years ago

I have some domains that should redirect to others. Is this already possible, or would this be a feature request?

JoshData commented 8 years ago

There is an undocumented, unsupported feature:

https://github.com/mail-in-a-box/mailinabox/blob/master/management/web_update.py#L138

I would like to include this within the control panel some day.

yeah commented 7 years ago

FTR this feature can be used by creating a file called /home/user-data/www/custom.yaml with content like this:

my-domain.com:
  redirects:
    ^/foo: https://example.com/bar
  proxies:
    /baz: https://example.com/qux

The above example would result in nginx directives like this:

server {
  server_name my-domain.com;
  # ...
  rewrite ^/foo https://example.com/bar permanent;
  location /baz {
    proxy_pass https://example.com/qux;
  }
}

The relevant nginx docs are here:

The configuration must be regenerated/reloaded before this takes effect. You can do so by navigating to Web within the admin panel and clicking on any of the Change buttons or simply run sudo ~/mailinabox/tools/web_update.

da-code-a commented 7 years ago

Can you also include uWSGI proxies in this file?

bjmuld commented 6 years ago

hey guys... I'm having trouble with this feature.

# custom.yaml
sub.my-domain.com:
  redirects:
    ^/: http://www.yahoo.com

and running webupdate leaves me with a 301 redirect to the MIB box's root domain

lorrin commented 5 years ago

@bjmuld Try something like

sub.my-domain.com:
  redirects:
    ^.*: $scheme://www.yahoo.com$request_uri
lorrin commented 5 years ago

I have discovered that setting up a redirect like this blocks the verification step when provisioning a new Let's Encrypt certificate. Temporarily removing the redirect when provisioning the certificates does the trick.

Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator webroot, Installer None Performing the following challenges: http-01 challenge for my.other.domain http-01 challenge for my.domain Using the webroot path /home/user-data/ssl/lets_encrypt/webroot for all unmatched domains. Waiting for verification... Cleaning up challenges Failed authorization procedure. my.domain (http-01): urn:ietf:params:acme:error:unknownHost :: The server could not resolve a domain name :: No valid IP addresses found for my.domain IMPORTANT NOTES: - The following errors were reported by the server: Domain: my.domain Type: unknownHost Detail: No valid IP addresses found for my.domain To fix these errors, please make sure that your domain name was entered correctly and the DNS A/AAAA record(s) for that domain contain(s) the right IP address.

ghost commented 4 years ago

@bjmuld Try something like

sub.my-domain.com:
  redirects:
    ^.*: $scheme://www.yahoo.com$request_uri

I know this is an old issue, but I wanted to say. I got this to work pretty easily using the above.

custom.yaml

bjmuld commented 4 years ago

oddly, it's still not doing anything for me.... I have a custom dns entry: CNAME record pointing mail.mydomain.net to the mailinabox host I have a custom.yaml in /home/usr-data/www/ with the contents:

mail.mydomain.net:
  redirects:
    ^.*: https://www.yahoo.com

and ran web_update and restarted nginx service.... the result is nginx serving the default site at mail.mydomain.net

ghost commented 4 years ago

weird. I added the subdomain to mailinabox just like normal. got it to display the default website.

Then added custom.yaml under www directory. Updated the web service, and it forwarded no problem.

The original post was from two years ago, but i never knew i could do this.. been running mailinabox for my dns for years now.

ghost commented 4 years ago

sub.domain.com: redirects: ^/*: $scheme://newdomain.com

ghost commented 4 years ago

This worked for me no problem, but i had to create the subdomain in mailinabox first.

bjmuld commented 4 years ago

yeah, tried those contents exactly... grepping /etc/nginx doesn't return any results for sub.domain.com or my new subdomain or yahoo or newdomain. doesn't look like web_update is actually regenerating anything

ghost commented 4 years ago

you don't have to do anything in /etc/nginx..

just have mailinabox serve a valid page at your subdomain with a TLS cert. shows the default webpage.

Then go into your ..../www/ directory and create custom.yaml file with

sub.domain.com: redirects: ^/*: $scheme://newdomain.com/PAGE1/PAGE2

just put in your link.

and then

$sudo ~/mailinabox/tools/web_update

ghost commented 4 years ago

it takes a while little bit. and I restarted my server, then it just worked.

infidelus commented 3 years ago

Can't seem to get this working at all.

I've tried multiple variations but everything I do just redirects me to box.mydomain.co.uk.

I've created a placeholder file at /home/user-data/www/default/sub/index.html

I've created /home/user-data/www/custom.yaml and added:

#custom.yaml
sub.mydomain.co.uk:
  redirects:
    ^/*: $scheme://192.168.x.x/

Then run sudo ~/mailinabox/tools/web_update

I think I've also pretty much tried every variation of text listed above, but nothing changes. Stumped.

daveteu commented 3 years ago

anyone got this working?

i followed the instructions but nothing working.

I want to map my other email domains to the customdomain/mail directory

bjmuld commented 3 years ago

I could not.

On 12/9/20 2:02 AM, Dave wrote:

anyone got this working?

my web_update returns 500 error

|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 500 Internal Server Error

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

|

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mail-in-a-box/mailinabox/issues/608#issuecomment-741603860, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACWULT32HI6AVTOIKGJFVCDST4VIHANCNFSM4BVKBNZQ.

-- Barry Muldrey barry@muldrey.net mailto:barry@muldrey.net

ghost commented 3 years ago

I can do it.

Scott

On Dec 9, 2020, at 6:48 AM, Barry Muldrey notifications@github.com wrote:

 I could not.

On 12/9/20 2:02 AM, Dave wrote:

anyone got this working?

my web_update returns 500 error

|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 500 Internal Server Error

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

|

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mail-in-a-box/mailinabox/issues/608#issuecomment-741603860, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACWULT32HI6AVTOIKGJFVCDST4VIHANCNFSM4BVKBNZQ.

-- Barry Muldrey barry@muldrey.net mailto:barry@muldrey.net — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

bjmuld commented 3 years ago

Can you describe your setup? In my case, I'm making a new CNAME entry in the DNS (admin panel) called test.mydomain.net and pointing it to the mailinabox server.  Then I make /home/user-data/www/custom.yaml look like:

test.mydomain.net:
   redirects:
     ^/: https://www.google.com

then, I run sudo ~/mailinabox/tools/web_update

when I point a browser to https://test.mydomain.net, I get the mailinabox default page from /home/user-data/www/default

Can you describe your setup? Is it apparent what you're doing differently?

Thanks!

On 12/9/20 6:57 AM, Upkiik wrote:

I can do it.

Scott

On Dec 9, 2020, at 6:48 AM, Barry Muldrey notifications@github.com wrote:

 I could not.

On 12/9/20 2:02 AM, Dave wrote:

anyone got this working?

my web_update returns 500 error

|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 500 Internal Server Error

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

|

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub

https://github.com/mail-in-a-box/mailinabox/issues/608#issuecomment-741603860,

or unsubscribe

https://github.com/notifications/unsubscribe-auth/ACWULT32HI6AVTOIKGJFVCDST4VIHANCNFSM4BVKBNZQ.

-- Barry Muldrey barry@muldrey.net mailto:barry@muldrey.net — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mail-in-a-box/mailinabox/issues/608#issuecomment-741753402, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACWULT4I5HH4OHAQLEISXATST5X3XANCNFSM4BVKBNZQ.

-- Barry Muldrey barry@muldrey.net mailto:barry@muldrey.net

ghost commented 3 years ago

change a https to schema

Scott

On Dec 9, 2020, at 7:11 AM, Barry Muldrey notifications@github.com wrote:

 Can you describe your setup? In my case, I'm making a new CNAME entry in the DNS (admin panel) called test.mydomain.net and pointing it to the mailinabox server. Then I make /home/user-data/www/custom.yaml look like:

test.mydomain.net:
  redirects:
    ^/: https://www.google.com

then, I run sudo ~/mailinabox/tools/web_update

when I point a browser to https://test.mydomain.net, I get the mailinabox default page from /home/user-data/www/default

Can you describe your setup? Is it apparent what you're doing differently?

Thanks!

On 12/9/20 6:57 AM, Upkiik wrote:

I can do it.

Scott

On Dec 9, 2020, at 6:48 AM, Barry Muldrey notifications@github.com wrote:

 I could not.

On 12/9/20 2:02 AM, Dave wrote:

anyone got this working?

my web_update returns 500 error

|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 500 Internal Server Error

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

|

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub

https://github.com/mail-in-a-box/mailinabox/issues/608#issuecomment-741603860,

or unsubscribe

https://github.com/notifications/unsubscribe-auth/ACWULT32HI6AVTOIKGJFVCDST4VIHANCNFSM4BVKBNZQ.

-- Barry Muldrey barry@muldrey.net mailto:barry@muldrey.net — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mail-in-a-box/mailinabox/issues/608#issuecomment-741753402, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACWULT4I5HH4OHAQLEISXATST5X3XANCNFSM4BVKBNZQ.

-- Barry Muldrey barry@muldrey.net mailto:barry@muldrey.net — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

ghost commented 3 years ago

you create a new user noreply at subdomain. domain.com and then update the Yaml file. you don’t create a cname in mailinabox. all the dns is done automatically by creating the user with subdomain.

schema instead of https in the url redirect amd reload shoukd work

Scott

On Dec 9, 2020, at 7:11 AM, Barry Muldrey notifications@github.com wrote:

 Can you describe your setup? In my case, I'm making a new CNAME entry in the DNS (admin panel) called test.mydomain.net and pointing it to the mailinabox server. Then I make /home/user-data/www/custom.yaml look like:

test.mydomain.net:
  redirects:
    ^/: https://www.google.com

then, I run sudo ~/mailinabox/tools/web_update

when I point a browser to https://test.mydomain.net, I get the mailinabox default page from /home/user-data/www/default

Can you describe your setup? Is it apparent what you're doing differently?

Thanks!

On 12/9/20 6:57 AM, Upkiik wrote:

I can do it.

Scott

On Dec 9, 2020, at 6:48 AM, Barry Muldrey notifications@github.com wrote:

 I could not.

On 12/9/20 2:02 AM, Dave wrote:

anyone got this working?

my web_update returns 500 error

|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 500 Internal Server Error

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

|

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub

https://github.com/mail-in-a-box/mailinabox/issues/608#issuecomment-741603860,

or unsubscribe

https://github.com/notifications/unsubscribe-auth/ACWULT32HI6AVTOIKGJFVCDST4VIHANCNFSM4BVKBNZQ.

-- Barry Muldrey barry@muldrey.net mailto:barry@muldrey.net — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mail-in-a-box/mailinabox/issues/608#issuecomment-741753402, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACWULT4I5HH4OHAQLEISXATST5X3XANCNFSM4BVKBNZQ.

-- Barry Muldrey barry@muldrey.net mailto:barry@muldrey.net — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

bjmuld commented 3 years ago

So I was just playing around with this again, and now ~/mailinabox/tools/webupdate returns an error even if config.yaml is empty:

user@box:/home/user-data/www$ ~/mailinabox/tools/web_update

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
bjmuld commented 3 years ago

A little more info: There is a message on the system status page: But mailinabox is still serving the default page at www.mydomain.net... @upkiik: Do you have any custom DNS entries on the same domain you're using for your redirects?

iuvbio commented 3 years ago

Just to chime in here, for me this works fine as well. I want to redirect mail.mydomain.com to roundcube and box.mydomain.com to nextcloud. This is my custom.yaml in /home/user-data/www:

mail.mydomain.com:
    redirects:
        ^/$: https://mail.mydomain.com/mail

box.mydomain.com:
    redirects:
        ^/$: https://box.mydomain.com/cloud

After creating the file, I ran sudo ~/mailinabox/tools/web_update.

@bjmuld I have a custom DNS record, but just for TLS-RPT.

I also initially wasn't sure if I had to create the directories for the subdomains, so I created one for mail sub, but not for box, and both work fine (so creating the subdirectory is not necessary).

bjmuld commented 3 years ago

Fixed it. Of course it was a problem on my end. I had custom DNS entries that were clobbering the internal server. Removed them, created email domain aliases, and voila!

PeterSurda commented 3 years ago

Same problem as @bjmuld and same solution. Custom DNS record was the cause of the problem. After deleting email aliases and the DNS record, I created the alias afresh and the problem was solved.

MrTuffa commented 2 years ago

it is also possible to change the configuration entry : client_max_body_size 0;

via the custom_yaml for a proxy ?

brownj commented 2 years ago

it is also possible to change the configuration entry : client_max_body_size 0;

via the custom_yaml for a proxy ?

I've added client_max_body_size 2G; to my example.com.conf custom file to allow for larger uploads. I assume you could set it to 0 to disable the size checking (based the nginx documentation website).