在apache中可給apache配置多個虛擬主機我們需要在httpd.conf或在httpd-vhosts.conf文件配置即可了,下面是在httpd.conf的配置方法。
VirtualHost:在我的本機內 Apache 的主配置文件在:
- D:/usr/local/apache2/conf/httpd.conf
創建各個虛擬主機的子配置文件:創建 dbmanager 的配置文件:D:/usr/webroot/phpMyAdmin/httpd.conf
- #dbmanager 虛擬主機設置
- <VirtualHost 127.0.0.2:80>
- ServerName www.hzhuti.com
- DocumentRoot D:/usr/webroot/phpMyAdmin
- <Directory D:/usr/webroot/phpMyAdmin>
- AllowOverride All
- Options All
- </Directory>
- </VirtualHost>
創建 phpweb20 的配置文件:D:/usr/webroot/Zendphpweb20/httpd.conf
- #phpweb20 虛擬主機設置
- <VirtualHost 127.0.0.3:80>
- ServerName 111cn.net
- DocumentRoot D:/usr/webroot/Zendphpweb20/htdocs
- <Directory D:/usr/webroot/Zendphpweb20/htdocs>
- AllowOverride All
- Options All
- </Directory>
- #修改 PHP 配置(可選)
- php_value include_path .;D:/usr/webroot/Zendphpweb20/include;D:/usr/local/php5/PEAR
- php_value magic_quotes_gpc off
- php_value register_globals off
- </VirtualHost>
各個虛擬主機的配置就看應用站點的不同需要了,DocumentRoot 為其根目錄(php_value 是修改此站點的 PHP 運行參數,根據自己應用的需要來寫,這樣就不必修改 PHP 主配置文件)。
重啟 Apache 服務:
在httpd-vhosts.conf中配置,在httpd-vhosts.conf配置之前我們需要在apache的httpd.conf找到
- # Virtual hosts
- #Include conf/extra/httpd-vhosts.conf
把前面的#號去了,然后進入extra/httpd-vhosts.conf,寫法與在httpd.conf 一樣了。
新聞熱點
疑難解答