Click to See Complete Forum and Search --> : confused about virtual hosting


ruwach
01-30-2005, 02:39 AM
hey there, i have checked the forums and all the docs at apache, but i cant find out what i am doing wrong.

i want to host two domains from this one computer with only one connection to the internet.
they are registered at Godaddy and i am using zoneedit to do the dns thing. so they are all comming to one ip.

so here is what i have in httpd.conf

listen 80

NameVirtualHost *:80

</VirtualHost *:80>
ServerName www.site1.org
DoccumentRoot /home/httpd/html/site1
</VirtualHost>

</VirtualHost *:80>
ServerName www.site2.com
DoccumentRoot /home/httpd/html/site2
</VirtualHost>

in the /home/httpd/html/ dirrectory i have two folders site1 and site2 with the index files in each.

i can open a browser and go to www.site1.org and loads up nice,
but when i try to go to site2, it tells me the server refused the connection.

any ideas ?
thanks

ReaperT2
01-30-2005, 02:41 AM
your setup is exactly the same as mine, and i had it working using a guid i once found. I dont have the computer "setup" atm because im fighting with nix lol. If you give me a few minutes ill try my darndest to find the guide for you!

ReaperT2
01-30-2005, 02:43 AM
heres the few i used

http://www.apacheweek.com/features/vhost

http://httpd.apache.org/docs/vhosts/name-based.html

http://www.devshed.com/c/a/Apache/Configuring-and-Using-Virtual-Hosts-in-Apache/

Hope they help!

psi42
01-30-2005, 03:20 AM
Originally posted by ruwach

</VirtualHost *:80>

Should be


<VirtualHost *:80>

ruwach
01-30-2005, 10:06 AM
still refusing my connection to site 2.
when i try to restart httpd, it fails. and it fails when i try to restart it. but it still serves site 1
weier, nothing in the error log either. its blank

welmers
01-30-2005, 10:45 AM
Are you sure www.site1.org and www.site2.org are pointing to the same server?


listen 80

NameVirtualHost *:80

</VirtualHost *:80>
ServerName www.site1.org
DoccumentRoot /home/httpd/html/site1
</VirtualHost>

</VirtualHost *:80>
ServerName www.site2.com
DoccumentRoot /home/httpd/html/site2
</VirtualHost>


You should add an extra empty <VirtualHost *:80></VirtualHost> container for the default virtual host. If you don't, your webserver always returns the first VirtualHost when a undefined hostname is used.
Place this empty container directly after NameVirtualHost directive.

To find out what's going wrong, try:


telnet www.site1.org 80
>> Trying ::1...
>> telnet: connect to address ::1: Connection refused
>> Trying 127.0.0.1...
>> Connected to localhost.
>> Escape character is '^]'.
>>
GET / HTTP/1.0
host: www.site1.org


Note the extra CR you have to type after the host line to make the server understand you're done with the headers.

You should get the HTML contents of the site.

Do the same for www.site2.org and tell us what happens.


when i try to restart httpd, it fails. and it fails when i try to restart it.


sounds all of being something wrong with apache. What platform are you using and how's apache installed? (From source, or package...)

ruwach
01-30-2005, 11:15 AM
i am using arch linux.
installed apache from the binary.
every thing worked fine untill i tried to add another domain to it. still works with site1 ok.
i will check out your suggestions
and respond in a minute

ruwach
01-30-2005, 12:22 PM
yep - the dns is pointed out right.

i commented out with # all entries regarding virtual hosting.
i then moved the index file from
/home/httpd/html/site2 and put it into
/home/httpd/html

opened firefox and went to www.site2.com and there it was !

i do not know what tel-net is

when i did the /etc/rc.d/http restart, it did not fail.
so i have something awry in me ol http.conf regarding virtual hosting.

here is what i have in http.conf right now

#
<IfModule !mpm_winnt.c>
<IfModule !mpm_netware.c>
#LockFile /var/log/httpd/accept.lock
</IfModule>
</IfModule>

<IfModule !mpm_netware.c>
<IfModule !perchild.c>
#ScoreBoardFile /var/log/httpd/apache_runtime_status
</IfModule>
</IfModule>

<IfModule !mpm_netware.c>
PidFile /var/run/httpd.pid
</IfModule>

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 15

<IfModule prefork.c>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>

<IfModule worker.c>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>

<IfModule perchild.c>
NumServers 5
StartThreads 5
MinSpareThreads 5
MaxSpareThreads 10
MaxThreadsPerChild 20
MaxRequestsPerChild 0
</IfModule>

<IfModule mpm_winnt.c>
ThreadsPerChild 250
MaxRequestsPerChild 0
</IfModule>

<IfModule beos.c>
StartThreads 10
MaxClients 50
MaxRequestsPerThread 10000
</IfModule>

<IfModule mpm_netware.c>
ThreadStackSize 65536
StartThreads 250
MinSpareThreads 25
MaxSpareThreads 250
MaxThreads 1000
MaxRequestsPerChild 0
</IfModule>

<IfModule mpmt_os2.c>
StartServers 2
MinSpareThreads 5
MaxSpareThreads 10
MaxRequestsPerChild 0
</IfModule>

Listen 80

