Mac自带的Apache2增加自定义目录部署静态网站

Version: Apache2

Commands:
sudo apachectl start
sudo apachectl stop
sudo apachectl -k restart
相关文件夹Path

安装目录:/etc/apache2
默认放网页地址:/Library/WebServer/Documents
访问地址:http://localhost
自定义放网页地址:/Users//Sites/
访问地址:http://localhost/~

增加自定义放网页的目录

  1. 创建目录
    mkdir ~/Sites

  2. 创建一个网页

echo "

My site works!

" > ~/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/.conf,作修改

    1. 添加内容
    /Sites/">
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from localhost
        Require all granted
    
    
    1. 保存文件/etc/apache2/users/.conf
  4. 测试

    1. 默认放网页地址:/Library/WebServer/Documents
      访问地址:http://localhost
      网页显示:
It works!
1. 自定义放网页地址:```/Users//Sites/```  

访问地址:http://localhost/~
Note:注意不要忘了波浪号~
网页显示:

My site works!

你可能感兴趣的:(Mac自带的Apache2增加自定义目录部署静态网站)