1 (edited by maxwellsmart 2019-04-12 12:15:52)

Topic: Static virtual host

==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====
- iRedMail version (check /etc/iredmail-release):
- Deployed with iRedMail Easy or the downloadable installer?
- Linux/BSD distribution name and version:
- Store mail accounts in which backend (LDAP/MySQL/PGSQL):
- Web server (Apache or Nginx):
- Manage mail accounts with iRedAdmin-Pro?
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====
I'm running iRedMail-0.9.8 / CentOS 7.  Pretty much a fresh install at this point. 

I need to be able to serve up static images and cannot for the life of me figure out how to create a simple virtual host page block in nginx. 

I need to create a page that answers to https://test.example.com with a root directory of /home/test/public_html/
Every config I've tried either answers to SOGo or /mail/

Help me Obewan, you're my only hope...

2 (edited by maxwellsmart 2019-04-12 12:13:36)

Re: Static virtual host

No nginx gurus out there? 

The problem I'm having is that the Nginx setup on an iRedMail server is not stock.  Nginx is new to me and I can't figure out the setup.  Any help is welcome.

Zhang, you there?  Can you shed some light???

3

Re: Static virtual host

What file executes the redirect to /mail?

4 (edited by kamaranl 2019-04-13 22:21:15)

Re: Static virtual host

I don't exactly know what you are aiming for, but here's some things that might help...

• /var/www/html/index.html is the file that redirects you to '$hostname.$domain/SOGo' - this is the file you usually replace or edit on a stock Nginx setup.
• /etc/nginx/sites-available/ is where you will find your site-configurations for your virtual hosts - you can copy the default and/or default ssl to use as a template, eg: cp /etc/nginx/sites-available/00-default-ssl.conf /etc/nginx/sites-available/mywebsite-ssl.conf
• lastly, once you have your configuration set up properly, you are going to symlink it to the sites-enabled folder, eg: ln -s /etc/nginx/sites-available/mywebsite-ssl.conf /etc/nginx/sites-enabled/mywebsite-ssl.conf

5

Re: Static virtual host

Thanks for chiming in. 

I've figured all that out, but here's the caveat.  I'm trying to get the server to answer to test.example.com without redirecting to test.example.com/mail   No matter what changes I make it redirects to /mail, like so

2019/04/12 21:04:37 [error] 18741#0: *21 "/var/www/html/test/mail/index.php" is not found (2: No such file or directory), client: 192.168.0.100, server: _, request: "GET /mail/ HTTP/1.1", host: "test.example.com"

Here is the config file with the appropriate files in sites-available and sites-enabled

location / {

        root    /var/www/html/test;
        index   index.php index.html;
}

6

Re: Static virtual host

It should be very easy to create a virtual web host like this:

- Create file /etc/nginx/sites-available/mysite.conf (replace this file name by whatever you want, but must end with '.conf'):

# http host
server {
    # IPv4
    listen 80;

    # IPv6
    #listen [::]:80;

    server_name test.example.com;

    # Redirect all insecure http:// requests to https://
    return 301 https://$host$request_uri;
}

# https host
server {
    listen 443;
    server_name test.example.com;

    # Define the root directory of web files. you must create it first.
    root /var/www/mysite;
    index index.php index.html;

    # You can load more config snippets from /etc/nginx/templates/ with the "include" directive.
    include /etc/nginx/templates/misc.tmpl;
    include /etc/nginx/templates/ssl.tmpl;
    include /etc/nginx/templates/php-catchall.tmpl;
}

Easy?

----

Does my reply help a little? How about buying me a cup of coffee ($5) as an encouragement?

buy me a cup of coffee

7 (edited by maxwellsmart 2019-04-13 12:24:28)

Re: Static virtual host

Why .conf and not .tmpl like the rest of the includes?

I don't understand why you cannot add the include in the sites-enabled/00-default-ssl.conf  and then point it to the test.example.com.tmpl file in the templates/test.example.com.tmpl file.

8 (edited by maxwellsmart 2019-04-13 12:38:35)

Re: Static virtual host

Tried what you've suggested, with no luck.  Same error, still trying to redirect to /mail subfolder.

I agree this should be simple, but it's certainly elusive.

9

Re: Static virtual host

Show me your FULL nginx config file for this virtual web host.

Sorry i forgot to mention that you need to create symbol link of /etc/nginx/sites-available/mysite.conf to /etc/nginx/sites-enabled/.

----

Does my reply help a little? How about buying me a cup of coffee ($5) as an encouragement?

buy me a cup of coffee

10

Re: Static virtual host

maxwellsmart wrote:

Why .conf and not .tmpl like the rest of the includes?

I don't understand why you cannot add the include in the sites-enabled/00-default-ssl.conf  and then point it to the test.example.com.tmpl file in the templates/test.example.com.tmpl file.

We use .tmpl for code snippet file.

----

Does my reply help a little? How about buying me a cup of coffee ($5) as an encouragement?

buy me a cup of coffee

11 (edited by maxwellsmart 2019-04-13 23:52:18)

Re: Static virtual host

I used the exact text you provided above, but changed the pertinent information to match my server.  I've created a link in the /var/www/ file to match the content in the corresponding /home/test/public_html/index.html file I want to serve. I also had created the symbolic link in sites-enabled.

I double checked the 00-default.conf and 00-default-ssl.conf to make sure I hadn't had any erroneous links from my trials, all good.

