multiple virtual hosts causing problems - Printable Version +- Linux-Noob Forums (https://www.linux-noob.com/forums) +-- Forum: Linux Server Administration (https://www.linux-noob.com/forums/forum-8.html) +--- Forum: LAMP (https://www.linux-noob.com/forums/forum-83.html) +--- Thread: multiple virtual hosts causing problems (/thread-621.html) |
multiple virtual hosts causing problems - anyweb - 2009-07-07 hi all i have some virtual webservers in apache and if i leave out the www infront of the address eg: http://windows-noob.com it will open up https://www.linux-noob.com which is quite funny but not the desired result my httpd.conf file looks ok (i think) so where does the problem lie ? with DNS, or with httpd.conf ? NameVirtualHost 94.75.228.161:80 <VirtualHost 94.75.228.161:80> ServerAlias www.linux-noob.com ServerAdmin anyweb@linux-noob.com DocumentRoot /websites/linux ServerName linux-noob.com </VirtualHost> <VirtualHost 94.75.228.161:80> # ServerAlias www.windows-noob.com ServerAdmin anyweb@linux-noob.com DocumentRoot /websites/windows ServerName www.windows-noob.com </VirtualHost> multiple virtual hosts causing problems - hybrid - 2009-07-07 I think that because your server name is www.windows-noob.com, it just isn't matching requests for windows-noob.com, simply because the two aren't the same. I actually run my virtual hosts the other way around -- I want them to respond to both the www.peter.upfold.org.uk prefix and no prefix (peter.upfold.org.uk), and then I redirect people silently to peter.upfold.org.uk if they went to www.peter.upfold.org.uk. I do this by setting ServerName to peter.upfold.org.uk and ServerAlias to *.peter.upfold.org.uk. Both prefixed and non-prefixed requests get directed to the correct virtual host, and then I can use a .htaccess rule with mod_rewrite to redirect people to the non-prefixed version. This solution should also be possible the other way round, so that's what I'd recommend here. So, in summary, my recommendation is:
An example of the mod_rewrite rule you might use: Code: RewriteEngine On multiple virtual hosts causing problems - anyweb - 2009-07-07 wow excellent answer thanks hybrid ! I'll test this out as soon as I can and report back :) thanks again multiple virtual hosts causing problems - Dungeon-Dave - 2009-07-25 A quick footnote here: if the HTTP/1.1 request hits apache and asks for a site that isn't matched in ServerName (or ServerAlias) then the *FIRST* virtual host defined is served up. This often has unexpected effects, such as in your case - DNS is resolving the FQDN to your server, but your server is unable to find any Vhost matching the HTTP request, so defaults to the first one. This also means that the first virtual host often gets plenty of unwanted traffic, some benign (from erroneously-configured DNS records) to malignant (apache port-sniffers). For that reason (and reasons of security), it is a good idea to have the first virtual host dropping requests into a blackhole, eg: Code: NameVirtualHost 94.75.228.161:80 Code: ## =========== LINUX-NOOB.COM ============= Code: ## =========== WINDOWS-NOOB.COM ============= Also note that many directives at server level (in the httpd.conf file) are usually overridden at vhost level so that vhosts don't pick them up by default - such as aliases for cgi-bin, logging areas, etc. On my servers, I would split mine out into 3 config files (a-default.conf, linux-noob.conf, windows-noob.conf - see above) then use "include" to bring them into my httpd.conf. It means disabling/enabling one site is purely a matter of quickly uncommenting/commenting out one line. Hope that helps (Apache is one of the things I know quite well!) multiple virtual hosts causing problems - anyweb - 2009-07-25 excellent info and i'd love to implement this but i'm so lacking with one thing, time, can you please expand on the following as I'm interested in hearing more about it Quote:On my servers, I would split mine out into 3 config files (a-default.conf, linux-noob.conf, windows-noob.conf) then use "include" to bring them into my httpd.conf. It means disabling/enabling one site is purely a matter of quickly uncommenting/commenting out one line. my webserver is serving more than windows-noob and linux-noob but i really need to get them replying properly and i like these ideas, so more info please :)and thanks ! multiple virtual hosts causing problems - Dungeon-Dave - 2009-07-25 Yup - it's pretty simple really, and makes administration much easier to manage. I'll take my setup as an example. I have /etc/httpd/ that contains three directories: conf/ conf.d/ vhosts.d/ in conf/ is my httpd.conf file. The last lines in there are: Code: Include "/etc/httpd/conf.d/*.conf" This means that any files ending in ".conf" in those directories are appended to the bottom of apache's config file. In my conf.d/ dir are files specific to certain services - ssl.conf, squirrelmail.conf, mod_security.conf, etc. Many of those get added by installed RPMs; some I rename from .conf to .old or .inc to "disable" them server-wide. In my vhosts.d/ dir are files specific to virtual hosts, such as those mentioned above. I also have some additional files (eg: "shared-icons.inc" and "ie-blocker.inc") that aren't included by default (don't end in .conf) but can still include them INTO an included vhost file - meaning that several vhosts can share common directory locations (such as /images, /icons and the like) - just removed unnecessary duplication. to disable a vhost, just rename it in the vhost.d/ dir from .conf to something else, eg: windows-noob.conf -> window.disabled - then after an apache reload, the config will be overlooked. If you are managing several vhosts, it makes sense to spend some time analysing and planning the config files layout, looking to template your files and normalise duplications (such as shared directory locations). Also: don't forget "/etc/init.d/apache configtest" - use it to test out your config settings before restarting/reloading apache! If it helps, feel free to chuck me a few of your files and I can throw back an example of how I'd structure them, just as an example. They won't fully fit your current setup (can't just drop them in place and hope they work) but it should illustrate what I'm talking about. |