LinuxQuestions.org
Visit Jeremy's Blog.
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 10-09-2009, 01:44 AM   #1
duxbuz
LQ Newbie
 
Registered: Oct 2009
Posts: 7

Rep: Reputation: 0
Virtual host apache2


Hi,

trying to get a virtualhost working on apache2.

The thing being its only on a local network so when it comes to the naming convention i am lost.

It seems all the examples show live websites e.g. www.example.com, www.example2.com

I am basically trying to use the same ip address on my server called penguin. then i want a second server called something else on the same ip.

Seems that people can do this, but i really dont understand all the many examples i have read.

Anyone help plz
 
Old 10-09-2009, 01:57 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,352

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If its purely for internal consumption, you can call it anything you like, although you'll need an equiv entry in /etc/hosts so the browser can find it, or a local DNS server.
Personally, like the fact that you should only use private ip ranges for this eg 192.168.x.x I (and others) also create fictitious domain names, so it's obvious if it escapes onto the internet it will get dropped instead of ending up at a real (not yours) website.
eg
site1.domain.cxm # note cxm is not a valid tld on the web.
YMMV

If this is for work (even if its only internal), you should get a proper name.
 
Old 10-09-2009, 02:02 AM   #3
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
Hi,

First thing with hosting a virtual host, if you are using multiple different domain names, if I remember right you have to uncomment the following line in the httpd.conf file, I can't remember this for certain if it's this line, there is certainly one line it has to be done but from memory it should look like the following.

#NameVirtualHost *:80

Just delete the #, you may possible want to change the listen port if it's not going to be port 80. After this you then you set up your virtual host something like the following substituting the <> for what ever needs to go there

Code:
<VirtualHost *:80>
        DocumentRoot <directory in file system where site is>
        ServerName <main domain ie example.com>
        ServerAlias <alternative domains ie www.example.com example2.com>
</VirtualHost>
if you want it to listen on a specific IP change the *:80 to the ip:80 ie 127.0.0.1:80

Last edited by r3sistance; 10-09-2009 at 02:10 AM.
 
Old 10-09-2009, 02:05 AM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by duxbuz View Post
Hi,

trying to get a virtualhost working on apache2.

The thing being its only on a local network so when it comes to the naming convention i am lost.

It seems all the examples show live websites e.g. www.example.com, www.example2.com

I am basically trying to use the same ip address on my server called penguin. then i want a second server called something else on the same ip.

Seems that people can do this, but i really dont understand all the many examples i have read.

Anyone help plz
To create a locally accessible virtual server, add something like this to /etc/httpd/conf/httpd.conf:

Code:
listen 8010

<VirtualHost *:8010>
    DocumentRoot /path/to/html/files
</VirtualHost>
Access the virtual server like this:

Code:
http://(name or ip of host):8010
If the host uses a local-only IP (like 192.168.*.*), the server will be limited to intranet use -- I think this is what you want.

You can create as many such virtual servers as you like, each with a different access port. This method using different access ports is by far the simplest way to create virtual servers, which explains why it's used so often.
 
Old 10-09-2009, 02:47 AM   #5
duxbuz
LQ Newbie
 
Registered: Oct 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks for that. I will try it.

The other method i cant get my head round, cause even if i had a dns entry for penguin = 10.101.22.254 then had penguin2 = 10.101.22.254 how could that work?

Anyhows will try the port thing
 
Old 10-09-2009, 02:54 AM   #6
eth1
Member
 
Registered: May 2008
Posts: 97

Rep: Reputation: 20
Even though both the VirtualHost containers are using the same IP address (NameBased VirtualHosting), Apache web server checks the Hostname/domain name in the HTTP header and shows the loads/parses the corresponding index page from the respective VirtualHost DocumentRoot.

You can check the following documentation page for better understanding and more information,
 
Old 10-09-2009, 02:54 AM   #7
duxbuz
LQ Newbie
 
Registered: Oct 2009
Posts: 7

Original Poster
Rep: Reputation: 0
*:8010 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported

Hmm got this error whilst trying to restart apache.

I am thinking the other server instances need ports fixing rather than using any?
 
Old 10-09-2009, 02:55 AM   #8
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,623

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
have you read the apache docs for this .i found them VERY helpful 6 years ago when i set up my first server
and still do use them .
http://httpd.apache.org/docs/2.2/vhosts/
 
Old 10-09-2009, 03:22 AM   #9
duxbuz
LQ Newbie
 
Registered: Oct 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Ye I read that page. Not very useful good really.

Am getting somewhere. I use the port mapping idea but the thing being it takes me to the same document root as the original server.

I have changed the documentroot on the virtual host... but not getting that htdocs folder content. tut
 
Old 10-09-2009, 03:38 AM   #10
duxbuz
LQ Newbie
 
Registered: Oct 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Ok got it.

Had to remove the default entries in sites-enabled and sites-available for my VirtualHost to work

Err actually DONT delete these files. I had a bit of an issue since doing so.

Give me a moment

Last edited by duxbuz; 10-09-2009 at 04:32 AM.
 
Old 10-09-2009, 03:44 AM   #11
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7/10
Posts: 893

Rep: Reputation: 119Reputation: 119
If you ever decide to use a control panel for ease admin and user use. You can install webmin and virtuemin. Just a suggestion.
 
Old 10-09-2009, 04:51 AM   #12
duxbuz
LQ Newbie
 
Registered: Oct 2009
Posts: 7

Original Poster
Rep: Reputation: 0
It seems that webmin was creating files in sites-available but missing top line





<VirtualHost *:80>
etc
etc

needed

NameVirtualHost *:80
<VirtualHost *:80>
etc
etc
 
Old 10-09-2009, 01:53 PM   #13
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
That's why I mentioned that darned line before, nothing more fun then having to hunt through documents just to find you need that line uncommented and active! Gotta love reading all the way through such a large file as the httpd.conf
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Apache2 virtual host. hgb Linux - Networking 10 01-24-2009 02:05 AM
Apache2 Virtual host on LAN jordankoppole Linux - Software 4 10-16-2007 09:57 AM
apache2 help -Virtual Host- Fredstar *BSD 4 06-06-2005 01:09 PM
Can't do Apache2 virtual host different ports SK_pt Linux - Software 3 01-30-2005 07:04 PM
apache2, virtual host problems rjcrews Linux - Software 13 05-25-2004 08:16 PM

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

All times are GMT -5. The time now is 10:45 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