Setting IP in Apache vhost as testing domain
I used the recommended Linode setup for Apache, but I was wondering if I can set the server external IP as a domain for testing.
On my Amazon server setup it works because all the domains point to the same folder.
domain1.com - /var/www/domain1
domain2.com - /var/www/domain2
ex.ter.nal.ip - /var/www/
So I can use ex.ter.nal.ip/test for a testing website.
On my Linode setup I moved the folders inside the user directories
domain1.com - /home/user1/public/domain1
domain2.com - /home/user2/public/domain2
ex.ter.nal.ip goes to domain2.com (I think it points to the last enabled site in Apache -a2ensite)
Is there a way to make it work?
I tried adding a vhost with
My domain vhost file looks like this:
<virtualhost *:80="">ServerName www.domain1.com
ServerAlias domain1.com
DirectoryIndex index.html index.php
DocumentRoot /home/user1/public/domain1.com/public
<directory home="" user1="" public="" domain1.com="">Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all</directory></virtualhost>
My testing one looks lithe this, but when enabled all the domains point to the test folder
<virtualhost ex.ter.nal.ip="">ServerName ex.ter.nal.ip
DirectoryIndex index.html index.php
DocumentRoot /home/test/public
<directory home="" test="" public="">Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all</directory></virtualhost>
4 Replies
I would question why you need/want to do this though- you can specify a virtual host for testing, and it will not be live until you change the name servers to point to it, but you can access is for testing by making an entry in your local hosts file.
I basically want to access something like 31.221.29.228/test and get to /home/test/public.
At the moment if I'm trying 31.221.29.228/test it goes to mydomain.com/test
If you're using the Debian-style sites-available directory, just name that one like 000test or __test or such, they're loaded in alphabetical order.
Personally, I think it looks very unprofessional to have the "catch all" address to display list of all sites, or tests, or any such stuff - it's just too easy for your customers to accidentally see it and complain.
Consider making it an empty vhost, a "business card" website, or such.
For testing, add another vhost - if you have your own domain use a subdomain of it, if you don't use something like testweb.private and add a line to your PC's hosts file pointing this name at the IP.
Also, Servername shouldn't have http:// in it.
#File 000catchall
<virtualhost *:80="">ServerName liXX-yyy.members.linode.com
#or
#ServerName your.own.domain.if.you.have.one
DocumentRoot /var/www/businesscard</virtualhost>
#File test
<virtualhost *:80="">ServerName test.your.own.domain
DocumentRoot /var/www/test</virtualhost>
#File domain1.com
<virtualhost *:80="">ServerName www.domain1.com
ServerAlias domain1.com
DocumentRoot /home/user1/public/domain1.com/public</virtualhost>
#File domain2.com
<virtualhost *:80="">ServerName www.domain2.com
ServerAlias domain2.com
DocumentRoot /home/user2/public/domain2.com/public</virtualhost>