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.

配置启用 Virtual Host

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

1
2
#Include /private/etc/apache2/extra/httpd-vhosts.conf
#LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

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

1
2
3
4
5
6
7
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
</VirtualHost>

启用个人 Sites

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

/etc/apache2/httpd.conf 中找到

1
2
#LoadModule userdir_module libexec/apache2/mod_userdir.so
#Include /private/etc/apache2/extra/httpd-userdir.conf

并取消注释.

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

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

也取消注释.

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

1
2
3
4
5
6
7
<Directory "/Users/user/Sites/">
Options +Indexes +MultiViews +FollowSymLinks +SymLinksIfOwnerMatch +ExecCGI
AllowOverride All
Require local
Order allow,deny
Allow from all
</Directory>

然后重启Apache:

1
sudo apachectl restart

启用 PHP

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

1
#LoadModule php5_module libexec/apache2/libphp5.so

设置反向代理

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

1
2
3
4
5
6
7
#LoadModule proxy_module libexec/apache2/mod_proxy.so
#LoadModule proxy_connect_module #libexec/apache2/mod_proxy_connect.so
#LoadModule proxy_ftp_module libexec/apache2/mod_proxy_ftp.so
#LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so
#LoadModule proxy_fcgi_module libexec/apache2/mod_proxy_fcgi.so
#LoadModule proxy_balancer_module #libexec/apache2/mod_proxy_balancer.so
#LoadModule proxy_express_module #libexec/apache2/mod_proxy_express.so

例如配置 ghost 博客平台:

1
2
3
4
5
6
7
8
9
10
11
12
<VirtualHost *:80>
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/
</VirtualHost>

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


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