lighttpd configure java web server

我的apache 2.061在window 2003 下老是报告错误,虽然也可以使用但感觉很不爽.
报告队列中的错误: 错误应用程序 Apache.exe,版本,错误模块 ntdll.dll,版本 5.2.3790.3959,错误地


. When to use lighttpd

You can use lighttpd to

  • secure access to your application server
  • reduce load on your server by offloading static requests
  • load balance your application servers
  • use lighttpd’s spambot and bad bot blocking capabilities
  • get more request rewriting and redirecting flexibility
  • use the above flexibility to improve your search engine rankings
  • profit.

2. When not to use lighttpd

You might not like lighttpd if you

  • don’t like configuring software
  • use URL rewriting and ;jsessionid (though a patch is available for this problem).

3. lighttpd modules you need

The following lighty modules are needed:

  • mod_access
  • mod_redirect
  • mod_rewrite
  • mod_proxy

Add them to your server.modules section:

server.modules = (

4. Denying access to JEE directories

The WEB-INF and META-INF directories shouldn’t be accessible through lighttpd. Files from your development environment also shouldn’t be visible.

url.access-deny = ( “WEB-INF”, “.classpath”, “.project”, “META-INF” )

5. Binding your application server to localhost

To prevent duplicate content penalties, your application server shouldn’t be visible from the web. Even if you run it on a high port, someone might eventually find it.

Binding a web site to localhost looks like this in Orion’s <name>-web-site.xml:

<web-site host=”″ port=”12345″>
<frontend host=”” port=”80″/>

Consult your documentation if you aren’t using Orion.

6. Redirecting www. to non-www. hosts

Even if you don’t really need to do this, I recommend doing so. Removing duplicate content will improve your rankings.

The following snippet redirects all visitors from www.<domain> to <domain> with a 301 permanent redirect.

$HTTP[“host”] =~ “^www\.(.*)___FCKpd___3quot; {
url.redirect = ( “^/(.*)” => “http://%1/$1” )

You should also redirect all additional domains (, to your main domain.

7. Proxying dynamic requests

We will use mod_proxy to proxy some requests to your Java application server.

Depending on your site’s structure, one of the following approaches will work better.

Simple JSP

If all you have is a bunch of Java Server Pages, the following mod_proxy rule is sufficient:

proxy.server = ( “.jsp” =>
( “host” => “”,
“port” => “12345”

Note that the JSP must be actual files. You cannot use Servlets mapped to these URIs.


If you use Servlets or more complex applications, you can proxy URIs by prefix:

proxy.server = ( “/blog/” =>
( “host” => “”,
“port” => “12345”

Proxying with exceptions

If most of your site is dynamic and you have a directory for static content (/assets, /static or so), you can proxy all requests except requests for static files:

$HTTP[“url”] !~ “^/static” {
proxy.server = ( “” =>
( “host” => “”,
“port” => “12345”

8. Rewriting requests

lighttpd can dynamically rewrite requests. I mostly use this to use default.jsp as dynamic index file instead of index.html. Here’s an example:

url.rewrite-once = ( “^(.*)/___FCKpd___7quot; => “$1/default.jsp”,
“^(.*)/([;?]+.*)___FCKpd___7quot; => “$1/default.jsp$2” )

This is visible at and internally rewrites all requests from / to /default.jsp (including jsessionid and query string).

mod_rewrite can also be used to make URLs shorter. For example, to remove the ?page=comments query string, I use the following:

url.rewrite-once = (
“^/blog/(.*)\.html___FCKpd___8quot; => “/blog/$1.html?page=comments”

9. Redirecting requests

You can use mod_redirect to redirect the user to a different URL. Contrary to mod_rewrite where the request is rewritten, a 301 permanent redirect will be sent to the browser.

In this example, I’m redirecting requests to an old domain to a new domain:

$HTTP[“host”] == “” {
url.redirect = (
“^/(.*)___FCKpd___9quot; => “$1”

10. More things to be aware of

  • The only IP address in your application server log files should be If you need the original address, log the X-FORWARDED-FOR header.
  • Don’t analyze both lighttpd and application server logs – lighty’s log files already contain all requests.
  • You might want to set up virtual hosts sooner or later.
  • Use mod_expire to make resources cacheable. Doing so can make your site a lot faster and save you money.

Configure lighttpd alias (mod_alias)

This lighttpd module provides for mapping different parts of the host filesystem in the document tree. You can use it for mapping various directories. For example cgi-bin directory mapped to /var/lib/cgi-bin.


Open your lighttpd configuration file:

vi /etc/lighttpd/lighttpd.conf

Append/add mod_ alias to list of server modules:
server.modules += ( “mod_alias” )


Add cgi-bin alias for doamin
alias.url = ( “/cgi-bin/” => “/home/lighttpd/” )

Browse all documents installed at /usr/share/doc/ directory with following alias:
alias.url = ( “/docs/” => “/usr/share/doc/” )
alias.url += ( “/stats/” => “/home/” )

Open a browser and type url or