1. 程式人生 > >xampp 虛擬主機配置

xampp 虛擬主機配置

測試環境 xampp3.2.1 + win7

一、基於埠的虛擬主機

(1)Apache配置檔案 httpd.conf 改動:

A、 搜尋“Listen”。增加兩個新埠

  Listen 8000

  Listen 8001

B、搜尋“vhosts” 。確保“Include conf/extra/httpd-vhosts.conf” 前無註釋符號“#”

(2)改動 vhosts.conf檔案

增加配置項

<VirtualHost *:8000>
    ##ServerAdmin [email protected]
    DocumentRoot "D:/Program Files (x86)/xampp/htdocs/keya/4_upload"
    ##ServerName keya
    ErrorLog "logs/keya-error.log"
    CustomLog "logs/keya-access.log" common
</VirtualHost>
<Directory "D:/Program Files (x86)/xampp/htdocs/keya/4_upload">
  Order allow,deny
  Allow from all
</Directory>
<VirtualHost *:8001>
    ##ServerAdmin

[email protected]
    DocumentRoot "D:/Program Files (x86)/xampp/htdocs/nw"
    ##ServerName ylk
    ErrorLog "logs/nw-error.log"
    CustomLog "logs/nw-access.log" common
</VirtualHost>
<Directory "D:/Program Files (x86)/xampp/htdocs/nw">
  Order allow,deny
  Allow from all
</Directory>

(3)訪問

chrome 瀏覽器訪問 localhost:8000或者localhost:8001

二、基於域名的虛擬主機
(1)配置C:\Windows\System32\drivers\etc\hosts檔案

     加兩行

           127.0.0.1    keya

           127.0.0.1    ylK

(2) 修改apache的配置檔案 httpd.conf

          A、監聽埠                 Listen 80

          B、包含虛擬主機配置檔案     “Include conf/extra/httpd-vhosts.conf”   確保這句話前無註釋符號

(3)修改httpd-vhosts.conf

<VirtualHost *:80>
    ##ServerAdmin [email protected]
    DocumentRoot "D:/Program Files (x86)/xampp/htdocs/keya/4_upload"
    ServerName keya
    ErrorLog "logs/keya-error.log"
    CustomLog "logs/keya-access.log" common
</VirtualHost>
<Directory "D:/Program Files (x86)/xampp/htdocs/keya/4_upload">
  Order allow,deny
  Allow from all
</Directory>
<VirtualHost *:80>
    ##ServerAdmin [email protected]
    DocumentRoot "D:/Program Files (x86)/xampp/htdocs/nw"
    ServerName ylk
    ErrorLog "logs/nw-error.log"
    CustomLog "logs/nw-access.log" common
</VirtualHost>
<Directory "D:/Program Files (x86)/xampp/htdocs/nw">
  Order allow,deny
  Allow from all
</Directory>