homepage Welcome to WebmasterWorld Guest from 50.19.169.37
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Apache2 Virtual Hosts question
Multiple Header Identities on a Virtual Host
kaspencer




msg:4517498
 12:40 pm on Nov 9, 2012 (gmt 0)

Greetings all ...

I am currently moving a website from Microsoft IIS v7 onto Apache2 v5.5 under a Debian variant. There will be several different Virtual Hosts. Everything is basically working but I need a little advice:

IIS7 has an option which permits entry of a list of possible Host/Server Name/Identity submissions which may be received for any given specified Virtual Host.
For example:
www.site-name.domain
site-name.domain
www.different-name.domain
different-name.domain
might all have to point to the same content on the web server.

So, to the point: what is the simplest and most effective method of achieving this in Apache2?

Incidentally, I am using Webmin 1.6 to manage the server applications on the Debian machine.

Many thanks,

Kenneth Spencer

 

phranque




msg:4517510
 1:07 pm on Nov 9, 2012 (gmt 0)

welcome to WebmasterWorld, Kenneth!

i'm not sure what v5.5 is but your apache should be a version of 2.0, 2.2 or 2.4 - but this shouldn't matter as far as your question is concerned.

within your <VirtualHost> context you would typically set your hostname for the virtual host using the ServerName directive.
you can also specify one or more alternate hostnames within that <VirtualHost> context using the ServerAlias directive.

if you do this you should pick one of those hostnames to be the canonical hostname and 301 redirect all non-canonical URLs requested to the canonical hostname.

Name-based Virtual Host Support - Apache HTTP Server:
http://httpd.apache.org/docs/current/vhosts/name-based.html [httpd.apache.org]

<VirtualHost> Directive:
http://httpd.apache.org/docs/current/mod/core.html#virtualhost

ServerName Directive:
http://httpd.apache.org/docs/current/mod/core.html#servername

ServerAlias Directive:
http://httpd.apache.org/docs/current/mod/core.html#serveralias

kaspencer




msg:4517553
 4:58 pm on Nov 9, 2012 (gmt 0)

Thanks alot for that speedy reply, ph.

And sorry about the v5.5 I think that's the MySQL version! Apache2 is indeed v2.2.22.

I shall try the ServerAlias directive early next week, but I think that seems to replicate what I needed.

All the best

Kenneth Spencer

kaspencer




msg:4518809
 6:49 pm on Nov 13, 2012 (gmt 0)

Thanks again for the earlier reply.

I have done a some more work on the server, but I still haven't got it right. So here is some more background:

1. Background
I have a subdomain on an external dynamic DNS service of the form:
www.my-example.example.com
or
my-example.example.com.
I do not own example.com, and the subdomain my-example is provided by the DNS service as part of my subscription. (I have several of them).
The my-example.example.com points to my WAN IP address and is directed to my web server by local IP address and port 80 redirection in my router.
This is for background only as all this is working on the existing server.

2. Default website (Working)
On the Apache2 web server I wish to use the root-data directory /var/www as the default website.
The web server is registered in my DNS Server in the form:
[my-serverIP] my-machine-name
and is thus accessible from my LAN as:
http://[my-serverIP]
or as:
http://my-machine-name.
As there in only one local domain on my LAN, I do not need to fully qualify the address.

2. First Virtual Host
The data for the my-example web site is in a subdirectory /var/www/my-example and thus at the moment can be accessed as:
http://[my-serverIP]/my-example
or as:
http://my-machine-name/my-example.
This is working, but I need to set up access as:
http://my-example
http://my-example.example.com
and
http://www.my-example.example.com

I have tried several different arrangements for the entry in /etc/apache2/sites-available/my-example but none so far have worked properly.
My ports.conf file contains:
Listen 80
and some other lines relevant to SSL port 443.

In /etc/apache2/conf.d I have a file ServerName.conf which contains the line:
ServerName my-machine-name

Also in /etc/apache2/conf.d I have a file VirtualHosts.conf which contains the line:
NameVirtualHost [my-serverIP]:80

So far, Apache2 starts and stops with neither warning nor error, and the default website and my-example site are available as stated in 2. and 3. above.

In /etc/apache2/sites_available I have a file my-example which contains the following lines:
<VirtualHost my-example:80>
ServerAdmin [email address]
ServerName my-example
ServerAlias www.my-example.example.com
ServerAlias *.my-example.example.com

DirectoryIndex index.htm
DocumentRoot /var/www/my-example

