Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Virtual Hosts - Always going to the first one?

Status
Not open for further replies.

grande

Programmer
Feb 14, 2005
657
0
0
CA
Okay, first of all, I don't know what I'm doing. This isn't what I normally do, I'm a developer. However, I'm the best we've got at the time (long story...)

So, here's what I'm trying to do. We have a DNS record for stage.mydomain.com and dev.mydomain.com. I've edited an existing httpd.conf to try and have them both (beforehand, it only had a record for stage). I've tried following different tutorials, but the problem keeps persisting. It's continually just going to the first record.

Notes:
- I currently have both versions working on localhost. Stage is on port 80, dev is on 82.
- The httpd.conf is listening on Port 81. I don't know why, but if I remove this line, things break.

Can anyone offer any insight?

Code:
ServerType standalone
ServerRoot "${path}/apache"
PidFile logs/httpd.pid
ScoreBoardFile logs/apache_runtime_status
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
MaxRequestsPerChild 0
ThreadsPerChild 50

Listen 81
Listen <external ip address>:81

LoadModule rewrite_module modules/mod_rewrite.so
LoadModule anon_auth_module modules/mod_auth_anon.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule php4_module "${path}/php/php4apache.dll"

ClearModuleList
AddModule mod_env.c
AddModule mod_log_config.c
AddModule mod_mime.c
AddModule mod_negotiation.c
AddModule mod_include.c
AddModule mod_autoindex.c
AddModule mod_dir.c
AddModule mod_isapi.c
AddModule mod_cgi.c
AddModule mod_asis.c
AddModule mod_imap.c
AddModule mod_actions.c
AddModule mod_userdir.c
AddModule mod_alias.c
AddModule mod_rewrite.c
AddModule mod_access.c
AddModule mod_auth.c
AddModule mod_auth_anon.c
AddModule mod_proxy.c
AddModule mod_so.c
AddModule mod_setenvif.c
AddModule mod_php4.c

Port 81

ServerAdmin admin@localhost

<Directory />
    Options FollowSymLinks Indexes
    AllowOverride All
</Directory>

<IfModule mod_userdir.c>
    UserDir "${path}/apache/users/"
</IfModule>

<IfModule mod_dir.c>
    DirectoryIndex index.html index.shtml index.wml index.pwml index.php index.php3 index.php4
</IfModule>

AccessFileName .htaccess

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

UseCanonicalName Off

<IfModule mod_mime.c>
    TypesConfig conf/mime.types
</IfModule>

DefaultType text/plain

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

HostnameLookups Off

ErrorLog logs/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

CustomLog logs/access.log common

ServerSignature Email

<IfModule mod_alias.c>

    Alias /icons/ "${path}/apache/icons/"

    <Directory "${path}/apache/icons">
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>


    Alias /images_easyphp/ "${path}/home/images_easyphp/"

    <Directory "${path}/home/images_easyphp">
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>


    Alias /mysql/ "${path}/phpmyadmin/"

    <Directory "${path}/phpmyadmin">
        Options FollowSymLinks Indexes
        AllowOverride None
        Order deny,allow
        allow from 127.0.0.1
        deny from all
    </Directory>


    Alias /help/ "${path}/help/"

    <Directory "${path}/help">
        Options FollowSymLinks Indexes
        AllowOverride None
        Order deny,allow
        allow from 127.0.0.1
        deny from all
    </Directory>

    ScriptAlias /cgi-bin/ "${path}/cgi-bin/"

    <Directory "${path}/cgi-bin">
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
    </Directory>

</IfModule>

