LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-01-2014, 04:18 AM   #1
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Rep: Reputation: Disabled
Apache Question


Hey Guys,

I wonder if you can help.. I have been studying for some time and I've been on a few Red Hat courses. I have sat and passed my RHCSA, and I followed by attending the RHCE course where I unfortunately failed the exam - forgot to check fstab and the server didn't boot

Anyway, I've got a re-sit booked for this Friday and I've been studying for the couple of weeks I've been back to prepare myself.

So, that's my background.. now for my question.

I'm looking at Apache Virtual hosts, and while I have it working I am intrigued by something.. I began by installing httpd, created a simple test index.html file and put it into /var/www/html, did the usual and it works fine.

I then looked at a virtual host, I configured the virtual host as follows in /etc/httpd/conf/httpd.conf:

Code:
<VirtualHost *:80>
    ServerAdmin webmaster@virtual.example.com
    DocumentRoot /www/virtual
    ServerName virtual.example.com
    ErrorLog logs/virtual.example.com-error_log
    CustomLog logs/virtual.example.com-access_log common
</VirtualHost>
I then set the SELinux context for /www/virtual and tested, and now http://virtual.example.com does display the correct web page.

However, the original http://server.example.com also displays the virtual.example.com web page. Now from reading a little more of the config file, it does say that the first virtual host will be the first to respond to everything if the host does not match a recognised virtual host.

I was able to fix this by amending the virtual host section of the httpd.conf file to look like this:

Code:
<VirtualHost *:80>
    ServerAdmin webmaster@server.example.com
    DocumentRoot /var/www/html
    ServerName server.example.com
    ErrorLog logs/server.example.com-error_log
    CustomLog logs/server.example.com-access_log common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@virtual.example.com
    DocumentRoot /www/virtual
    ServerName virtual.example.com
    ErrorLog logs/virtual.example.com-error_log
    CustomLog logs/virtual.example.com-access_log common
</VirtualHost>
This works fine.

However, I don't remember having to do this on the course, I thought that the virtual host would act as the virtual host and the main website would still be accessible as the main document root...

Just trying to make sure I fully understand it, so if someone could just confirm if what I've done is right? Or have I just done a work around and covered up something else that I've done wrong?

Thanks in advance...

Jon
 
Old 06-01-2014, 04:56 AM   #2
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Hey John,

I work with virtual Apache servers a lot so I was looking at your question.

Quote:
However, the original http://server.example.com also displays the virtual.example.com web page
No, it doesn't, if you changed the test page on the guest server, it wouldn't change the page on the host server. Part of your confusion is your use of "host" as both a designation for a server running Apache and a server running a virtual sandbox where one or more "guests" are operating. The guest Apache servers versus the host Apache server.

The reason what you're doing isn't on the test is you'll only find someone doing that when working in a "test" virtual environment (as opposed to the production virtual environment) and then exceedingly rarely because it's not really important how your workstation would run the web app or site, it's only important how the guest servers are running it. In fact, I've never even turned the Apache web server built into my workstation on, the app server or site server is a guest server, the host servers (or nodes) primarily just run the sandbox and the workstations primarily just monitor and interact with the sandbox or the guests.

Hope that helps, good luck on the test.

Last edited by dijetlo; 06-01-2014 at 05:03 AM.
 
Old 06-01-2014, 05:03 AM   #3
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
Hey, thanks for your response.

I got the impression that you were referring to Host and Guest OS's?

I was talking more about Virtual Hosts, like host headers in Windows, meaning you can host multiple websites on one server with one IP Address.

The way I understand it is that you can have http://server.example.com and http://virtual.example.com displaying different web pages but on a single server with a single instance of Apache, where that server has only one ip address.

I've got it working this way.

But my question is more, when the Apache Configuration looks at the config file for virtual hosts (at the bottom of the config file) - should it then ignore the main config (the document root outlined in the main part of the file) and look solely at the virtual host section, meaning you've got to re configure the 'main' webpage as a virtual host it's self?
 
Old 06-01-2014, 05:34 AM   #4
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Jon, I've never taken a Red Hat test, so what Red Hat is telling you is an open question in my mind. If you have a question about what's on the test, you should probably wait for one of the people who've taken it to straighten you out because I can't tell you what's on the test. I'm concerned I'm going to confuse you here and I don't want to do that.
Quote:
I've got it working this way.
I suspect what you've done is configure the host apache server to accept http requests for both the www.server.com domain and the www.virtual-server.com while not configuring the guests servers to do much of anything at all. Their configuration files are not on the host machine, they are inside the shared data store that your host machine can only access by accessing the guest servers and editing the files.

