簡體   English   中英

如何設置 /etc/hosts 以像訪問根文件夾一樣訪問子文件夾(在 Mac 上)

[英]How to set up /etc/hosts to access a subfolder like it's a root folder (on a Mac)

我正在安裝一台新機器。 我將其配置為使用站點文件夾和本地主機來訪問它。 使用 Apache,一切都通過 Homebrew 安裝。

站點文件夾

  • 站點 1
  • 網站2

在瀏覽器中

  • 本地主機/site1/index.html
  • 本地主機/site2/index.html

那部分工作正常。

問題是 site1 和 site2 認為 localhost 是根文件夾(它是),但我希望他們認為 localhost/site1 和 localhost/site2 是這些站點的根文件夾。

這是我可以用 /etc/hosts 或其他一些技巧來做的事情嗎?

事實證明這是 /etc/hosts 和 Apache VirtualHosts 的組合。 以下是我采取的步驟:

  1. 建立您要為其提供服務的目錄(這將成為您的 DocumentRoot)。 在我的例子中 /Users/myusername/Sites/site1

  2. 編輯您的 /etc/hosts 文件以包含您的新“域名”(這將成為您的服務器名稱)。 在我的例子中 site1.com

    127.0.0.1 站點 1.com

    ::site1.com

  3. 創建一個 Apache 虛擬主機...關於這個有不同的方法到 go,但我使用 Homebrew 安裝 Apache,所以對我來說,這里有一個文件:/opt/homebrew/etc/httpd/extra/httpd-vhosts。會議。 如上所述,我使用 DocumentRoot 和 ServerName 復制了提供的示例。

  4. 更新此文件 /opt/homebrew/etc/httpd/httpd.conf 以取消注釋此行

    包括 /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf

  5. 重啟 Apache

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM