It’s common to test our site on local machine. And it’s useful to keep it down about configuring apache on mac osx 10.9 and 10.10. The process under linux is similar.


  1. 配置启用 Virtual Host
  2. 启用个人 Sites
  3. 启用 PHP
  4. 设置反向代理

配置启用 Virtual Host

修改/etc/apache2/httpd.conf, 将下面两行取消注释. 这两行用来启用 Virtual Host

#Include /private/etc/apache2/extra/httpd-vhosts.conf
#LoadModule vhost_alias_module libexec/apache2/

/etc/apache2/extra/httpd-vhost.conf中有一个 vhost 的样本, 可以按照它来设置一个Virtual Host. 如:

    DocumentRoot "/usr/docs/"
    ErrorLog "/private/var/log/apache2/"
    CustomLog "/private/var/log/apache2/" common

启用个人 Sites

apache 可以设置 userdir, 通过访问 http://localhost/~user/ 来访问个人 home 下的 Sites 文件夹下的网页.

/etc/apache2/httpd.conf 中找到

#LoadModule userdir_module libexec/apache2/
#Include /private/etc/apache2/extra/httpd-userdir.conf


/etc/apache2/extra/http-userdir.conf 中, 找到下面一行

#Include /private/etc/apache2/users/*.conf


最后建立如下配置文件 user.conf, 并拷贝到/etc/apache2/users/ 下:

    Options +Indexes +MultiViews +FollowSymLinks +SymLinksIfOwnerMatch +ExecCGI
    AllowOverride All
    Require local
    Order allow,deny
    Allow from all


sudo apachectl restart

启用 PHP

/ etc/apache2/httpd.conf 中找到如下一行, 并取消注释:

#LoadModule php5_module libexec/apache2/


找到如下几行并取消注释, 开启 http, https, ftp, fcgi 等反向代理:

#LoadModule proxy_module libexec/apache2/
#LoadModule proxy_connect_module #libexec/apache2/
#LoadModule proxy_ftp_module libexec/apache2/
#LoadModule proxy_http_module libexec/apache2/
#LoadModule proxy_fcgi_module libexec/apache2/
#LoadModule proxy_balancer_module #libexec/apache2/
#LoadModule proxy_express_module #libexec/apache2/

例如配置 ghost 博客平台:

    ServerAdmin admin@admin
    DocumentRoot "/Users/user/Sites/ghost/"
    ServerName ghost.localhost
    ServerAlias www.ghost.localhost
    ErrorLog "/private/var/log/apache2/ghost.localhost-error_log"
    CustomLog "/private/var/log/apache2/ghost.localhost-access_log" common
    ProxyPreserveHost on
    ProxyRequests off
    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/

PS: If any question, please leave a note. (o)/~

水水更健康 O(∩_∩)O~…