How to setup virtual host in Apache

During Proxy setting in Apache

we have to work on two files

  • httpd.conf              (apache/conf) (This page will be used to enable apache modules)
  • httpd-vhost.conf  (apache/conf/extra) ( this page will be used to write proxy settings)

Needs to uncomment following lines httpd.conf

  • LoadModule vhost_alias_module modules/
  • LoadModule proxy_http_module modules/
  • LoadModule negotiation_module modules/
  • LoadModule proxy_module modules/
  • LoadModule alias_module modules/

Then search for a line something like below

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

if, something is written like this. It means apache knows, about the external vhost file. you may change this file name.

Following is one of the example of writing vhosts in Apache.

Following things you have to ensure during proxy setup

  1. Do not repeat the code “NamevirtualHost *:80” more than once in “httpd-vhosts.conf” file. It should be written only once.
  2. If you want redirect the request from port “80” to a different port , like port “8080”. Then these lines should be written before any other virtual host scripts. like you have to write all your complex proxy redirect just after “NamevirtualHost *:80”
  3. All the simple poxy redirects like “localhost” or “” should be written just after the complex “proxy” redirects (at the buttom of the page)

NamevirtualHost *:80

<VirtualHost *:80>

  ProxyPreserveHost On
  ProxyRequests Off
  ServerAlias *
  ProxyPass /
  ProxyPassReverse /


<virtualHost *:80>
ServerName http://localhost
ServerAlias localhost
DocumentRoot “C:/wamp/www”

Keep Apache :)