lynxus Posted June 3, 2009 Share Posted June 3, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160790-solved-virtual-hosts-really-need-some-help/ Share on other sites More sharing options...
JonnoTheDev Posted June 3, 2009 Share Posted June 3, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160790-solved-virtual-hosts-really-need-some-help/#findComment-848664 Share on other sites More sharing options...
lynxus Posted June 3, 2009 Author Share Posted June 3, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160790-solved-virtual-hosts-really-need-some-help/#findComment-848674 Share on other sites More sharing options...
ldougherty Posted June 3, 2009 Share Posted June 3, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160790-solved-virtual-hosts-really-need-some-help/#findComment-848678 Share on other sites More sharing options...
lynxus Posted June 3, 2009 Author Share Posted June 3, 2009 Damn. So theres no way to say. if someone comes from domain3.com then goto thisdir. otherwise any other request use the normal /var/www/html root? Quote Link to comment https://forums.phpfreaks.com/topic/160790-solved-virtual-hosts-really-need-some-help/#findComment-848685 Share on other sites More sharing options...
ldougherty Posted June 3, 2009 Share Posted June 3, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/160790-solved-virtual-hosts-really-need-some-help/#findComment-848704 Share on other sites More sharing options...
lynxus Posted June 3, 2009 Author Share Posted June 3, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/160790-solved-virtual-hosts-really-need-some-help/#findComment-848707 Share on other sites More sharing options...
ldougherty Posted June 3, 2009 Share Posted June 3, 2009 What happens if you replace 212.125.94.xxx:80 with *:80 I ran the same code on my web server and it worked fine. Quote Link to comment https://forums.phpfreaks.com/topic/160790-solved-virtual-hosts-really-need-some-help/#findComment-848723 Share on other sites More sharing options...
lynxus Posted June 4, 2009 Author Share Posted June 4, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160790-solved-virtual-hosts-really-need-some-help/#findComment-849079 Share on other sites More sharing options...
JonnoTheDev Posted June 4, 2009 Share Posted June 4, 2009 http://forums.theplanet.com/index.php?showtopic=79287 Quote Link to comment https://forums.phpfreaks.com/topic/160790-solved-virtual-hosts-really-need-some-help/#findComment-849083 Share on other sites More sharing options...
lynxus Posted June 4, 2009 Author Share Posted June 4, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160790-solved-virtual-hosts-really-need-some-help/#findComment-849119 Share on other sites More sharing options...
trq Posted June 4, 2009 Share Posted June 4, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160790-solved-virtual-hosts-really-need-some-help/#findComment-849121 Share on other sites More sharing options...
lynxus Posted June 4, 2009 Author Share Posted June 4, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160790-solved-virtual-hosts-really-need-some-help/#findComment-849131 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.