Last edited by dijetlo; 06-01-2014 at 05:38 AM.
 
Old 06-01-2014, 05:46 AM   #5
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
Hey,

Although I have sat the exam, I'm not asking for help with a particular question. I would never discuss the exam questions and I wouldn't ask for advice regarding a particular question. When we sit Red Hat exams we sign an NDA agreeing never to discuss this exam content.. I would never do this and I would'nt expect anyone else to.. it just devalues our certifications if the exams are made easy by people discussing the content. I think agree, that none of us want this.

I'm just trying to make sure I understand this stuff fully to give me the best chance of passing the exam, but more importantly so that I fully understand it for me!

I still think we're on different pages here.. I'm not talking about multiple server or virtual instances. I have one server, with one apache config file. This server will provide access to multiple websites from the same IP Address.

If the request come from http://virtual.example.com apache checks to see if there is a virtual host configured in httpd.conf associated with that domain, and if there is it will deliver the website associated with virtual.example.com... in this case:

Code:
<VirtualHost *:80>
    ServerAdmin webmaster@virtual.example.com
    DocumentRoot /www/virtual
    ServerName virtual.example.com
    ErrorLog logs/virtual.example.com-error_log
    CustomLog logs/virtual.example.com-access_log common
</VirtualHost>
This is working and without a problem. If I navigate locally to http://virtual.example.com I can see the content of index.html stored in /www/virtual.

No problem here.

If I turn off Virtual hosts by commenting out the line: NameVirtualHost *:80 then the default website stored in /var/www/html will be displayed when I navigate to http://server.example.com but when I navigate to http://virtual.example.com nothing is displayed (we'd expect this)...

But then I turn on Virtual hosts by uncommenting the line NameVirtualHost *:80, and add the above mentioned virtual host to the configuration file, I have to then add another virtual host for the default site located within /var/www/html.. it appears to not be recognised form the default configuration.

So I guess in essence my questions is, does the virtual host configuration override the default configuration and therefore the contents of the default document root are not looked at unless it is specified within a virtual host at the bottom of httpd.conf.
 
Old 06-01-2014, 05:49 AM   #6
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Quote:
I got the impression that you were referring to Host and Guest OS's?
OK, Sorry, now I get it... you're talking about a virtual domain, not a virtual server....

There's nothing actually virtual about a virtual domain,it's just an alias. The reason they display the same web page is they have the same document root. Point the document root on the first domain to /var/www/example.com/html and the second to /var/www/virtual.example.com/html/ -after you've created the directories and populated them, give each a different index and you'll get the result your looking for.
Hope that helps.

Last edited by dijetlo; 06-01-2014 at 05:59 AM. Reason: Standard Practice
 
Old 06-01-2014, 06:01 AM   #7
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
I've got the result I'm aiming for.. but I wanted to know if I've done it the right way.

If Apache hosts a single website, the content for that website is /var/www/html (unless changed) and Apache knows to serve that site.

If I add a single virtual domain and point the virtual domain to have a document root of /www/virtual..

Does the original website in /var/www/html work without becoming a virtual domain of it's own?

At the moment the only was I can get it working is instead of having one virtual domain and the original site... is to have two virtual domains.
 
Old 06-01-2014, 06:09 AM   #8
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Sorry Jon, we're about 1 question behind each other at this point....

Quote:
does the virtual host domain configuration override the default configuration
No, if you dug a little deeper into Apache configuration you'd realize all your really doing at this point is binding domains for a single Apache server, it runs on a single configuration (it loads 1 set of modules, for example).
I don't know why you had to list it twice to work, I've never had that problem.
 
Old 06-01-2014, 06:16 AM   #9
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
I don't have to list the same site twice.. the virtual one and the original one.

I understand that they share the config.

The config untouched points to /var/www/html.

But when I add a different virtual site, looking for example /www/virtual.. the config forgets that it also has a site at /var/www/html
 
Old 06-01-2014, 06:30 AM   #10
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Quote:
when I add a different virtual site, looking for example /www/virtual.. the config forgets that it also has a site at /var/www/html
Oh, it's because when you added the second domain they both became virtual domains from the servers point of view.Also you have the virtual domain not as a domain but as a sub domain by using the x.y.com format.

I notice Apache is calling them virtual hosts... I never noticed that before
Quote:
# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/example
ServerName www.example.com

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/virtualexample
ServerName www.virtualexample.org

# Other directives here

</VirtualHost>