LoadModule access_module lib/apache/mod_access.so
LoadModule actions_module lib/apache/mod_actions.so
LoadModule alias_module lib/apache/mod_alias.so
LoadModule asis_module lib/apache/mod_asis.so
LoadModule auth_module lib/apache/mod_auth.so
LoadModule auth_anon_module lib/apache/mod_auth_anon.so
LoadModule auth_dbm_module lib/apache/mod_auth_dbm.so
LoadModule auth_digest_module lib/apache/mod_auth_digest.so
LoadModule autoindex_module lib/apache/mod_autoindex.so
LoadModule cgi_module lib/apache/mod_cgi.so
LoadModule dav_module lib/apache/mod_dav.so
LoadModule dav_fs_module lib/apache/mod_dav_fs.so
LoadModule dir_module lib/apache/mod_dir.so
LoadModule env_module lib/apache/mod_env.so
LoadModule expires_module lib/apache/mod_expires.so
LoadModule ext_filter_module lib/apache/mod_ext_filter.so
LoadModule headers_module lib/apache/mod_headers.so
LoadModule imap_module lib/apache/mod_imap.so
LoadModule include_module lib/apache/mod_include.so
LoadModule info_module lib/apache/mod_info.so
LoadModule log_config_module lib/apache/mod_log_config.so
LoadModule mime_module lib/apache/mod_mime.so
LoadModule negotiation_module lib/apache/mod_negotiation.so
LoadModule rewrite_module lib/apache/mod_rewrite.so
LoadModule setenvif_module lib/apache/mod_setenvif.so
LoadModule speling_module lib/apache/mod_speling.so
LoadModule ssl_module lib/apache/mod_ssl.so
LoadModule status_module lib/apache/mod_status.so
LoadModule userdir_module lib/apache/mod_userdir.so
LoadModule vhost_alias_module lib/apache/mod_vhost_alias.so
#LoadModule php5_module lib/apache/libphp5.so

<IfModule !mpm_winnt.c>
<IfModule !mpm_netware.c>
User nobody
Group #-1
</IfModule>
</IfModule>

ServerAdmin me@isp.net

UseCanonicalName Off

DocumentRoot "/home/httpd/html"

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

<Directory "/home/httpd/html">

Options Indexes FollowSymLinks

AllowOverride None

Order allow,deny
Allow from all

</Directory>

UserDir public_html

<IfModule mod_php5.c>
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>

DirectoryIndex index.html index.html.var

AccessFileName .htaccess

<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>

TypesConfig /etc/httpd/conf/mime.types

DefaultType text/plain

<IfModule mod_mime_magic.c>
MIMEMagicFile /etc/httpd/conf/magic
</IfModule>

HostnameLookups Off

http://httpd.apache.org/docs-2.0/mod/core.html#enablemmap

ErrorLog /var/log/httpd/error_log

LogLevel warn

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
\"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

ServerTokens Prod

ServerSignature On

Alias /icons/ "/home/httpd/icons/"

<Directory "/home/httpd/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

ScriptAlias /cgi-bin/ "/home/httpd/cgi-bin/"

<IfModule mod_cgid.c>
</IfModule>

<Directory "/home/httpd/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

IndexOptions FancyIndexing VersionSort

AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip

DefaultIcon /icons/unknown.gif

ReadmeName README.html
HeaderName HEADER.html

IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

ForceLanguagePriority Prefer Fallback

AddType application/x-tar .tgz
AddType image/x-icon .ico

BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0

BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[012]" redirect-carefully
BrowserMatch "^gnome-vfs" redirect-carefully

<IfModule mod_ssl.c>
Include /etc/httpd/conf/ssl.conf
</IfModule>

### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.0/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog /var/log/httpd/dummy-host.example.com-error_log
# CustomLog /var/log/httpd/dummy-host.example.com-access_log common

#<VirtualHost *:80>
#ServerName www.site2.com
#ServerAlias *.site2.com
#DoccumentRoot /home/httpd/html/site2
# <Directory "/home/httpd/html/site2">
# Options - Indexes +FollowSymLinks
# AllowOverride Options Indexes AuthConfig
# Order allow,deny
# Allow from all
# </Directory>
#</VirtualHost>

#<VirtualHost *:80>
#ServerName www.site1.org
#ServerAlias *.site1.org
#DoccumentRoot /home/httpd/html/site1
# <Directory "/home/httpd/html/site1">
# Options - Indexes +FollowSymLinks
# AllowOverride Options Indexes AuthConfig
# Order allow,deny
# Allow from all
# </Directory>
#</VirtualHost>


except for some stuff about languages and icons, didnt feel like that part mattered for this.

please advise
and thanks

psi42
01-30-2005, 02:19 PM
You can run apachectl configtest, and it will tell you where your syntax errors exist.

You can get telnet by just typing "telnet" at the shell prompt. If you haven't got telnet installed, well, your distro has issues... :)

Try:


<VirtualHost *:80>
ServerName www.site1.org
ServerAlias site1.org
DocumentRoot "/var/www/htdocs/site1"
</VirtualHost>


That _will_ work...

ruwach
01-30-2005, 03:18 PM
i got a syntax error
it says <virtualhost> not closed

yep my distro has issues./
there are a couple of telnet packages available.
dont know exactly which i should install
thanks
how do i close <virtualhost> ?

bsm2001
01-30-2005, 03:45 PM
</virtualhost>


looks like this is the 1
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog /var/log/httpd/dummy-host.example.com-error_log
# CustomLog /var/log/httpd/dummy-host.example.com-access_log common

ruwach
01-30-2005, 03:52 PM
Hey its fixed.
thank you so much

that apachectl configtest was the key
(and some research on the apache docs page to see where it was boinked)

thanks a million !