1. 程式人生 > >如何在Apache中開啟虛擬主機

如何在Apache中開啟虛擬主機

首先在apache的安裝目錄下的conf\extra\httpd-vhosts.conf中新增如下

<VirtualHost *:80>  //虛擬主機埠號
   ServerAdmin [email protected]  //伺服器管理員郵箱
    DocumentRoot "E:/PHPWorkj/think/public/index.php"  //虛擬主機需要對映到的專案地址
    ServerName zxl.com  
    ServerAlias www.zxl.com   //虛擬主機訪問域名
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common </VirtualHost> 接著在conf/httpd.conf中加入 <Directory />
   Options Indexes FollowSymLinks 
     AllowOverride None  
     Allow from all 
</Directory> 在把 LoadModule access_compat_module modules/mod_access_compat.so #
基於主機的組授權(名稱或IP地址) httpd 2.x相容的模組,
LoadModule proxy_module modules/mod_proxy.so #apache的代理模組
LoadModule proxy_http_module modules/mod_proxy_http.so #代理http和https請求
LoadModule vhost_alias_module modules/mod_vhost_alias.so #虛擬主機動態配置
LoadModule authz_host_module modules/mod_authz_host.so #基於主機的組授權
Include conf/extra/httpd-vhosts.conf#
啟用虛擬主機配置 以上模組前面的#去除 找到C:\Windows\System32\drivers\etc\hosts 在裡面把localhost換成剛才的域名即可