Last edited by dijetlo; 06-01-2014 at 06:34 AM.
 
Old 06-01-2014, 06:40 AM   #11
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
Ah right that answers it.

So when you make a virtual host, both hosts become virtual and therefore the original one must be re-added as a virtual host also.

I just don't remember configuring it this was on the Red Hat course... but what I've done is right then awesome
 
Old 06-01-2014, 06:44 AM   #12
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Yeah except avoid that www.somedomain.com and the www.jon.somedomain.com thing. That's not a different domain as far as the servers are concerned, it a subdivision of one domain. Make sure you use root domain names and you should be fine.
Edit: One last suggestion and I'll stop pestering you.

If I have to talk about the machine that has the webserver running on it that hosts a virtual domain, I don't ever call it a virtual host. That means something else entirely these days. I'd call it the host for the virtual domain. If you call it a virtual host you'll confuse the heck out of people.

Good luck, you appear to be doing fine in your preparation

Last edited by dijetlo; 06-01-2014 at 07:09 AM.
 
Old 06-01-2014, 08:14 AM   #13
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
Thanks for your help, I understand it much better now.

Thanks again.
 
Old 06-01-2014, 10:00 AM   #14
potato_farmer
Member
 
Registered: May 2014
Posts: 55

Rep: Reputation: Disabled
A host for a virtual domain? I am sorry dijetlo but I think you may have been given some bad information. This has nothing to do with sub domain, domains, or virtualization.

Johnnybinthemix, to answer your question...

When you use Name-based virtual hosts, the first defined virtual host acts as a catch-all (or default host) for ALL hostnames that 1) resolve to the server and 2) do not have their own virtual host entries. You should always define a default virtual host that points to your server to act as a catch-all if you have multiple domains that resolve to the server's IP (maybe for different services), but lack a virtual host for each domain (since not all domains may need web services).

From Apache:
Quote:
Now when a request arrives, the server will first check if it is using an IP address that matches the NameVirtualHost. If it is, then it will look at each <VirtualHost> section with a matching IP address and try to find one where the ServerName or ServerAlias matches the requested hostname. If it finds one, then it uses the configuration for that server. If no matching virtual host is found, then the first listed virtual host that matches the IP address will be used.

As a consequence, the first listed virtual host is the default virtual host. The DocumentRoot from the main server will never be used when an IP address matches the NameVirtualHost directive. If you would like to have a special configuration for requests that do not match any particular virtual host, simply put that configuration in a <VirtualHost> container and list it first in the configuration file.

Source: http://httpd.apache.org/docs/2.2/vhosts/name-based.html
Also, the correct term to use for Apache Virtual Host entries are "virtual hosts". This has nothing to do with a Virtualization, virtual machine servers, virtual machine guests, etc.

Hope that helps.
 
1 members found this post helpful.
Old 06-01-2014, 12:52 PM   #15
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Quote:
I am sorry dijetlo but I think you may have been given some bad information
No, that's basically what I was trying to explain to him, without being concerned about a "Default" virtual domain since he doesn't have a real domain, as is evidenced by his example.com reference. You're overthinking what he did, he's not a server in the example.com domain serving internal pages on the default domain while hosting a virtual domain externally ( a common configuration), he's emulating a web server that doesn't serve web pages on it's own domain (an internet web server, for example, without an inward facing port). He doesn't want to involve his domain settings because if you actually walked up to the machine and typed $HOSTNAME into the terminal it might say somethng like "D1QW8UHU.nodenet.pri".
Quote:
Also, the correct term to use for Apache Virtual Host entries are "virtual hosts". This has nothing to do with a Virtualization, virtual machine servers, virtual machine guests, etc.
Apache can call it what they like, the virtual host in the modern IT environment is the machine hosting guest machines virtually, not a server answering more than one doorbell. That's a virtual domain server or more commonly the "the web server". You need to remember Jon prefaced the conversation with "I'm retaking my RHEL exam" which indicates he needs to get comfortable with how RHEL assigns nomenclature to this stuff, not how Apache does it.

Last edited by dijetlo; 06-01-2014 at 01:18 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about Suse, Apache and Apache's "Threads" mechanism wessie Linux - General 0 07-28-2006 03:31 AM
Apache Question Verbal Kint Linux - Software 4 09-28-2005 12:20 PM
apache question plisken Linux - Software 3 03-09-2004 10:26 AM
Apache question again....... deepsix Linux - Software 3 09-05-2003 12:09 PM
Apache 2.0 question deepsix Linux - Software 10 08-29-2003 07:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration