{"id":475,"date":"2008-01-28T00:00:00","date_gmt":"2008-01-27T16:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=475"},"modified":"2011-07-15T09:44:41","modified_gmt":"2011-07-15T01:44:41","slug":"lighttpd-configure-java-web-server","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=475","title":{"rendered":"lighttpd configure java web server"},"content":{"rendered":"<p><DIV>\u6211\u7684apache 2.061\u5728window 2003 \u4e0b\u8001\u662f\u62a5\u544a\u9519\u8bef,\u867d\u7136\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4f46\u611f\u89c9\u5f88\u4e0d\u723d.<BR>\u9519\u8bef\u5165\u4e0b,\u627e\u4e86\u5f88\u4e45\u4e5f\u6ca1\u6709\u529e\u6cd5,\u5305\u62ec\u4fee\u590dsockt\u4e5f\u6ca1\u7528.<BR>\u62a5\u544a\u961f\u5217\u4e2d\u7684\u9519\u8bef: \u9519\u8bef\u5e94\u7528\u7a0b\u5e8f Apache.exe\uff0c\u7248\u672c 2.0.61.200\uff0c\u9519\u8bef\u6a21\u5757 ntdll.dll\uff0c\u7248\u672c 5.2.3790.3959\uff0c\u9519\u8bef\u5730<BR><BR>\u4e00\u76f4\u60f3\u627e\u4e00\u4e2a\u66ff\u4ee3apache\u7684\u8f6f\u4ef6,\u6700\u8fd1\u770b\u4e86lighttpd\u60f3\u7528lighttpd\u6765\u66ff\u4ee3apache,\u5148\u4e0b\u653e\u8fc7\u8d44\u6599.<BR>\u4e0b\u8f7d\u5730\u5740.<BR>http:\/\/ftp.dtech.hu\/pub\/WLMP-Project\/LightTPD-Win32\/<BR><BR><BR><br \/>\n<H2>. When to use lighttpd<\/H2><br \/>\n<P>You can use lighttpd to<\/P><br \/>\n<UL><br \/>\n<LI>secure access to your application server<br \/>\n<LI>reduce load on your server by offloading static requests<br \/>\n<LI>load balance your application servers<br \/>\n<LI>use lighttpd\u2019s <A href=\"http:\/\/johannburkard.de\/blog\/www\/spam\/introduction-to-blocking-spambots-and-bad-bots.html\">spambot and bad bot blocking<\/A> capabilities<br \/>\n<LI>get more request rewriting and redirecting flexibility<br \/>\n<LI>use the above flexibility to improve your search engine rankings<br \/>\n<LI>profit.<\/LI><\/UL><br \/>\n<H2>2. When not to use lighttpd<\/H2><br \/>\n<P>You might not like lighttpd if you<\/P><br \/>\n<UL><br \/>\n<LI>don\u2019t like configuring software<br \/>\n<LI>use <ACRONYM title=\"Uniform Resource Locator\">URL<\/ACRONYM> rewriting and <CODE>;jsessionid<\/CODE> (though a <A href=\"http:\/\/johannburkard.de\/blog\/bla\/Tux-to-lighttpd.html\">patch<\/A> is available for this problem).<\/LI><\/UL><br \/>\n<H2>3. lighttpd modules you need<\/H2><br \/>\n<P>The following lighty modules are needed:<\/P><br \/>\n<UL><br \/>\n<LI>mod_access<br \/>\n<LI>mod_redirect<br \/>\n<LI>mod_rewrite<br \/>\n<LI>mod_proxy<\/LI><\/UL><br \/>\n<P>Add them to your <CODE>server.modules<\/CODE> section:<\/P><PRE>server.modules = (<BR> &#8220;mod_accesslog&#8221;,<BR> <STRONG>&#8220;mod_access&#8221;,<BR> &#8220;mod_redirect&#8221;,<BR> &#8220;mod_rewrite&#8221;,<BR> &#8220;mod_proxy&#8221;<\/STRONG>,<BR> &#8220;mod_status&#8221;,<BR> &#8220;mod_evhost&#8221;,<BR> &#8220;mod_expire&#8221;<BR>)<BR><\/PRE><br \/>\n<H2>4. Denying access to <ACRONYM title=\"Java Enterprise Edition\">JEE<\/ACRONYM> directories<\/H2><br \/>\n<P>The <CODE>WEB-INF<\/CODE> and <CODE>META-INF<\/CODE> directories shouldn\u2019t be accessible through lighttpd. Files from your development environment also shouldn\u2019t be visible.<\/P><PRE>url.access-deny = ( &#8220;WEB-INF&#8221;, &#8220;.classpath&#8221;, &#8220;.project&#8221;, &#8220;META-INF&#8221; )<BR><\/PRE><br \/>\n<H2>5. Binding your application server to localhost<\/H2><br \/>\n<P>To prevent duplicate content penalties, your application server shouldn\u2019t be visible from the web. Even if you run it on a high port, <A href=\"http:\/\/help.yahoo.com\/l\/us\/yahoo\/search\/webcrawler\/\">someone<\/A> might eventually find it.<\/P><br \/>\n<P>Binding a web site to localhost looks like this in <A href=\"http:\/\/www.orionserver.com\/\">Orion<\/A>\u2019s <CODE>&lt;name&gt;-web-site.xml<\/CODE>:<\/P><PRE>&lt;web-site <STRONG>host=&#8221;127.0.0.1&#8243; port=&#8221;12345&#8243;<\/STRONG>&gt;<BR>\t&lt;frontend host=&#8221;johannburkard.de&#8221; port=&#8221;80&#8243;\/&gt;<BR><\/PRE><br \/>\n<P>Consult your documentation if you aren\u2019t using Orion.<\/P><br \/>\n<H2>6. Redirecting <CODE>www.<\/CODE> to non-<CODE>www.<\/CODE> hosts<\/H2><br \/>\n<P>Even if you don\u2019t really <EM>need<\/EM> to do this, I recommend doing so. Removing duplicate content <EM>will<\/EM> improve your rankings.<\/P><br \/>\n<P>The following snippet redirects all visitors from <CODE>www.&lt;domain&gt;<\/CODE> to <CODE>&lt;domain&gt;<\/CODE> with a <CODE>301<\/CODE> permanent redirect.<\/P><PRE>$HTTP[&#8220;host&#8221;] =~ &#8220;^www\\.(.*)___FCKpd___3quot; {<BR> url.redirect = ( &#8220;^\/(.*)&#8221; =&gt; &#8220;http:\/\/%1\/$1&#8221; )<BR>}<BR><\/PRE><br \/>\n<P>You should also redirect all additional domains (<CODE>johannburkard.com<\/CODE>, <CODE>johann-burkard.org<\/CODE>) to your main domain.<\/P><br \/>\n<H2>7. Proxying dynamic requests<\/H2><br \/>\n<P>We will use <CODE>mod_proxy<\/CODE> to proxy some requests to your Java application server.<\/P><br \/>\n<P>Depending on your site\u2019s structure, one of the following approaches will work better.<\/P><br \/>\n<H3>Simple <ACRONYM title=\"Java Server Pages\">JSP<\/ACRONYM><\/H3><br \/>\n<P>If all you have is a bunch of Java Server Pages, the following <CODE>mod_proxy<\/CODE> rule is sufficient:<\/P><PRE>proxy.server = ( &#8220;.jsp&#8221; =&gt;<BR> (<BR>  ( &#8220;host&#8221; =&gt; &#8220;127.0.0.1&#8221;,<BR>    &#8220;port&#8221; =&gt; <STRONG>&#8220;12345&#8221;<\/STRONG><BR>  )<BR> )<BR>)<BR><\/PRE><br \/>\n<P>Note that the <ACRONYM title=\"Java Server Pages\">JSP<\/ACRONYM> <EM>must be actual files<\/EM>. You cannot use Servlets mapped to these <ACRONYM title=\"Uniform Resource Identifier\">URI<\/ACRONYM>s.<\/P><br \/>\n<H3>Applications<\/H3><br \/>\n<P>If you use Servlets or more complex applications, you can proxy <ACRONYM title=\"Uniform Resource Identifier\">URI<\/ACRONYM>s by prefix:<\/P><PRE>proxy.server = ( &#8220;\/blog\/&#8221; =&gt;<BR> (<BR>  ( &#8220;host&#8221; =&gt; &#8220;127.0.0.1&#8221;,<BR>    &#8220;port&#8221; =&gt; &#8220;12345&#8221;<BR>  )<BR> )<BR>)<BR><\/PRE><br \/>\n<H3>Proxying with exceptions<\/H3><br \/>\n<P>If most of your site is dynamic and you have a directory for static content (<CODE>\/assets<\/CODE>, <CODE>\/static<\/CODE> or so), you can proxy all requests <EM>except<\/EM> requests for static files:<\/P><PRE>$HTTP[&#8220;url&#8221;] !~ &#8220;^\/static&#8221; {<BR> proxy.server = ( &#8220;&#8221; =&gt;<BR>  (<BR>   ( &#8220;host&#8221; =&gt; &#8220;127.0.0.1&#8221;,<BR>     &#8220;port&#8221; =&gt; &#8220;12345&#8221;<BR>   )<BR>  )<BR> )<BR>}<BR><\/PRE><br \/>\n<H2>8. Rewriting requests<\/H2><br \/>\n<P>lighttpd can dynamically rewrite requests. I mostly use this to use <CODE>default.jsp<\/CODE> as dynamic index file instead of <CODE>index.html<\/CODE>. Here\u2019s an example:<\/P><PRE>url.rewrite-once = ( &#8220;^(.*)\/___FCKpd___7quot; =&gt; &#8220;$1\/default.jsp&#8221;,<BR> &#8220;^(.*)\/([;?]+.*)___FCKpd___7quot; =&gt; &#8220;$1\/default.jsp$2&#8221; )<BR><\/PRE><br \/>\n<P>This is visible at <A href=\"http:\/\/gra0.com\/\">gra0.com<\/A> and internally rewrites all requests from <CODE>\/<\/CODE> to <CODE>\/default.jsp<\/CODE> (including <CODE>jsessionid<\/CODE> and query string).<\/P><br \/>\n<P><CODE>mod_rewrite<\/CODE> can also be used to make <ACRONYM title=\"Uniform Resource Locator\">URL<\/ACRONYM>s shorter. For example, to remove the <CODE>?page=comments<\/CODE> query string, I use the following:<\/P><PRE>url.rewrite-once = (<BR> &#8220;^\/blog\/(.*)\\.html___FCKpd___8quot; =&gt; &#8220;\/blog\/$1.html?page=comments&#8221;<BR>)<BR><\/PRE><br \/>\n<H2>9. Redirecting requests<\/H2><br \/>\n<P>You can use <CODE>mod_redirect<\/CODE> to redirect the user to a different <ACRONYM title=\"Uniform Resource Locator\">URL<\/ACRONYM>. Contrary to <CODE>mod_rewrite<\/CODE> where the request is rewritten, a <CODE>301<\/CODE> permanent redirect will be sent to the browser.<\/P><br \/>\n<P>In this example, I\u2019m redirecting requests to an old domain to a new domain:<\/P><PRE>$HTTP[&#8220;host&#8221;] == &#8220;olddomain.com&#8221; {<BR> url.redirect = (<BR>  &#8220;^\/(.*)___FCKpd___9quot; =&gt; &#8220;http:\/\/newdomain.com\/$1&#8221;<BR> )<BR>}<BR><\/PRE><br \/>\n<H2>10. More things to be aware of<\/H2><br \/>\n<UL><br \/>\n<LI>The only <ACRONYM title=\"Internet Protocol\">IP<\/ACRONYM> address in your application server log files should be <CODE>127.0.0.1<\/CODE>. If you need the original address, log the <CODE>X-FORWARDED-FOR<\/CODE> header.<br \/>\n<LI>Don\u2019t analyze both lighttpd and application server logs&nbsp;\u2013&nbsp;lighty\u2019s log files already contain all requests.<br \/>\n<LI>You might want to set up <A href=\"http:\/\/johannburkard.de\/blog\/www\/simple-virtual-hosts-vhosts-with-lighttpd.html\">virtual hosts<\/A> sooner or later.<br \/>\n<LI>Use <CODE>mod_expire<\/CODE> to make resources cacheable. Doing so can make your site a lot faster and save you money.<\/LI><\/UL><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u7684apache 2.061\u5728window 2003 \u4e0b\u8001\u662f\u62a5\u544a\u9519\u8bef,\u867d\u7136\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4f46\u611f\u89c9\u5f88\u4e0d\u723d.\u9519\u8bef\u5165\u4e0b,\u627e\u4e86\u5f88\u4e45\u4e5f\u6ca1\u6709\u529e\u6cd5,\u5305\u62ec\u4fee\u590dsockt\u4e5f\u6ca1\u7528.\u62a5\u544a\u961f\u5217\u4e2d\u7684\u9519\u8bef: \u9519\u8bef\u5e94\u7528\u7a0b\u5e8f Apache.exe\uff0c\u7248\u672c 2.0.61.200\uff0c\u9519\u8bef\u6a21\u5757 ntdll.dll\uff0c\u7248\u672c 5.2.3790.3959\uff0c\u9519\u8bef\u5730\u4e00\u76f4\u60f3\u627e\u4e00\u4e2a\u66ff\u4ee3apache\u7684\u8f6f\u4ef6,\u6700\u8fd1\u770b\u4e86lighttpd\u60f3\u7528lighttpd\u6765\u66ff\u4ee3apache,\u5148\u4e0b\u653e\u8fc7\u8d44\u6599.\u4e0b\u8f7d\u5730\u5740.http:\/\/ftp.dtech.hu\/pub\/WLMP-Project\/LightTPD-Win32\/ . 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\u2019s spambot and bad bot blocking capabilities get more request rewriting and redirecting flexibility use &hellip; <a href=\"https:\/\/www.strongd.net\/?p=475\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">lighttpd configure java web server<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,20],"tags":[61],"class_list":["post-475","post","type-post","status-publish","format-standard","hentry","category-linux","category-20","tag-lighttpd"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=475"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/475\/revisions"}],"predecessor-version":[{"id":895,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/475\/revisions\/895"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}