cancel
Showing results for 
Search instead for 
Did you mean: 

Apache setup - Mix of testing & live sites

andun84
Rising Star
Posts: 233
Thanks: 4
Fixes: 1
Registered: ‎01-08-2007

Apache setup - Mix of testing & live sites

I've setup the following:
Apache webserver setup on my home linux build which is setup with virtual hosts for:
Test Website 1 (live site hosted externally - horrbile site built by someone else I just helped the guy move it from his old host)
Test Website 2
Live Website 1 (hosted on my home linux build) & the Test website for this Live Site.
I have configured the hosts file so they resolve all website addresses internally and have configured DNS for the Live Website which I am going to host and I have tested it and it can be accessed from pc's external to my internal network. Port 80 has been opened and forwarded correctly though I guess you got that from my last sentence.
Great I thought however snag in the tail is that if someone were to enter my IP address they are taken to Test Website 1 which shouldn't be public facing. Any ideas how I get anyone entering the ip address of my site to be taken to the Live Website 1 which I'm hosting?
6 REPLIES 6
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: Apache setup - Mix of testing & live sites

Depends a little on the setup, but, if I understand you correctly, you should be able to fix that with a rewrite. Something like
RewriteCond %{HTTP_HOST} ^123\.123\.123\.123
RewriteRule (.*) http://www.domain.co.uk/$1 [R=301,L]

in the htaccess of test website 1 - or the same with the / removed from infront of the $1 in your conf.
(remembering rewriteengine on and you may need to followsymlinks)
Gabe
zubel
Community Veteran
Posts: 3,793
Thanks: 4
Registered: ‎08-06-2007

Re: Apache setup - Mix of testing & live sites

As a rule, the first declared VirtualHost in the apache configuration files will be served in response to  'unknown' named virtual hosts.
Are they all set up as /etc/httpd/conf.d/*.conf  files?
If so, I would make sure that your primary live website is served first (rename the xxxx.conf file to __xxxx.conf or something that puts it alphabetically first in the directory, or include the vhost config directly into httpd.conf, before the Include conf.d/*.conf line)
B.
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: Apache setup - Mix of testing & live sites

You each have your cat. Let skinning commence.  Wink
Would probably still want to canonicalize, but could use a negative condition.
Gabe
andun84
Rising Star
Posts: 233
Thanks: 4
Fixes: 1
Registered: ‎01-08-2007

Re: Apache setup - Mix of testing & live sites

Thanks guys.
Gabe I wasn't sure where to look on the apache user guide for this as I wasn't sure to describe the issue however I must admit the use fo the word canonicalize had me intrigued so I searched it along with apache and got this link:
http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html
which should explain your first reply much better.
Barry I did wonder if it was going in alphabetic order as the test being served from the ip address is the first alphabettically and you are right regarding the location.
I will do the rename however I will certainly look at Gabe's as I think it is something worth the learning.
Thanks again.
zubel
Community Veteran
Posts: 3,793
Thanks: 4
Registered: ‎08-06-2007

Re: Apache setup - Mix of testing & live sites

I agree with Gabe regarding the cat skinning!
However, IMO this is certainly an Apache configuration issue.  Moving the 'fix' to use rewriting could potentially conflict with other rewrite rules that you may require in the future, so I'm all for keeping it as simple as possible Smiley
Cheers
B.
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: Apache setup - Mix of testing & live sites

In this instance, I'm struggling to think of a potential conflict.
For a name-based setup, I wouldn't normally put a live site in the default vhost, and my own preference is to declare explicitly how to treat calls for the ip address (and to point them at a you-can't-get-there-from-here page if there's more than one live vhost).
It's also a canonical-urls issue. With two or more http_hosts pointing at the same place it's still going to require either the same rewrite or a catch-all to canonicalize.
Gabe