play framework学习笔记之 front-end HTTP server

阅读更多

使用lighttpd

Set-up with lighttpd

This example shows you how to configurelighttpdas a front-end web server. Note that you can do the same with Apache, but if you only need virtual hosting or load balancing, lighttpd is a very good choice and much easier to configure!

The/etc/lighttpd/lighttpd.conffile should define things like this:

server.modules = (
      "mod_access",
      "mod_proxy",
      "mod_accesslog" 
)
...
$HTTP["host"] =~ "www.myapp.com" {
    proxy.balance = "round-robin" proxy.server = ( "/" =>
        ( ( "host" => "127.0.0.1", "port" => 9000 ) ) )
}
 
$HTTP["host"] =~ "www.loadbalancedapp.com" {
    proxy.balance = "round-robin" proxy.server = ( "/" => ( 
          ( "host" => "127.0.0.1", "port" => 9000 ), 
          ( "host" => "127.0.0.1", "port" => 9001 ) ) 
    )
}

使用apache 代理 play

Set-up with Apache

The example below shows a simple set-up withApache httpd serverrunning in front of a standard Play configuration.

LoadModule proxy_module modules/mod_proxy.so
...

  ProxyPreserveHost On
  ServerName www.loadbalancedapp.com
  ProxyPass / http://127.0.0.1:9000/
  ProxyPassReverse / http://127.0.0.1:9000/
###########例子代码################################################
LoadModule proxy_module modules\mod_proxy.so
LoadModule proxy_http_module modules\mod_proxy_http.so
NameVirtualHost 188.188.1.109:80

  ServerName 188.188.1.109
  Alias /hy2 "D:\webapp\hy2"
  ProxyPreserveHost On
  ProxyPass / http://188.188.1.109:9000/
  ProxyPassReverse / http://188.188.1.109:9000/

其中注意 http://188.188.1.109:9000/ 最后的那一个 / 很重要
此处除了load模块 proxy_module 外还要导入相对的子 module如 我们这里用到了 http协议,那么就要用到 proxy_http_module这个子模块,此外还有ftp,balancer等其它对应的子模块

使用apache负载均衡

LoadModule proxy_module modules\mod_proxy.so

LoadModule proxy_http_module modules\mod_proxy_http.so

LoadModule proxy_balancer_module modules\mod_proxy_balancer.so

ServerName 188.188.1.109

SetHandler balancer-manager

Order Deny,Allow

Deny from all

Allow from ALL

BalancerMember http://localhost:9000

#这里可以用localhost

BalancerMember http://localhost:9001 status=+H

#+H的意思是 备用的意思

Order Allow,Deny

Allow From All

ProxyPreserveHost On

ProxyPass /balancer-manager !

ProxyPass / balancer://mycluster/

ProxyPassReverse / http://localhost:9000/

ProxyPassReverse / http://localhost:9001/

使用了负载均衡了之后如果你的主力服务器挂了,或者在升级,那么的备用的会替换上,接着干

你可能感兴趣的:(lighttpd,Apache,UP,Access,Web)