Creating multiple virtual hosts using apache is so common, you may find making it so easy and straight forward on Linux or even Mac, but believe me it is not the case with Windows !
Here is the deal, the idea behind how to make this is to give another IP for your new host, and make apache listen on that IP, let's do it:
Step 1: add your new host in the hosts file under "C:\Windows\System32\drivers\etc" and assign new IP to it:
- 127.0.0.1 localhost
- 127.0.0.2 mysite.com
Step 2: make your apache server listens on the new IP by modifying httpd.conf file in the "apache\conf" folder, put the following in the Listen section:
- Listen 80
- Listen 127.0.0.2:80
Step 3: and finally, open "apache\conf\extra\httpd-vhosts.conf" and add your new virtual hosts like this:
- <virtualhost mysite.com:80>
- DocumentRoot "absolute_location_to_mysite_public_folder"
- ServerName Boston.com
- ServerAlias boston.com
- <directory "absolute_location_to_mysite_public_folder">
- AllowOverride All
- Options Indexes FollowSymLinks
- Order allow,deny
- Allow from all
- </directory>
- </virtualhost>
- <virtualhost localhost:80>
- DocumentRoot "apache_htdocs_folder"
- ServerName localhost
- ServerAlias localhost
- <directory "apache_htdocs_folder">
- AllowOverride All
- Options Indexes FollowSymLinks
- Order allow,deny
- Allow from all
- </directory>
- </virtualhost>
Finally, you can use the two hosts in your browser:
- localhost
- mysite.com
No comments:
Post a Comment