前言:
1. 我只配置多網站,因為配置多網站就是去配置一個一個的網站,我認為是包括了單個網站。
2. 一個網站的核心資訊:ServerNane(網站名/伺服器名),DocumentRoot(網站目錄)
3. 安裝Apache後,htdocx就是一個預設的網站:
ServerNane:localhost(127.0.0.1),DocumentRoot:D:\amp\apache\htdocs
一、httpd.conf 開啟多網站配置項
避免出錯,開啟這兩個模組:
二、(示範)添加兩個網站
開啟httpd-vhosts.conf:
比如說,這裡把兩個檔案夾“D:\mycodes\tets”、"D:\amp\www"設定為網站,代碼:
#網站<VirtualHost *:80>#網站名、伺服器名ServerName www.abc.com#網站位置 DocumentRoot "D:/mycodes/test"#網站別名,兩個都可以訪問ServerAlias www.study.com<Directory "D:/mycodes/test">#當請求沒有指定檔案的時候,顯示目錄 Options Indexes #啟用檔案夾存取控制的檔案.htaccess設定 AllowOverride All #請求控制 Require all granted #預設頁面,第一個最優先 DirectoryIndex index.php index.html</Directory></VirtualHost>
#網站<VirtualHost *:80>ServerName www.playful.com DocumentRoot "D:/amp/www"ServerAlias www.study.com<Directory "D:/amp/www"> Options Indexes AllowOverride All Require all granted DirectoryIndex index.php index.html</Directory></VirtualHost>
如圖:
將www.abc.com和www.playful.com添加到電腦的hosts裡,這裡說下原因:
1. 訪問一個地址,先從原生hosts檔案裡找,找到了就訪問,假如這裡設定成功那麼久訪問電腦上的檔案;
2. 本機上沒找到,就去網路上找,比如www.baidu.com或者www.sina.com.cn等,不過這是人家是花了錢的。
先測試代碼有沒有錯誤,在cmd下httpd -t,沒錯就重啟Apache,訪問www.abc.com:
至此,完成。 下一篇:認識PHP(怎麼啟動並執行。運行過程是什麼。)