ErrorLog /var/www/my-example/logs/error.log
CustomLog /var/www/my-example/logs/access.log combined
</VirtualHost>
.

When I link this file into /etc/apache2/sites-enabled and start Apache2 I receive the error:
"Starting web server Apache2 [date] [error] (EA1 2) Name or service not known: Could not resolve host name my-example -- ignoring!
Action 'start' failed.
"
There is no error.log in /var/www/my-example/log but there is an error in /var/log/apache2/error.log:
"[Date] [notice] caught SIGTERM, shutting down.
[Date] [notice] seg fault or similar nasty error detected in the parent process
"

Perhaps I am missing an obvious error?

Sorry about the long post but I thought you'd appreciate as many details as possible.

Thanks in advance,

Kenneth Spencer

phranque




msg:4518896
 10:20 pm on Nov 13, 2012 (gmt 0)

what happens when you do this?


nslookup my-example

kaspencer




msg:4518922
 12:48 am on Nov 14, 2012 (gmt 0)

If I do an nslookup on a remote (Windows) PC it finds my-example.my-domain.local, as the web server machine is in the DNS on my LAN. In fact it is in my DNS as the machine name and per the entry in the virtual hosts.

However, the web server machine doesn't have nslookup (and I cannot find it from any of my known sources) so I cannot try it from the web server machine. In the web server, the ServerName is definitely in the /etc/hosts file.

Thanks for the reply ...

Kenneth Spencer

phranque




msg:4518937
 2:26 am on Nov 14, 2012 (gmt 0)

Could not resolve host name my-example

you need to do the nslookup from the server.
i can't imagine nslookup is unavailable.
what type of system is your server running on?

"nslookup my-example" should resolve to an IP address.

you could also try:

ping my-example

kaspencer




msg:4518998
 9:47 am on Nov 14, 2012 (gmt 0)

Thanks PH ...

Indeed I should have stated previously that:
ping my-example
correctly gets replies. So it does resolve outside Apache2. But maybe Apache2's error message is misleading.

Regarding nslookup: I am running Debian Wheezy 7.0.
So far as Debian is concerned, nslookup is part of BIND and all the indications are that it cannot be installed alone. I don't wish to install BIND as I already have a DNS server on my Windows 2003 R2 domain controller.

The machine name, and all virtual host names are entered into the /etc/hosts file (because ultimately I am intending to run this machine as a standalone web server) so far as direct access on the local machine is concerned.

I have a couple of other things I will try, but what I need to avoid is a repeat of what has already happened - namely that the server became quite "messed up" and reinstalling packages didn't sort it out, so I had to reinstall the lot: OS, Proftp, Apache2, Webalizer, MySQL, PHP5 etc etc etc!

Thanks again for your attention.

Ken.

phranque




msg:4519007
 11:27 am on Nov 14, 2012 (gmt 0)


<VirtualHost my-example:80>


try using the IP address instead of the hostname in the VirtualHost directive:
for example:

<VirtualHost 192.168.1.1:80>

kaspencer




msg:4519402
 5:18 pm on Nov 15, 2012 (gmt 0)

Thanks PH ...

I had previously tried using the IP address of the server instead of the hostname. And having tried it again, it still fails.

I don't know why Apache2 collapses with a SIGTERM when I am certain the the configuration is correct. And even if it wasn't I'd have thought that any error should be trapped.

It's a bit disappointing, but I am going to re-install the OS and Apache2 in a minimal server so that re-installation of the whole thing during the discovery of why this isn't working is easier. If I can then get a set of configuration files that work (!) I will try them with a fully installed fully configured server.

You may not hear from me for a while but thanks for your patience!

Best wishes,

Ken

phranque




msg:4519518
 11:57 pm on Nov 15, 2012 (gmt 0)

try testing the apache configuration with:

apachectl configtest

or

apachectl -t

kaspencer




msg:4519644
 9:51 am on Nov 16, 2012 (gmt 0)

Hello again, PH ...

Last night I completed a detailed look at what I was trying to do with Apache2, but using an absolutely minimal installation of the OS and of Apache2.

I am glad to say that I made progress. I will probably not be able to do much more now until Tuesday of next week as social things will get in the way of web development. However, it seems that there are some things concerning the log files which Apache2 is unable to trap if they are not quite right - they are the cause of the SIGTERMs.

On Tuesday I shall complete the tests on the minimal installation and then try to implement my changes on a full system (possible after a full re-installation of absolutely everything because I suspect that the existing full installation may have been damaged by the events).

I will report back after that.

Many thanks again for your interest and help ...

Ken.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved