Author |
|
Klaipedaville
Joined: 12 Oct 2013 Posts: 22
|
Posted: Sat 12 Oct '13 18:34 Post subject: Subdomains Served by Themselves? |
|
|
I'll try to be concise and would be thankfull for any help. Here is what happens at my side of the pond.
When I type mail.mydomain.com into any browser it resolves to the first virtual host that my apache has even though there aren't any document roots defined for mail.mydomain.com. Apache itself works fine, mail server itself works fine as well. I thought that since mail.mydomain.com has an A record but does not have any document roots specified for that Apache simply takes the first virtual host it has on its list and shows it up online as mail.mydomain.com. Is that not right? Is there perhaps any misconfiguration somewhere?
I tried deleting virtual hosts one by one and this test simply confirmed that in order to "serve" mail.mydomain.com Apache takes the first virtual host it has on the list. Then I created a document root for mail.mydomain.com and now it shows some test content I specified but my issue / question remains.. Does it mean that I have to create document root stuff for every single A record I have? For example I have an A record for mail.mydomain.com which works as a mail server but for some reason it also resolves as a simple web page?
The problem in short is that when I type mail.mydomain.com into a browser it shows the content from subdomain.mydomain.com. The relation to mail is not webmail, it's just a regular standard mail server. The question / goal is to find out whether it is supposed to be like that? If it is then I will have to create some content to be shown when someone types mail.mydomain.com
I would highly appreciate and would be grateful to hear any comments / advises / suggestions / feed back in general at all. Many thanks! |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Sat 12 Oct '13 18:48 Post subject: |
|
|
It's called the _default_ host, which will answer when the hostname asked for has not been configured for, so it is normal and documented. http://your_ip_address will show this same _default_ host. |
|
Back to top |
|
Klaipedaville
Joined: 12 Oct 2013 Posts: 22
|
Posted: Sat 12 Oct '13 19:06 Post subject: |
|
|
Thank you glsmith. However, it does not resolve to the default host, it resolves to a subdomain... or... I mean to say there is only one IP address for all these... Although I begin to see a pattern here and will read on the_default_host to clarify the entire picture. I think you hit the nail right on its head and in that case I may need to configure the hostname (document root) for ns1.mydomain.com and ns2.mydomain.com because otherwise it will resolve to the first subdomain (host) Apache has on its list. Is that right? |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Sat 12 Oct '13 19:43 Post subject: |
|
|
Yes it is.
My first vhost is a junk vhost, all it does is basically say "There is no website at this address" if the sever answers any non-configured hostname. |
|
Back to top |
|
Klaipedaville
Joined: 12 Oct 2013 Posts: 22
|
Posted: Sat 12 Oct '13 19:57 Post subject: |
|
|
Fantastic! That's a perfect idea! Junk host! Thank you so much for sharing!!! I might as well implement it too! All I need to do is to make it begin with a letter A so that it would be the first one on the list in accordance with the pattern I noticed.
It took me only a second to fix the junk host and it is already working and doing fine there! |
|
Back to top |
|
Klaipedaville
Joined: 12 Oct 2013 Posts: 22
|
Posted: Sun 20 Oct '13 21:04 Post subject: |
|
|
Since you're so increadilbly good here I thought I would ask a little further about the_default_host. Would highly appreciate any tips at all.
I have two installations. The first apache on my first server is very flexible. I can simply delete the_dafault_host and my next host becomes the default one. I just name it for example A so that it would jump on top the one named B as I notice apache creates and treats its hosts in alphabetical order.
My next apache installation on my next server goes totaly dead and crashes for good as soon as I delete the_default_host. The only work around I could find about it at the moment was totally re-installing apache again and leaving the_default_host alone.
Now the question is which one of these two is the correct and regular behavior? I cannot seem to find how my first option coud be possibly configurable this way on purpose? Many thanks! |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Mon 21 Oct '13 6:44 Post subject: |
|
|
quick & dirty
httpd.conf
Code: |
ServerName somename.domain.com
DocumentRoot /www/default/public_html
<Directory /www/default/public_html>
...needed stuff...
</Directory>
|
extra/httpd-vhosts.conf
Code: |
# default host must be the first vhost listed and a
# partial duplicate of the main host in httpd.conf
# per "Main host goes away" section at
# http://httpd.apache.org/docs/2.4/vhosts/name-based.html#using
<VirtualHost _default_:80>
DocumentRoot /www/default/public_html
</VirtualHost>
# Now all the real hosts
<VirtualHost *:80>
ServerName www.mydomain.com
DocumentRoot /www/mydomain/public_html
<Directory /www/mydomain/public_html>
...needed stuff...
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName www.otherdomain.com
DocumentRoot /www/otherdomain/public_html
<Directory /www/otherdomain/public_html>
...needed stuff...
</Directory>
</VirtualHost>
|
etc. etc. |
|
Back to top |
|
Klaipedaville
Joined: 12 Oct 2013 Posts: 22
|
Posted: Mon 21 Oct '13 15:51 Post subject: |
|
|
Hey! Thanks! I will give it a try as I have an idea.
However, I am not sure I understood it correctly because I do not have any httpd.conf or extra/httpd-vhosts.conf files at all. Nonetheless my apaches run well without these two files. All my vhosts have a separate file (each vhost has its own file) and my default_vhost looks like this :
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost> |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Mon 21 Oct '13 19:48 Post subject: |
|
|
you do not have an httpd.conf file? I'll assume this isn't Windows we're talking about anymore.
Methinks on *nix it's /etc/conf.d/apache2.conf is the main config file if I remember correctly which is the sameISH as httpd.conf on Windoze.
I have multiple vhosts files as well, I was just using the standard issue Windows config for an example. As long as the first vhost (_default_) is a minor copy of the main host er that note in the docs, things should be fine. |
|
Back to top |
|
Klaipedaville
Joined: 12 Oct 2013 Posts: 22
|
Posted: Tue 22 Oct '13 9:11 Post subject: |
|
|
That's right and many thanks to follow up on this! It is definitely not Windows that I am talking about. Debian (Linux distro) does not have any httpd.conf files at all unless a user creates it himself/herself. Httpd.conf in Debian is used only for additional customization if you need one, otherwise apaches on Debian run fine without any httpd.conf files at all.
Are you saying that I have to create a copy of the_default_host and then I shall be fine even if I delete my main default host that was created automatically when apaches were installed? But in that case the default host will still be the default host (a copy of it) and not the first existing host I have on the list. Is that not right? It may not be as clear but what I am looking for is to find out whether it is possible to completely delete the_default_host that was installed automatically together with apache so that that the first virtual host of mine would become apaches' main default_host instead?
I read the docs about a couple of dozen times but there are points in them that are simply totally beyong my understanding )) |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Tue 22 Oct '13 9:25 Post subject: |
|
|
I cranked up my Ubuntu VM today and had a look and noticed just what you are saying, and in that config there is no main host (ServerName,DocumentRoot,<Directory> business in a Global context) like there is in Windows.
James Blond here is a Debian guru, he'll know. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Tue 22 Oct '13 18:36 Post subject: |
|
|
*cough* who RTFW? Not I!
I'm not generally concerned about the Debian layout myself, more in how vhosts are configured to properly work on one. Since I know you have 2.4 with multiple hosts running on a Debian, I just assumed you may be able to do the translation between Windows & Debian on this subject. |
|
Back to top |
|
Klaipedaville
Joined: 12 Oct 2013 Posts: 22
|
Posted: Wed 23 Oct '13 13:03 Post subject: |
|
|
It's been useful to take a look at the link. Thanks. However, this information is pretty much the very basic one. We weren't looking for configuration files' locations and apache layouts. I mentioned httpd.conf as a side-note just in addition, it was only a comment. The point was if it was possible to delete the existing default_vhost so that my main / first vhost would become the_default_vhost instead?
Last edited by Klaipedaville on Wed 23 Oct '13 13:34; edited 1 time in total |
|
Back to top |
|
Klaipedaville
Joined: 12 Oct 2013 Posts: 22
|
Posted: Wed 23 Oct '13 13:32 Post subject: |
|
|
glsmith wrote: | *cough* who RTFW? Not I!
I'm not generally concerned about the Debian layout myself, more in how vhosts are configured to properly work on one. Since I know you have 2.4 with multiple hosts running on a Debian, I just assumed you may be able to do the translation between Windows & Debian on this subject. |
I am also fine with the layout, the proper configuration is what I am after as well
The translation in between Windows and Linux (Debian) almost worked as I can see the idea in general now but these small little details is where I get stuck. Removing the symlink on Debian which is actually a vhost (the_default_host) crashes apache for good.
Although it's OK for me to re-configure the_default_host and make it my junk host to say 'there is no website at this address' which I assume would be the only proper way to do it.
My other "tweaked" (not done by me) instalation of apache on Debian does not have any default_hosts at all. There are no softlinks (symlinks) for that either and there are no default_vhosts either under /sites-available or /sites-enabled. Nonetheless it works perfectly fine anyway and 'employs' my first actual vhost as the default_vhost. I begin to think that this one is messed up somehow somewhere and I'd better re-do it the right way. That's why I began looking for "the right way" the default_vhost is supposed to function |
|
Back to top |
|