天天看点

ubuntu下快速配置mongrel+apache2

ubuntu下用源装好 apache2,它的配置是比较特殊的,但熟悉了之后还是好配的。

apache2的配置文件主要是在/etc/apache2下,要用root权限。

先要起用mod,办法很简单,用ln 把mods-available下的模块链接到 mods-enabled下就可以起用了。

至少需要以下模块:

[code]

proxy_balancer.load

proxy.load

proxy_http.load

[/code]

在mods-enabled目录下使用:

[code]

sudo ln -s ../mods-available/proxy.load proxy.load

[/code]

这样就创建了软链接。

然后要创建一个站点,假设域名叫webcs,可以在/etc/hosts里定义一下:

[code]

127.0.0.1 webcs

[/code]

然后在/etc/apache2/sites-available下创建一个文件webcs,输入:

[code]

ProxyRequests Off

<Proxy balancer://mongrel_cluster>

BalancerMember http://127.0.0.1:8000

BalancerMember http://127.0.0.1:8001

BalancerMember http://127.0.0.1:8002

</Proxy>

<VirtualHost *>

ServerName webcs

ProxyPass /images !

ProxyPass /stylesheets !

ProxyPass /javascripts !

ProxyPass /stylesheets !

ProxyPass /yui !

ProxyPass /enter_chat.html !

ProxyPass /license.html !

ProxyPass /favicon.ico !

Alias /images /home/magicgod/workspace/webcs/public/images

Alias /stylesheets /home/magicgod/workspace/webcs/public/stylesheets

Alias /javascripts /home/magicgod/workspace/webcs/public/javascripts

Alias /yui /home/magicgod/workspace/webcs/public/yui

Alias /enter_chat.html /home/magicgod/workspace/webcs/public/enter_chat.html

Alias /license.html /home/magicgod/workspace/webcs/public/license.html

Alias /favicon.ico /home/magicgod/workspace/webcs/public/favicon.ico

ProxyPass / balancer://mongrel_cluster/

ProxyPassReverse / balancer://mongrel_cluster/

ProxyPreserveHost on

ErrorLog /var/log/apache2/webcs-error_log

CustomLog /var/log/apache2/webcs-access_log common

</VirtualHost>

[/code]

假设开了三个mongrel,并且端口从8000开始增加排列。

日志目录要指向/var/log/apache2,可以参考另一个站点配置default,在ubuntu里会缺省创建这个站点。

静态内容都不要传到mongrel去,直接建立别名,也可以仅仅用DocumentRoot指向。一定要用ProxyPass来禁止转换。

保存后在sites-enabled目录创建一个软链接:

[code]

sudo ln -s ../sites-available/webcs 001-webcs

[/code]

再重新启动一下apache2