<IfModule mod_autoindex.c>

    IndexOptions FancyIndexing

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

    AddIconByType (TXT,/icons/text.gif) text/*
    AddIconByType (IMG,/icons/image2.gif) image/*
    AddIconByType (SND,/icons/sound2.gif) audio/*
    AddIconByType (VID,/icons/movie.gif) video/*

    AddIcon /icons/binary.gif .bin .exe
    AddIcon /icons/binhex.gif .hqx
    AddIcon /icons/tar.gif .tar
    AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
    AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
    AddIcon /icons/a.gif .ps .ai .eps
    AddIcon /icons/layout.gif .html .shtml .htm .pdf
    AddIcon /icons/text.gif .txt
    AddIcon /icons/c.gif .c
    AddIcon /icons/p.gif .pl .py
    AddIcon /icons/f.gif .for
    AddIcon /icons/dvi.gif .dvi
    AddIcon /icons/uuencoded.gif .uu
    AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
    AddIcon /icons/tex.gif .tex
    AddIcon /icons/bomb.gif core

    AddIcon /icons/back.gif ..
    AddIcon /icons/hand.right.gif README
    AddIcon /icons/folder.gif ^^DIRECTORY^^
    AddIcon /icons/blank.gif ^^BLANKICON^^

    DefaultIcon /icons/unknown.gif

    AddDescription "GZIP compressed document" .gz
    AddDescription "tar archive" .tar
    AddDescription "GZIP compressed tar archive" .tgz
    AddDescription "ZIP archive" .zip
    AddDescription "CAB archive" .cab
    AddDescription "Win32 Executable" .exe

    ReadmeName README
    HeaderName HEADER

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

</IfModule>

<IfModule mod_mime.c>

    AddEncoding x-compress Z
    AddEncoding x-gzip gz tgz
    
    AddLanguage da .dk
    AddLanguage nl .nl
    AddLanguage en .en
    AddLanguage et .ee
    AddLanguage fr .fr
    AddLanguage de .de
    AddLanguage el .el
    AddLanguage he .he
    AddCharset ISO-8859-8 .iso8859-8
    AddLanguage it .it
    AddLanguage ja .ja
    AddCharset ISO-2022-JP .jis
    AddLanguage kr .kr
    AddCharset ISO-2022-KR .iso-kr
    AddLanguage nn .nn
    AddLanguage no .no
    AddLanguage pl .po
    AddCharset ISO-8859-2 .iso-pl
    AddLanguage pt .pt
    AddLanguage pt-br .pt-br
    AddLanguage ltz .lu
    AddLanguage ca .ca
    AddLanguage es .es
    AddLanguage sv .sv
    AddLanguage cz .cz
    AddLanguage ru .ru
    AddLanguage tw .tw
    AddLanguage zh-tw .tw
    AddCharset Big5         .Big5    .big5
    AddCharset WINDOWS-1251 .cp-1251
    AddCharset CP866        .cp866
    AddCharset ISO-8859-5   .iso-ru
    AddCharset KOI8-R       .koi8-r
    AddCharset UCS-2        .ucs2
    AddCharset UCS-4        .ucs4
    AddCharset UTF-8        .utf8

    <IfModule mod_negotiation.c>
        LanguagePriority en da nl et fr de el it ja kr no pl pt pt-br ru ltz ca es sv tw
    </IfModule>

    AddType application/x-tar .tgz
    AddType image/x-icon .ico
    AddType application/vnd.wap.wmlc .wmlc
    AddType application/x-httpd-php .phtml .pwml .php3 .php4 .php .php2 .inc
    AddType text/vnd.wap.wml .wml
    AddType text/vnd.wap.wmlscript .wmls
    AddType text/vnd.wap.wmlscriptc .wmlsc
    AddType image/vnd.wap.wbmp .wbmp

    AddHandler cgi-script .cgi

    AddType text/html .shtml
    AddHandler server-parsed .shtml

</IfModule>

<IfModule mod_setenvif.c>

    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

</IfModule>

NameVirtualHost *

<VirtualHost *>
    ServerName stage.mydomain.ca
    ProxyPass / [URL unfurl="true"]http://localhost:80/[/URL]
</VirtualHost>

<VirtualHost *>
    ServerName dev.mydomain.ca
    ProxyPass / [URL unfurl="true"]http://localhost:82/[/URL]
</VirtualHost>

Any help at all would be greatly appreciated.

-------------------------
Matt Grande
C# Master.
Ruby on Rails Admirer.
ActionScript Student.
JavaScript Hate-Monger.
 
From reading this, I'm not quite clear what the goal is. So, I have a few questions:
[ol][li]Is this server directly connected to the internet?- if not, Listen <external ip address>:81 is of no value[/li][li]Why are the different ports being used? If port 80 is being blocked, I can understand trying to use 81, but all Named VirtualHosts can listen on the same port[/li][li]What is the reason for the proxypass directives in each virtualhost? I don't think this is really what you want.[/li][/ol]

The traditional way of having several named virtualhosts on an apache server is like this faq65-1831
 
I forgot to mention about the behavior that you're seeing-- With VirtualHosts, when apache receives a request and can not determine [for whatever reason] which VirtualHost should serve the request, it will always use the first VirtualHost listed.
 
First, I don't know what you are doing but you are typing the URL:

and

make double sure (from the browser perspective) those
names match YOURIP. Or consult your accesslog to
see if your request appears there (it better).

In your config, when you disable Port 81 it by default listens on port 80. Since you don't specify a Listen directive, it uses the wildcard * ip address. That clashes with localhost port 80. If your proxy is also using wildcard IP, then it will not bind correctly.

If you restrict the proxies to localhost only, then
restrict your new http to listen on YOURIP:80, then
you can run both on port 80.

Use the netstat -an | grep PORT | grep LIST to
see what ports are listening, like
netstat -an | grep 80 | grep LIST

The wildcard will be like *:80, the specific listens
will be 127.0.0.1:80 and the YOURIP:80.

more later
eugene
 
smah:
1. That's good to know. I've removed that line, and I now just have "Listen 81." Things are still working the way they were.
2. I'm using multiple ports because Mongrel doesn't like serving more than one site per port.
3. I've tried both ProxyPass and DocumentRoot, and gotten the same results. Should I use DocumentRoot instead?

So as per your second post, how do I tell it which site to go to?

elgrandeperro:
Here's what I get when going to the following sites:
--> The stage website.
--> A directory listing of my Ruby on Rails app for stage.
-- The dev website.

I can't grep, I'm on Windows Server 2k3 :(

-------------------------
Matt Grande
C# Master.
Ruby on Rails Admirer.
ActionScript Student.
JavaScript Hate-Monger.
 
Going to the dev site on any port produces the same result as going to the stage site on any port.

-------------------------
Matt Grande
C# Master.
Ruby on Rails Admirer.
ActionScript Student.
JavaScript Hate-Monger.
 
In your http.conf, for each virtual host (well for the second one especially.) that is the exact ServerName you type in for
? That is all that matters, it uses that to match the HTTP header.
eugene
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top