Jump to content

[SOLVED] Virtual hosts. really need some help.


lynxus

Recommended Posts

Hi guys,

I have an apache server running a few sites ( not using vhsosts ) but another provider just forwards whatever site request to x.x.x.x/sitename/index.html

 

anyway.

 

I now have a site that has an a record pointing to me.

 

I need to setup a vhost for this domain but if the request isnt from that domain i need the server to continue serving pages as if they were direct requests..

 

How do i do this?

 

Thisis what i have:

 

NameVirtualHost *:80

 

 

<VirtualHost domain.com:80>

        ServerName www.domain.com

        ServerAlias domain.com

        DocumentRoot /var/www/html/domainname

</VirtualHost>

 

 

 

 

Thanks

G

Link to comment
Share on other sites

I need to setup a vhost for this domain but if the request isnt from that domain

This does not make sense. Please elaborate.

Virtual hosting just allows multiple websites to use the same IP Address (A record) and are served from unique document roots.

Link to comment
Share on other sites

Ok, what i have is...

 

domain1.com

domain2.com

domain3.com

 

domain1 and 2, have a forward setup by my provider so if someone goes to domain1.com they actaully goto http://ipaddress/domain1/index.html

 

However i now have domain3 that i have A records for.

 

So domain3 has an A record of the ipaddress.

 

if i browse to domain3 i just get the main html fil in the normal dir on the webserver.

 

So for domain3 i need people who come from that site to goto ipaddress/domain3/index.html

 

How do i tell apache to do this for domain3 but if anyone directly requests ipaddress/somedir/blaa.zip it will let them.

 

Link to comment
Share on other sites

So right now for domain1 and domain2 you are sharing an IP address?

 

if I typed in domain1.com or domain2.com I'd be directed to 1.2.3.4/domain1 or 1.2.3.4/domain2 right?

 

The problem is if you add an additional site domain3 in Apache you'll need to set it as 1.2.3.4:80 which means 1.2.3.4 on port 80 will have a web root of whatever you specify in the docroot.

 

If you follow this path then domain1 and domain2 will essentially become subfolders of domain3.

 

To keep your existing set up and add the record for domain3 you'll need to either add host names for domain1 and domain2 or get an additional IP address for domain3

Link to comment
Share on other sites

Actually I take it back.. I've been thinking about it and you should actually be fine.

 

The first container will be all sites that resolve to IP address that have no ServerName or ServerAlias entries.

 

The second container is specifically for domain.com which is IP on port 80

 

<VirtualHost <IP>:80>

        # The primary configuration for the site.

        DocumentRoot /var/www/html/

</VirtualHost>

 

<VirtualHost domain.com:80>

        ServerName www.domain.com

        ServerAlias domain.com

        DocumentRoot /var/www/html/domainname

</VirtualHost>

Link to comment
Share on other sites

Humm.

I get this error when i restart httpd

 

 

[Wed Jun 03 19:13:17 2009] [warn] NameVirtualHost *:80 has no VirtualHosts

 

And it doesnt work.

Any ideas?

 

if i hash out NameVirtualHost *:80

still nothing

 

Heres the config for that section.

#

# Use name-based virtual hosting.

#

NameVirtualHost *:80

#

# NOTE: NameVirtualHost cannot be used without a port specifier

# (e.g. :80) if mod_ssl is being used, due to the nature of the

# SSL protocol.

#

 

#

# 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 logs/dummy-host.example.com-error_log

#    CustomLog logs/dummy-host.example.com-access_log common

#</VirtualHost>

 

<VirtualHost 212.125.94.xxx:80>

        # The primary configuration for the site.

        DocumentRoot /var/www/html

</VirtualHost>

 

<VirtualHost blaa.com:80>

        ServerName www.blaa.com

        ServerAlias blaa.com

        DocumentRoot /var/www/html/blaaa

</VirtualHost>

Link to comment
Share on other sites

Humm ok,

 

I tried that and then nothing works.

 

The code is:

<VirtualHost 212.125.94.168:80>

        # The primary configuration for the site.

        DocumentRoot /var/www/html

</VirtualHost>

 

<VirtualHost imsupporting.com:80>

        ServerName www.imsupporting.com

        ServerAlias imsupporting.com

        DocumentRoot /var/www/html/imsupporting

</VirtualHost>

 

 

When i restart httpd i get this message:

[Thu Jun 04 09:29:07 2009] [warn] VirtualHost 212.125.94.168:80 overlaps with VirtualHost imsupporting.com:80, the first has precedence, perhaps you need a NameVirtualHost directive

 

 

 

 

 

Link to comment
Share on other sites

Humm hasnt helped much.

 

Every attempt i make just fails.

 

it either points all traffic to a vhost all none at all.

Really i just want.

 

Traffic for blaa.com to goto /var/www/html/blaa

and all other traffic not or blaa.com to goto /var/www/html

 

Hummmmm

 

Link to comment
Share on other sites

Humm hasnt helped much.

 

Every attempt i make just fails.

 

it either points all traffic to a vhost all none at all.

Really i just want.

 

Traffic for blaa.com to goto /var/www/html/blaa

and all other traffic not or blaa.com to goto /var/www/html

 

Hummmmm

 

 

You cannot have one vhosts root within another vhosts root. other than that, there should be no problems doing what you want.

 

The first vhost you define becomes the default, so it will catch any request not specified in the second vhost.

Link to comment
Share on other sites

Ive managed to fix it.

Heres what i have:

 

<VirtualHost *>

    DocumentRoot /var/www/html

</VirtualHost>

 

<VirtualHost *>

    DocumentRoot /var/www/html/imsupporting/mainsite

    ServerName www.imsupporting.com

    ServerAlias imsupporting.com

</VirtualHost>

 

 

Thanks for your help yall .

This is a great site.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.