Mac OS WEB服务配置

启动APACHE

Mac OS 预装了Apache,需要手动通过命令开启或关闭:

启动 sudo apachectl start

停止 sudo apachectl stop

重启 sudo apachectl restart

查看版本信息 httpd -v

通过浏览器浏打开 http://127.0.0.1 或者 http://localhost 可以检测WEB服务是否正常工作,如果正常启动会看到“It Works!”的页面;

文件根目录

系统级的根目录: http://localhost/

对应的文件目录是:/Library/WebServer/Documents

系统级根目录默认没有开启目录列表,开启方法:编辑 /etc/apache2/httpd.conf文件,搜索找到 <Directory "/Library/WebServer/Documents" >,将 Options FollowSymLinks Multiviews 修改为 Options Indexes FollowSymLinks Multiviews

用户级根目录:http://localhost/~username/

另一个WEB根目录是用户目录下的 Sites 目录,~/Sites 对应 http://localhost/~username/ 。Mac OS 10.9 中需要手动建立这个目录。检查 /etc/apache2/users/ 目录下是否有 username.conf 文件,如果没有,则需要新建一个。username 是帐户名称。

开启用户目录

编辑 /etc/apaches/httpd.conf 文件;

搜索到 Include /private/etc/apache2/extra/httpd-userdir.conf ,将行首的 # 字符删除,启用用户目录;

修改 <DIrectory /> 配置为以下内容(用户访问权限?);

<Directory />
    AllowOverride none
    Order allow,deny
    Allow from all
</Directory>

修改 <Directory "/Library/WebServer/Documents"> 配置为以下内容(用户访问权限?);

<Directory "/Library/WebServer/Documents">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks Multiviews
    MultiviewsMatch Any

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    # Require all granted
    Order allow,deny
    Allow from all
</Directory>

保存 httpd.conf 文件;

在 /Users/username 目录下建立 "Sites" 文件夹;

在 /etc/apache2/users/ 目录下建立 username.conf,内容如下:

<Directory "/Users/username/Sites/">    (注意Sites后的/)
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

在 /Users/username/Sites/ 目录下建立一个 index.html 文件,内容简单设置为 “Hello World!”;

在浏览器中输入 http://localhost/~username/index.html,如果显示为 “Hello World!” 表示配置成功。

如果在SItes目录下还有其他的子目录,需要对目录授权?(chmod 755 foldername)

results matching ""

    No results matching ""