DNS 綁定 A 記錄#
首先在 DNS 上建立 A 記錄,將網域名稱綁定到相應 IP 上。
建立網站目錄#
在伺服器上,添加 /srv/www/vhosts/www.111cn.net 目錄,並在該目錄下建立一個 index.html 檔案 – 用於測試。
配置 Apache#
建立虛擬機器主機設定檔#
| 代碼如下 |
複製代碼 |
$ cd /etc/apache2/vhosts.d
$ sudo cp vhost.template www.111cn.net.conf
|
修改 www.111cn.net.conf 檔案內容如下:
| 代碼如下 |
複製代碼 |
|
<VirtualHost *:80>
ServerName www.111cn.net
ServerAdmin chenxsan@gmail.com
DocumentRoot /srv/www/vhosts/www.111cn.net
ErrorLog /var/log/apache2/www.111cn.net-error_log
CustomLog /var/log/apache2/www.111cn.net-access_log combined
# don't loose time with IP address lookups
HostnameLookups Off
# needed for named virtual hosts
UseCanonicalName Off
# configures the footer on server-generated documents
ServerSignature On
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/srv/www/vhosts/www.111cn.net">
AllowOverride All
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
</VirtualHost> |
之後重啟 Apache:
$ sudo rcapache2 restart
訪問 www.111cn.net 網址,已經可以看到 index.html 檔案的內容了。如果我們之前未添加 index.html 檔案,訪問的話,則會出現如下錯誤資訊:
Access forbidden!
You don’t have permission to access the requested directory. There is either no index document or the directory is read-protected.
If you think this is a server error, please contact the webmaster.
Error 403
www.111cn.net