Mac自帶的Apache2增加自定義目錄部署靜態(tài)網(wǎng)站

Version: Apache2

Commands:
sudo apachectl start
sudo apachectl stop
sudo apachectl -k restart
相關(guān)文件夾Path

安裝目錄:/etc/apache2
默認(rèn)放網(wǎng)頁地址:/Library/WebServer/Documents
訪問地址:http://localhost
自定義放網(wǎng)頁地址:/Users/<your short user name>/Sites/
訪問地址:http://localhost/~<your short user name>

增加自定義放網(wǎng)頁的目錄

  1. 創(chuàng)建目錄
    mkdir ~/Sites

  2. 創(chuàng)建一個(gè)網(wǎng)頁

echo "<html><body><h1>My site works!</h1></body></html>" > ~/Sites/index.html.en
  1. 打開配置文件sudo vi /etc/apache2/httpd.conf,做修改

    1. Uncomment the following line:
      #LoadModule php5_module libexec/apache2/libphp5.so
      to
      LoadModule php5_module libexec/apache2/libphp5.so

    2. Uncomment the following line:
      #LoadModule userdir_module libexec/apache2/mod_userdir.so
      to
      LoadModule userdir_module libexec/apache2/mod_userdir.so

    3. Uncomment the following line:
      #Include /private/etc/apache2/extra/httpd-userdir.conf
      to
      Include /private/etc/apache2/extra/httpd-userdir.conf

    4. 保存文件/etc/apache2/httpd.conf

  2. 打開配置文件sudo vi /etc/apache2/extra/httpd-userdir.conf,作修改

    1. uncomment the following line:
      #Include /private/etc/apache2/users/*.conf
      to
      Include /private/etc/apache2/users/*.conf

    2. 保存文件/etc/apache2/extra/httpd-userdir.conf

  3. 打開配置文件sudo vi /etc/apache2/users/<your short user name>.conf,作修改

    1. 添加內(nèi)容
    <Directory "/Users/<your short user name>/Sites/">
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from localhost
        Require all granted
    </Directory>
    
    1. 保存文件/etc/apache2/users/<your short user name>.conf
  4. 測(cè)試

    1. 默認(rèn)放網(wǎng)頁地址:/Library/WebServer/Documents
      訪問地址:http://localhost
      網(wǎng)頁顯示:
It works!
1. 自定義放網(wǎng)頁地址:```/Users/<your short user name>/Sites/```  

訪問地址:http://localhost/~<your short user name>
Note:注意不要忘了波浪號(hào)~
網(wǎng)頁顯示:

My site works!
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容