Author |
|
Ang3lus
Joined: 02 Aug 2010 Posts: 18
|
Posted: Sun 12 Sep '10 12:08 Post subject: Vhost |
|
|
Hi
I want to create 2 name based virtual host on single server
for example: the first hostname is: site1.com
the second one is: site2.com
i read apache2 doc and i tried to follow steps correctly
However, when i try to access any site via browser it gave me error page: Server not found
===============
from httpd.conf file:
ServerName my servername.net:80
ServerAdmin admin@localhost
DocumentRoot "/home/www"
NameVirtualHost *:80
<VirtualHost *:80>
ServerName site1.com
DirectoryIndex index.html
DocumentRoot "/home/site1"
</VirtualHost>
<VirtualHost *:80>
ServerName site2.com
DocumentRoot "/home/site2"
</VirtualHost>
I can't access : site1.com or site2.com via browser
only i can access main server
there are something wrong with these configurations
from apache documentation . i can't understand this point:
Name-based virtual hosting is usually simpler, since you need only configure your DNS server to map each hostname to the correct IP address and then configure the Apache HTTP Server to recognize the different hostnames
any help would be appreciated
thanks |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Sun 12 Sep '10 18:51 Post subject: |
|
|
First vhost needs to be a minor duplicate of the main host (servername.net)
So, for the first vhost
<VirtualHost _default_:80>
DocumentRoot "/home/www"
</VirtualHost>
with site1.com and site2.com vhosts below it
It's explained in the name based docs under the heading "Main host goes away" but is known to show itself differently for different people. In your case main host shows the vhosts don't. |
|
Back to top |
|
Ang3lus
Joined: 02 Aug 2010 Posts: 18
|
Posted: Tue 14 Sep '10 7:23 Post subject: |
|
|
thanks for your replay glsmith
i figured out my problem. i need to add entries to dns
there is another possible way to achieve virtual host without dns entries cause iam not run sever as root |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Tue 14 Sep '10 17:54 Post subject: |
|
|
if you are just running it locally use the hosts file, not sure where it is in *nix but I'm sure someone here knows. If you want it to answer to the outside world, dns or a lot of IPs is going to be needed. Server should not need to be run as root in either case. Never run it as root. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Tue 14 Sep '10 23:31 Post subject: |
|
|
glsmith wrote: | not sure where it is in *nix but I'm sure someone here knows. |
/etc/hosts
On most system
Code: |
sudo nano /etc/hosts
|
Different to windows, if you wanna use more than one hostname to 127.0.0.1 add them in a row
e.g.
Code: |
127.0.0.1 computername localhost vhost1.local vhost2.local
|
|
|
Back to top |
|
Ang3lus
Joined: 02 Aug 2010 Posts: 18
|
Posted: Thu 16 Sep '10 7:00 Post subject: |
|
|
thanks for your help guys
it works fine locally from hosts file
another question:
if i have Document root path for example is: /var/home/htdocs
and the server name for exampe is: apacheserver.net
is possible to add link to my server as following:
htdocs.apachesever.net
sorry for bad explain i am just beginner
thanks |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Thu 16 Sep '10 11:39 Post subject: |
|
|
You think of a vhost for each user or just an alias for that domain? |
|
Back to top |
|
Ang3lus
Joined: 02 Aug 2010 Posts: 18
|
Posted: Fri 17 Sep '10 16:22 Post subject: |
|
|
Many thanks for you guys
I want to use it as alias and its work now fine
thanks again |
|
Back to top |
|