Lighttpd整合tomcat实践过程

一.lighttpd安装过程
  正则表达式需要prec支持
  tar xzvf pcre-6.6.tar.gz
  cd pcre-6.6
  ./configure
  make clean
  make
  make install
  
  tar xzvf lighttpd-1.4.13.tar.gz
  cd lighttpd-1.4.13
  ./configure --prefix=/usr/local/lighttpd
  make clean
  make
  make install
  
  复制lighttpd.conf到指定目录
  
  mkdir /usr/local/lighttpd/etc
  cp doc/lighttpd.conf /usr/local/lighttpd/etc
  
  
  groupadd lighttpd
  useradd -g lighttpd lighttpd
  mkdir /www
  chown -R lighttpd.lighttpd /www
  
  
  mkdir /lighttpdlogs
  chown -R lighttpd.lighttpd /lighttpdlogs
  chmod 750 /lighttpdlogs
  
  # 安装文件下的启动脚本
  cp doc/rc.lighttpd /etc/init.d/lighttpd
  chkconfig lighttpd on
  
  修改/etc/init.d/lighttpd,将配置文件变量更改为:
  vi /etc/init.d/lighttpd
  # LIGHTTPD_CONFIG=/etc/sysconfig/lighttpd
  LIGHTTPD_CONFIG=/usr/local/lighttpd/etc/lighttpd.conf
 
 
二.Lighttpd的配置
vi /usr/local/lighttpd/etc/lighttpd.conf
  -------------------------------------------------
  启用模块
  "mod_rewrite",
  "mod_redirect",
  "mod_proxy",
  "mod_expire",
  "mod_simple_vhost",
  在#### proxy module####下面添加如下内容:
$HTTP["host"] == "192.168.4.168" {
        server.document-root = "/usr/local/apache2/htdocs"
        server.max-keep-alive-requests=4000
        server.max-fds = 2048
        $HTTP["url"] =~ "^/ReaderServerInvoker/" {
                proxy.server = (
                                "" =>
                                ((
                                "host" => "127.0.0.1",
                                "port" => 8080
                                ))
                                )
        }
         $HTTP["url"] =~ "^/UserLogin/" {
                proxy.server = (
                                "" =>
                                ((
                                "host" => "127.0.0.1",
                                "port" => 8081
                                ))
                                )
        }
}
 
修改server.document-root和日志的路径:
server.document-root        = "/usr/local/apache2/htdocs/"
server.errorlog             = "/lighttpdlogs/error.log"
accesslog.filename          = "/lighttpdlogs/access.log"
 
优化lighttpd
*server.max-keep-alive-requests=4000
这一条比较关键,对性能的影响比较大。在一个keep-alive会话终止连接前能接受处理的最大请求数。Default: 128,对一个高负载的应用来说是不够的。我用了4000。
*server.max-fds = 2048
因为lighttpd是一个单线程(single-threaded)服务器,它的主要资源限制是文件描述符数目,默认值是1024。如果在一个高负载的站点上,可能你需要通过下面的设定增加这个限定值
*server.max-keep-alive-idle
一个空闲keep-alive连接被丢弃前,存在的的最大秒数。Default: 30。
*compress.cache-dir = "/var/www/cache/"
*compress.filetype = ("text/plain", "text/html")
如果文本稍微大点可以考虑使用压缩算法,减少带宽同时也能提高效率
 
启动lighttpd:
/usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf
 
三.配置 tomcat
安装jdk
安装tomcat并将端口设置为8080,部署应用,启动tomcat
 
四.测试
http://192.168.4.168/ ReaderServerInvoke/
看能不能代理到本地tomcat8080端口去
 
五. Lighttpd的重定向
重定向格式为:
$HTTP["host"] =~ "^192\.168\.4\.168(.*)"
{url.redirect = ( "^/HallServerInvoker/(.*)" => "http://192.168.4.168:8080/HallServerInvoker/$1" )
}
 
 
重定向规则
# 重定向到指定网址
url.redirect = ("^/" => "http://www.tianya.cn/index.asp")
  

# 变量传递
url.redirect = ("^/([0-9]+)$" => "http://cache.tianya.cn/publicforum/Content/house/1/$1.shtml")
url.redirect=("^/show/([0-9]+)/([0-9]+)$"=>"http://www.example.org/show.php?isdn=$1&page$2")

# 面向虚拟主机的重定向
$HTTP["host"] =~ "^www\.(.*)" {
  
url.redirect = ( "^/(.*)" => "http://%1/$1" )

   }

你可能感兴趣的:(tomcat,正则表达式,服务器,url,lighttpd,redirect)