1

Topic: Using Nginx to host websites on the same server as iRedMail

==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====
- iRedMail version: 14.2.1
- Deployed with iRedMail Easy or the downloadable installer?  Donwloaded Installer
- Linux/BSD distribution name and version: FreeBSD 13
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro?  Not yet
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====

Hello iRedMail community,

My first post here so please be gentle. I have iRedMail installed on an AWS EC2 instance. I would like to host websites for several very low traffic domains that I own on the same server. Are there any compelling reasons as to why I should not? Is there some guidance out there as to best practices should I choose to host some domains as the same server I host iRedMail on?

Thanks for any thoughts.

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Using Nginx to host websites on the same server as iRedMail

John Ullom wrote:

Are there any compelling reasons as to why I should not?

Sure you can host extra web domains on iRedMail.

John Ullom wrote:

Is there some guidance out there as to best practices should I choose to host some domains as the same server I host iRedMail on?

Check files under /etc/nginx/sites-enabled/ for example. smile

3

Re: Using Nginx to host websites on the same server as iRedMail

I have a question.

I am running iredmail on ubuntu 22.04 with nginx.

I would like to create another website e.g. mywebsite.com so I have followed the following steps.

1. created a folder /var/www/mywebsite.com
2. created a static index.html file within my root folder above
3. create a mywebsite.com.conf under /etc/nginx/sites-available/mywebsite.com.conf
below is my server config

server{
     root /var/www/mywesite.com
     index index.html
     server_name mywebsite.com

}

4. created a symlink sudo ln  -s /etc/nginx/mywebsite.com.conf /etc/sites-enabled/
5. ran nginx -t and test is successful
6. restarted nginx sudo systemctl restart nginx

7. opened my browser to access the new site from t mywebsite.com and it failed to load or even find the server.

Please what am I doing wrong.

thanks

4

Re: Using Nginx to host websites on the same server as iRedMail

Did you set the DNS records?

5

Re: Using Nginx to host websites on the same server as iRedMail

After upgrading of roundcubemail 1.42 to 1.5.5 session time of is not working. Even after one hours session of login session shall be active. session timedout is already configured.

// Session lifetime in minutes
$config['session_lifetime'] = 10;

6

Re: Using Nginx to host websites on the same server as iRedMail

Cthulhu wrote:

Did you set the DNS records?

I am running this locally on my ubuntu 22.04 server.
I have set hostname as mywebsite.com
and I have also updated hosts file with 127.0.1.1 as mywebsite.com while 127.0.0.1 as localhost

thanks

7

Re: Using Nginx to host websites on the same server as iRedMail

this is not what DNS records are meant to be

as i said before, you need to set proper DNS records for each hosted domain, includeing subdomains, dki, spf, mx, etc etc

8

Re: Using Nginx to host websites on the same server as iRedMail

Cthulhu wrote:

this is not what DNS records are meant to be

as i said before, you need to set proper DNS records for each hosted domain, includeing subdomains, dki, spf, mx, etc etc

Does it mean that without proper DNS record I can't run another site on nginx. I thought with virtual hosts it will be simple to host more than just iredmail (roundcube and admin) on the server.

Please I am testing this on localhost before I can migrate to proper production environment.

thanks

9

Re: Using Nginx to host websites on the same server as iRedMail

==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====
- iRedMail version: 1.6.8
- Deployed with iRedMail Easy or the downloadable installer?  Donwloaded Installer
- Linux/BSD distribution name and version: Ubuntu MATE 1.26.0 (Ubuntu 22.04.4 LTS)
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro?  Not yet
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====

Another first time user...  Kid Gloves please and assume lack of knowledge.

I have a registered domain with DNS and MX records.

Fresh install of Ubuntu, fresh download of iRedMail 1.6.8 from the web site.

Install ran perfectly.

Set up an SSL certificate with Certbot/Letsencrypt and added it to site/iredmail without a problem.

Forwarded ports through the router...

<Everything going well>

I have a second machine on which I installed both Plex and Emby media servers.
It responds to connection on the LAN, but not from the WAN - most likely because of the SSL certificate.

I installed both on the same machine as iRedmail. Neither of the application responds on either the LAN or WAN... 

