You can use lighttpd to
You might not like lighttpd if you
;jsessionid
(though a patch is available for this problem).The following lighty modules are needed:
Add them to your server.modules
section:
server.modules = (
"mod_accesslog",
"mod_access",
"mod_redirect",
"mod_rewrite",
"mod_proxy",
"mod_status",
"mod_evhost",
"mod_expire"
)
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" )
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="127.0.0.1" port="12345">
<frontend host="johannburkard.de" port="80"/>
Consult your documentation if you aren’t using Orion.
www.
to non-www.
hostsEven 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 (johannburkard.com
, johann-burkard.org
) to your main domain.
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.
If all you have is a bunch of Java Server Pages, the following mod_proxy
rule is sufficient:
proxy.server = ( ".jsp" =>
(
( "host" => "127.0.0.1",
"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" => "127.0.0.1",
"port" => "12345"
)
)
)
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" => "127.0.0.1",
"port" => "12345"
)
)
)
}
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 gra0.com 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"
)
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"] == "olddomain.com" {
url.redirect = (
"^/(.*)___FCKpd___9quot; => "http://newdomain.com/$1"
)
}
127.0.0.1
. If you need the original address, log the X-FORWARDED-FOR
header. mod_expire
to make resources cacheable. Doing so can make your site a lot faster and save you money.