# How to safely change the Roundcube Webmail URL

**URL:** <https://discourse.mailinabox.email/t/how-to-safely-change-the-roundcube-webmail-url/16244>\
**Category:** Unsupported Modifications\
**Created:** [February 3, 2026, 12:31pm UTC](https://discourse.mailinabox.email/t/how-to-safely-change-the-roundcube-webmail-url/16244 "2026-02-03T12:31:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Winux](https://discourse.mailinabox.email/letter_avatar_proxy/v4/letter/w/cc9497/32.png) [@Winux](https://discourse.mailinabox.email/u/Winux)\
**Post date:** [February 3, 2026, 12:31pm UTC](https://discourse.mailinabox.email/t/how-to-safely-change-the-roundcube-webmail-url/16244/1 "2026-02-03T12:31:50Z")

</div>

Hi everyone,

I wanted to share a method I discovered for changing the default Roundcube webmail URL (e.g., moving it to the root domain `box.yourdomain.com/` or a different subpath like `/webmail/`) that is “safe” meaning it persists through Mail-in-a-Box updates and doesn’t involve hacking core system files and also secure if configured correctly.

This method builds on the information discussed in the [Is atleast being able to toggle PHP planned?](https://discourse.mailinabox.email/t/is-atleast-being-able-to-toggle-php-planned) thread. As noted there, while hosting PHP sites is not officially supported, we can utilize the `nginx_conf_custom_include` feature to inject custom Nginx configurations. By adding the necessary FastCGI parameters to these custom files, we can enable the PHP execution required for Roundcube to function at a new location.

### The Method

The trick is to place a custom configuration file in the `user-data` directory. Mail-in-a-Box automatically includes configurations found here into the Nginx server block for your domain.

1. SSH into your box.
2. Navigate to `/home/user-data/www/`.
3. Create a new configuration file named after your box’s hostname (e.g., `box.yourdomain.com.conf`).

Depending on what you want to achieve, paste one of the following code snippets into that file.

#### Option 1: Serve Webmail at Root ([box.yourdomain.com/](http://box.yourdomain.com/))

This configuration sets Roundcube as the index for the root of your box domain and redirects any requests from the old `/mail` path to the root.

```auto
# Roundcube Webmail configuration - Root Access

# If the request starts with /mail, redirect immediately to root
if ($request_uri ~* "^/mail(.*)") {
    return 301 /$1;
}

location / {
         index index.php;
         alias /usr/local/lib/roundcubemail/;
         client_max_body_size 128M;
}

location ~ /config/.* {
         # A ~-style location is needed to give this precedence over the next block.
         return 403;
}

location ~ ^/(?!\/)[^/]*\.php$ {
         # note: ~ has precedence over a regular location block
         include fastcgi_params;
         fastcgi_split_path_info ^(/.*)()$;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME /usr/local/lib/roundcubemail/$fastcgi_script_name;
         fastcgi_param PHP_ADMIN_VALUE "session.cookie_path=/";
         fastcgi_pass php-fpm;

         # Outgoing mail also goes through this endpoint, so increase the maximum
         # file upload limit to match the corresponding Postfix limit.
         client_max_body_size 128M;
}

```

#### Option 2: Serve Webmail at a subpath ([box.yourdomain.com/webmail/](http://box.yourdomain.com/webmail/))

This configuration serves Roundcube at `/webmail/` and redirects the old `/mail` path there.

```auto
# Roundcube Webmail configuration - /webmail/ path

# If the request starts with /mail, redirect immediately to /webmail
if ($request_uri ~* "^/mail(.*)") {
    return 301 /webmail$1;
}

location /webmail/ {
         index index.php;
         alias /usr/local/lib/roundcubemail/;
         client_max_body_size 128M;
}

location ~ /webmail/config/.* {
         # A ~-style location is needed to give this precedence over the next block.
         return 403;
}

location ~ /webmail/.*\.php {
         # note: ~ has precedence over a regular location block
         include fastcgi_params;
         fastcgi_split_path_info ^/webmail(/.*)()$;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME /usr/local/lib/roundcubemail/$fastcgi_script_name;
         fastcgi_param PHP_ADMIN_VALUE "session.cookie_path=/webmail/";
         fastcgi_pass php-fpm;

         # Outgoing mail also goes through this endpoint, so increase the maximum
         # file upload limit to match the corresponding Postfix limit.
         client_max_body_size 128M;
}

```

### Apply Changes

After creating the file, you need to trigger a web update to apply the Nginx changes:

Bash

```auto
sudo ~/mailinabox/tools/web_update

```

This should seamlessly switch your webmail URL while keeping the configuration safe in your `user-data` directory!
