LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Virtual host apache2 (https://www.linuxquestions.org/questions/linux-newbie-8/virtual-host-apache2-760712/)

duxbuz 10-09-2009 01:44 AM

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

chrism01 10-09-2009 01:57 AM

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.

r3sistance 10-09-2009 02:02 AM

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

lutusp 10-09-2009 02:05 AM

Quote:

Originally Posted by duxbuz (Post 3713128)
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.

duxbuz 10-09-2009 02:47 AM

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

eth1 10-09-2009 02:54 AM

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,

duxbuz 10-09-2009 02:54 AM

*: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?

John VV 10-09-2009 02:55 AM

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/

duxbuz 10-09-2009 03:22 AM

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

duxbuz 10-09-2009 03:38 AM

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

jmc1987 10-09-2009 03:44 AM

If you ever decide to use a control panel for ease admin and user use. You can install webmin and virtuemin. Just a suggestion.

duxbuz 10-09-2009 04:51 AM

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

r3sistance 10-09-2009 01:53 PM

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


All times are GMT -5. The time now is 08:39 PM.