web development - apache vhost

Apache is a HTTP server, an HTTP server in a nutshell is the service that responds when your browser requests a web page. It manages the jump from the files on the server, to the information being transferred over the internet to your browser. Apache is probably the most widely used http server on the internet.

When your browser makes a request to a website, apache will pick up that request, interpret the url and look for a file on the servers hard disk to send to you. Sometimes this process is simple, an html file is requested and apache pulls the raw file and sends it to you ( wrapped in some http protocol business ); other times the process is more complex, such as when there is a web application that will handle the request.

There are many servers that run more than one website at a time, all the requests for each website go through to the same server and are handled by apache. When you request a file for website A, and the server hosts websites A,B,C, and D there has to be a way for apache to know which website you are making a request to. This is where vhosts come into play.

A vhost ( virtual host ) is a configuration directive in apache, you configure them through apache's configuration file ( httpd.conf ). When you setup a vhost, you let apache know what directory to serve the files from and what domain ( or IP address ) the apache should serve those files for.

In the httpd.conf you would have vhosts for website A,B,C, and D. When your browser makes the request, apache will look at what domain ( or ip ) was requested and match it up to a vhost. With that information apache now knows which files to serve for the website requested.

Comments

Be the first to leave a comment on this post.

Leave a comment

To leave a comment, please log in / sign up