Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running CentOS 5.6 on my server with Apache. I need to create a "staging" site so that client can view the development in progress. I understand that this is done via Apache virtual host. Where is this file located on the server?

Since we have 1 IP address on the test server, and we don't want to change DNS for the domain name just yet, how do I setup the virtual host to resolve the http://my.ip.addy to our test server's /var/www/html/public directory?

Thanks much for your guidance.

share|improve this question
    
It sounds like you need multiple domains going to different sites while using the same IP, right? –  Rilindo Oct 3 '11 at 20:31
    
Yes, I believe so. test.ourdomain.com is needed right away, and eventually ourdomain.com will be pointed to this server when dev/test is done. –  SidC Oct 3 '11 at 20:35
add comment

2 Answers 2

up vote 1 down vote accepted

It sounds like you are trying to get a domain name to resolve to an IP as well as getting the computer at that IP to respond appropriately. To do that you want to modify your httpd.conf file, which is located at /etc/httpd/conf/ by default. You would then add the following at the bottom:

<VirtualHost *:80> # note the asterisk.
ServerName staging.example.com
DocumentRoot /var/www/html/public
ErrorLog logs/staging.example.com-error_log
</VirtualHost>

For ServerName you put whatever you want as a domain. Changing the *:80 to your.ip.add.ress:80 means that the machine will only respond by the ServerName provided if the request is to that IP (You may want that too, but I generally avoid it).

Then, on the client side, I would modify the hosts file to point that domain to the IP of the testing server. This will let you navigate to the domain and arrive at the testing site. It might be something like this:

127.0.0.1         localhost loopback
::1               localhost
your.ip.add.ress  staging.example.com
share|improve this answer
    
On my hosts file, I have 127.0.0.1 localhost our.ip.addy test.ouraddy.com Do I need the entry ::1 localhost as well? When I browse to test.ouraddy.com I am unable to resolve to the test server. Is there something else I need to do? –  SidC Oct 3 '11 at 22:21
    
::1 is your IPv6 local host address. As for the other entry, you need to i has 127.0.0.1 test test.ouraddy.com. Don't remove the existing local entry, to avoid breakage. –  Rilindo Oct 3 '11 at 23:24
add comment

The configuration file is /etc/httpd/conf/httpd.conf and you can use the minimal virtualhost as follows,

<VirtualHost X.X.X.X:80>
ServerName staging.example.com
DocumentRoot /var/www/html/public
ErrorLog logs/staging.example.com-error_log
</VirtualHost>

More Info: http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-apache-config.html

share|improve this answer
    
Will that allow us to hit the server via our.ip.address ? –  SidC Oct 3 '11 at 20:55
    
Normally, the first virtualhost domain will be served when accessing the IP when you host multiple virtualhosts on the same IP. So, if there is only one virtualhost, I guess you got it :) –  SparX Oct 3 '11 at 22:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.