如何使用 Mac 上的 Sites 資料夾設定本機?

如何使用 Mac 上的 Sites 資料夾設定本機?

如何使用 Mac 上的「網站」資料夾設定本機?

答案1

Web 共享複選框在 10.8 中被刪除,但sudo apachectl start也永久啟用了 launchd 代理程式(請參閱 參考資料cat /usr/sbin/apachectl)。為了http://localhost/~username/工作,您可以將類似的內容儲存為/etc/apache2/users/username.conf

<Directory "/Users/username/Sites/">
    Options Indexes MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

如果您想將 localhost 導向到~/Sites/,您可以變更 中的 DocumentRoot /etc/apache2/httpd.conf

Include /private/etc/apache2/extra/httpd-vhosts.conf您可以透過取消註解/etc/apache2/httpd.conf127.0.0.1 testsite.dev新增至/etc/hosts並將其新增至 來新增虛擬主機/etc/apache2/extra/httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "/Users/username/Sites/testsite/"
    ServerName testsite.dev
</VirtualHost>

sudo apachectl restart應用更改。

答案2

打開系統偏好設定 » 分享,並啟用網路分享

山獅上網路分享已從首選項中刪除,因此用於sudo apachectl start啟動 Apache。

您將找到那裡指定的 URL。例如,我的站點資料夾/Users/danielbeck/Sites可作為http://10.0.1.2/~danielbeck/.

相關內容