0
我想弄清楚什麼是錯的。每個域都轉到同一個域。我必須將其添加到/ etc/hosts嗎?我對/ etc/hosts文件感到困惑。我只有一個IP虛擬主機Apache的問題?
這是我的conf文件:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerName petunderground.com
ServerAlias www.petunderground.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/catalog
<Directory /var/www/html/catalog>
AllowOverride All
</Directory>
第二個域
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerName giftboundgifts.com
ServerAlias www.giftboundgifts.com
ServerAdmin [email protected]
DocumentRoot /var/www/html
<Directory /var/www/html>
AllowOverride All
</Directory>
對於虛擬主機,apache2使用服務器別名(完整域)來處理請求。所以你可以在端口指定'example1.com'到一個處理程序和'example2.com'在同一個接口/機器的同一個端口到另一個處理程序。爲此,必須在請求中設置域。如果您的IP沒有DNS解析,那麼您必須編輯hosts文件以將域指向本地主機,這樣當瀏覽器嘗試使用example.com時,它將按原樣路由到localhost apache2 –