UFW is not active as the router controls access.
Ports are mapped correctly through the router to either machine (having chosen different ports.

I can't seem to set up the certificate path on the media servers on the iRedMail machine because the certificates are owned by root and in other user accounts I can't see the folder they are in.

Suggestions or ideas welcome.

10 (edited by IRedMailForum 2024-08-01 05:34:57)

Re: Using Nginx to host websites on the same server as iRedMail

In keeping with the OP title and the related/stranded question posed by oz above, I'm endeavoring to add non-webmail websites to the same physical server where I currently have 9 mail domains smoothly operating

- iRedMail version: 1.6.8
- Deployed with iRedMail Easy or the downloadable installer?  Donwloaded Installer
- Linux/BSD distribution name and version: Debian 12
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro?  Not yet

I have a full compliment of tested SPF, DMARC, DKIM, A and MX records in place for each of the nine domains, and DNSSEC is likewise connected and tested with each domain.

I also setup Let's Encrypt certificates for each of the hosts within the nine domains and have tested them.

the following default /etc/nginx/sites-available/00-default-ssl.conf file is in place:

#
# Note: This file must be loaded before other virtual host config files,
#
# HTTPS
server {
    listen 443 ssl http2;
    server_name _;
    root /var/www/html;
    index index.php index.html;

    include /etc/nginx/templates/misc.tmpl;
    include /etc/nginx/templates/ssl.tmpl;
    include /etc/nginx/templates/iredadmin.tmpl;
    include /etc/nginx/templates/roundcube.tmpl;
    include /etc/nginx/templates/sogo.tmpl;
    include /etc/nginx/templates/netdata.tmpl;
    include /etc/nginx/templates/php-catchall.tmpl;
    include /etc/nginx/templates/stub_status.tmpl;
}

AND, I have created a file /etc/nginx/sites-available/mydomain.com.conf as follows:

#
# Note: This file must be loaded before other virtual host config files,
#
# HTTPS
server {
    listen 443 ssl http2;
    server_name mydomain.com;
    root /var/www/mydomain.com;
    index index.html;
}

I then enabled the non mail virtual server via the symbolic link:

ln -s /etc/nginx/sites-available/mydomain.com.conf /etc/nginx/sites-enabled/

Next I placed a simple "hello world" index.html file in the /var/www/mydomain.com directory.

NOW, I retested all the mail domains to make sure I didn't break what has been working fine, and all remained well.

THEN, Imodified the DNS records for mydomain.com by simply removing mydomain.com from the MX record, leaving the other hostnames in place.

I restarted the server, and again tested all the domains for normal web mail as well as POP/SMTP mail functionality and all was still good.

The the moment of truth, mail.mydomain.com still worked as always, what would mydomain.com do?
It appeared as though my changes weren't being applied, I thought, ah maybe I have to wait for DNS to propagate and clear browser cache, but NO, I could see that other DNS changes were taking effect immediately.

Then I had a hunch.  I had noticed that the default Index.htm file in /var/www/html contained a redirect to /mail

<html><head><meta HTTP-EQUIV="REFRESH" content="0; url=/mail/"></head></html>

What if my new virtual server definition WAS being acted on, BUT, because this default index.html with the redirect was still being called prior to handing over control to the intended virtual server, instead of using the root= /var/www/mydomain.com/index.html file, it was actually looking for a file at root= /var/www/mydomain.com/mail/index.html ???

Easy to test, I created a mail directory under /var/www/mydomain.com/ , and placed another copy of the "hello world" index.html within that mail subdirectory.  And, VOILA, the added virtual server definition was indeed being used and the test site is thus accessible!

This is not perfect, as clearly I am still at a loss as to why the original index.html is being called before following the added virtual server definition, OR how to fix this behavior.

Hopefully there's a simple solution here that I am just too dense to see so far--would someone be so kind as to offer explanation and/or assist?

Thanks All :-)

11

Re: Using Nginx to host websites on the same server as iRedMail

IRedMailForum wrote:

I am still at a loss as to why the original index.html is being called

Make sure you have correct "root" and "index" directive in your virtual web host config file.
Also, please create new forum topic for your own issue, do not hijack other's.

12 (edited by IRedMailForum 2024-08-11 03:07:04)

Re: Using Nginx to host websites on the same server as iRedMail

Short of suggestions or better approaches I hope to hear of or discover in the future, I came up with a functional kludge.

I simply put another index.html under mydomain/mail that redirected the page back to the /var/www/mydomain.com/index file.

<html><head><meta HTTP-EQUIV="REFRESH" content="0; url=/index.html"></head></html>

13 (edited by IRedMailForum 2024-08-11 03:35:27)

Re: Using Nginx to host websites on the same server as iRedMail

My sincere apologies Zhang, didn't mean to "hijack" anything, and then missed your reply above before posting the workaround.  :-(

(Please understand, the topic heading seemed highly related, then both the general OP's stated goal and the second more detailed scenario appeared nearly identical to my own, as far as oz went--when he did not come back having handled the DNS entries as you noted, that conversation line fizzled out.  I thought perhaps my having gone a couple steps further down the same path, and then tripped over, then identifed a non-obvious repeatable oddity, my follow-on inquiry might offer more clues.)

SYK, I've just rechecked, after a few days of not staring at it, (and, as you can imagine, many times prior checked and double checked) the root and index directives--to my understanding it is correct.  Thank you for having looked at it and for making that reasonable suggestion.  When nginx gets to the new virtual server file it executes it as would be expected, the problem seems to be that, for whatever reason as yet unknown to me, (perhaps default behavior)? the nginx process first executes the virtual server definition in the default /etc/nginx/sites-available/00-default-ssl.conf, which causes the path to be postpended with the /mail directory (as employed in the intended webmail server scenario.)

Again, sorry for my mistep, and my profuse gratitude for your creation and maintenance of this product making it available through it's free open source version to indivuiduals like me who could not possibly afford to pay fair market value for such a valid, solid, workhorse product.