After a good nights sleep I woke with a complete understanding of the .conf and .tmpl differences.  Your virtual host config, made everything more clear.

That being said it's still redirecting to /mail   I have the nginx index file in the public directory along with the support images.  If I add index.html to the URL https://test.example.com/index.html it redirects to https://test.example.com/mail/  If I add the poweredby.png to the url https://test.example.com/poweredby.png it shows the image.

Now that I have a better understanding how it works, I'm even more confused, why it's not working. 

TIA to all for helping get it sorted.

12

Re: Static virtual host

maxwellsmart wrote:

I used the exact text you provided above, but changed the pertinent information to match my server.  I've created a link in the /var/www/ file to match the content in the corresponding /home/test/public_html/index.html file I want to serve. I also had created the symbolic link in sites-enabled.

Just a few follow-up questions concerning what you said above:
• Did you remove/alter the index.html file located at /var/www/html/?
• Did you remove the default symlinks in /etc/nginx/sites-enabled, making sure that only your symlink for your conf 'test.example.com' was left.
• Do you have DNS (A) records pointing to this server's IP or have you altered your hosts file on whatever client you are using to view the content on 'test.example.com'?

I only ask because the nginx setup shipped with iRedMail is set to redirect to /mail by default.

13

Re: Static virtual host

kamaranl wrote:
maxwellsmart wrote:

I used the exact text you provided above, but changed the pertinent information to match my server.  I've created a link in the /var/www/ file to match the content in the corresponding /home/test/public_html/index.html file I want to serve. I also had created the symbolic link in sites-enabled.

Just a few follow-up questions concerning what you said above:
• Did you remove/alter the index.html file located at /var/www/html/?
• Did you remove the default symlinks in /etc/nginx/sites-enabled, making sure that only your symlink for your conf 'test.example.com' was left.
• Do you have DNS (A) records pointing to this server's IP or have you altered your hosts file on whatever client you are using to view the content on 'test.example.com'?

I only ask because the nginx setup shipped with iRedMail is set to redirect to /mail by default.

Just a few follow-up questions concerning what you said above:
• Did you remove/alter the index.html file located at /var/www/html/? Yes, I changed the name to index.orig.  I also commented out the redirect in the index.html file.  It still redirects.  I'm missing some file that's redirecting, but I cannot find it.
• Did you remove the default symlinks in /etc/nginx/sites-enabled, making sure that only your symlink for your conf 'test.example.com' was left. I tried only commenting out the roundcube.tmpl in the 00-default-ssl.conf since it's the only one that resolves to the /mail subfolder.
• Do you have DNS (A) records pointing to this server's IP or have you altered your hosts file on whatever client you are using to view the content on 'test.example.com'?  Yes, I have DNS (A) records for the site I'm trying to serve.

I only ask because the nginx setup shipped with iRedMail is set to redirect to /mail by default.  Yes and here in lies the trouble I'm having, finding out why it still redirects even with those files commented out.  Are there any other files I should be looking at?

Thanks as always

14

Re: Static virtual host

maxwellsmart wrote:

Yes and here in lies the trouble I'm having, finding out why it still redirects even with those files commented out.

What's the root directory of your new website (defined in "root" directive)?
I don't understand why a different root directory will cause the redirection to "/mail", it doesn't make any sense to me.

Try to turn on debug mode in Nginx, check its log file to figure out which config file Nginx reads when you accessing this new web domain name, and which file (index.php/html) it reads to serve the client.

----

Does my reply help a little? How about buying me a cup of coffee ($5) as an encouragement?

buy me a cup of coffee

15 (edited by maxwellsmart 2019-04-15 23:37:47)

Re: Static virtual host

The root directory is /var/www/test  with test being a symbolic link to /home/test/public_html

index.html is the only file that causes a redirect.  If I use test.example.com/test.jpg it works fine as well as test.example.com/test.html

I believe I've found the problem.  It wasn't the server redirecting the request it was the browser.  I was suspect of this before and cleared the cache, but the configuration wasn't correct at that point.  Once the configuration was correct it was still calling up the cached version in the browser and redirecting to /mail.  The best solution for testing is to use a fresh private/incognito browser that doesn't have any cache.  This guarantees a clean call.

I'm still testing, once I finish I'll update.

Thanks all.

16

Re: Static virtual host

I believe I've gotten everything sorted.  Your input gave me enough help to find the misconfigurations. Thanks for all your help.

I do have another question regarding setting up subdomain rather than sub-folder, but I'll open another thread when I get to that.

17

Re: Static virtual host

Mind sharing the fix here? smile

----

Does my reply help a little? How about buying me a cup of coffee ($5) as an encouragement?

buy me a cup of coffee

18

Re: Static virtual host

The fix was deleting the cache in the browser or using a private browser that the cache was empty from the start.  It was the browser that was redirecting the WGET request.  The server configuration was correct.

Is there documentation for using the sub-domain instead of the subfolder tmpl?  for instance answering to https://mail.example.com instead of https://example.com/mail?

19

Re: Static virtual host

maxwellsmart wrote:

Is there documentation for using the sub-domain instead of the subfolder tmpl?  for instance answering to https://mail.example.com instead of https://example.com/mail?

Just create a virtual web host for "mail.example.com", and use Roundcube as its root directory (to be simpler, just include "/etc/nginx/templates/roundcube-subdomain.tmpl" and it's done.)

----

Does my reply help a little? How about buying me a cup of coffee ($5) as an encouragement?

buy me a cup of coffee