JBoss Web Server User's Guide
JBoss Web Server User's Guide
ii
1
About JBoss Web
JBoss Web is a key component in the JBoss Enterprise Middleware Stack (JEMS). It is runs Java EE, Microsoft
ASP.Net, PHP, and CGI applications with native performance matching or even exceeding the Apache Web Serv-
er. JBoss Web will replace Tomcat and become the default servlet / JSP container in JBoss AS 5.x and later.
In this guide, we discuss how to install and use the JBoss Web Server. We cover JBoss Web configuration options,
performance considerations, as well as how to run non-Java applications on the server.
This guide is work in progress. Please send your suggestions or comments to the JBoss Web user forum
[http://www.jboss.com/index.html?module=bb&op=viewforum&f=230].
1
2
Introducing JBoss Web
JBoss Web Server provides enterprises with a single, high-performance deployment platform for Java EE, Mi-
crosoft ASP.NET, PHP and CGI script technologies. It is meant to be used as a replacement for the standard Web
servers on all major platforms. JBoss Web is built on Apache Tomcat and Apache Portable Runtime (APR) techno-
logies. It brings together the best of both worlds of Java EE servers and native HTTP servers.
Apache Tomcat is a full Java Servlet and Java Server Pages (JSP) server. It is a very popular Java application serv-
er and is the default servlet container inside the JBoss AS 4.x. However, the plain Apache Tomcat does not perform
well in many areas, such as in supporting keep-alive connections, static contents, large files, HTTPS etc. JBoss
Web solves those performance problems by leveraging a hybrid model with APR and Tomcat native technologies.
The hybrid technology model offers the best from threading and event processing models from the latest OS tech-
nologies. As a result, JBoss Web server achieves scalability and performance characteristics that match or exceed
the native Apache HTTP Server or IIS. For instance, SSL performance in JBoss Web is almost 4 times faster than
that in plain Tomcat (Figure 2.1).
Aside from performance issues, another shortcoming of Apache Tomcat is that it is a limited integration platform.
2
Introducing JBoss Web
Tomcat runs only Java applications. If you want to run PHP/CGI scripts side-by-side with your Java applications,
you have to front Tomcat with the Apache Web Server or other native web servers. The APR-based hybrid model
in JBoss Web supports both in- and out-of-process execution of CGI and PHP scripts. Furthermore, JBoss Web
supports ASP.Net applications, and allows Java applications to access running .Net services and objects.
For Java EE application developers, JBoss Web is a complete replacement for the Apache Web Server +
Tomcat + mod_jk stack.
• Full Java EE Support: The power of JBoss Web comes with full Java EE support. Inheriting from Apache Tom-
cat, JBoss Web supports the JSP 2.0 and Servlet 2.4 specifications, providing a complete web development en-
vironment. With add-on JSF libraries (e.g., Apache MyFaces) and JBoss embeddable EJB3 libraries, you can
deploy full Java EE 5.0 applications in JBoss Web. JBoss Web runs in the same VM as the JBoss application
server, providing a complete environment for everything from simple web applications to complex high-end en-
terprise applications.
• Highly Scalable: JBoss Web scales to the levels required by the most demanding of applications. As we dis-
cussed, it out-performs Tomcat by several times and matches the performance of the native Apache Web Server
and IIS. The hybrid connection model can handle client loads of 10,000+ concurrent connections.
• Fast Static Content: JBoss Web takes advantage of fast OS-specific features to achieve zero-copy transfer of
static content. This decreases CPU load and improves application responsiveness.
• Clustering Support: JBoss Web can serve an amazing number of requests on a single machine, but when you
need to scale beyond that, JBoss Web is there. JBoss web offers full clustering support for web applications.
JBoss Web HTTP session replication is based on the powerful JBossCache technology, allowing your applica-
tion state to be efficiently shared between all the nodes in your application cluster.
• OpenSSL Support: The security of your web application matters. SSL is the cornerstone of web security, but
Java SSL engines are slow and can put a big burden on your CPU. JBossWeb integrates the native OpenSSL
libraries, the fastest and most secure open source SSL implementation. The highly-optimized OpenSSL librar-
ies also allow for hardware acceleration which yield a ten fold performance increase.
• URL Rewriting: JBoss Web provides a powerful URL rewriting module, similar to Apache mod_rewrite. URLs
can be rewritten to support legacy URLs, handle errors or rapidly respond to web application issues that come
up in the hectic day-to-day management of web applications.
• Integration: JBoss Web Server provides organizations with a single deployment platform for the most common
types of web applications. Not only does JBoss Web support the latest Java web technologies, but also JBoss
web can also support applications running on Microsoft .NET, PHP, and CGI. There is no longer any need to
manage multiple servers for multiple web platforms. Legacy applications can maintained on JBoss Web, right
along side your other applications. New development can take advantage of powerful features of any of these
web platforms. JBoss Web gives you the power to choose the right platform for each task, and total flexibility
to make changes along the way.
3
3
Getting Started
In this chapter, we will cover the steps to install the JBoss Web Server and deploy Java EE applications on it. If
you are interested in running PHP, CGI, and ASP.Net applications on JBoss Web, please refer to ???, ???, and ???
respectively.
Uncompress the distribution wherever you would like JBoss Web installed. The resulting directory
(jbossweb-1.0.1.GA-linux-i686, for example) contains the JBoss Web instance.
The last line is the message JBoss sends when all services are up and running, letting you know that everything is
good. However, the two lines before it are important for JBoss Web. They tell you that JBoss Web is listening on
two ports, 8080 and 8009. More importantly, you can see from the output that JBoss Web is using the APR(Apache
portable runtime) libraries. This means that you are using the optimized native libraries. Without the APR libraries,
you would see output more like the following, with no reference to the APR code.
4
Getting Started
In worse cases, like using the wrong version of the libraries for your platform, JBoss Web may completely fail to
start. If there is an error, check the console log (the output in your terminal window) or the server log in server/de-
fault/log/server.log for more information about the problem.
To access your JBoss Web instance, go to http://localhost:8080/ in your web browser. If everything went well, you
will see the JBoss Web start welcome screen. Congratulations, your JBoss Web instance is ready to go.
The ctxPath value is /myapp, which means the application would immediately be accessible at ht-
tp://localhost:8080/myapp.
Changes to the application can be made by copying a newer version of the WAR file into the deploy directory. If
you need to remove an application, remove the WAR file from the deploy directory. JBoss Web will undeploy the
application, noting the fact in the log.
To install the JBoss Web server as Windows service use the provided service.bat batch file.
C:\> cd c:\jbossweb-1.0.1.GA-windows-i586\bin
C:\> service.bat install
To start the JBoss Web server as Windows service use Control pannel or net start command. When running in ser-
vice mode the console output is redirected to the file run.log. You can inspect the file for any errors during service
startup.
5
Getting Started
To stop the JBoss Web server as Windows service use Control pannel or net stop command. When running in ser-
vice mode the console output is redirected to the file shutdown.log. You can inspect the file for any errors during
service shutdown.
To restart the JBoss Web server as Windows service use Control pannel.
To remove the JBoss Web server as Windows service use the provided service.bat batch file.
C:\> cd c:\jbossweb-1.0.1.GA-windows-i586\bin
C:\> service.bat uninstall
Service customization is done by editing the service.bat script. Each command has a separate section that you can
customize. The most common customization task would be changing service names if more then one service in-
stances per box are required.
6
4
Architecture Overview
In the previous chapter, you learned how to download, install, and run the JBoss Web Server. In this chapter, we
will discuss the overall architecture of the server. It provides the basis for the understanding the configuration op-
tions and modules later in this guide.
Additional modules allows to use the JBoss Web Server as drop-in replacement for standard native web servers,
while offering the Reference Implementation for the Java Servlet and JavaServer Pages technologies. The Java Ser-
vlet and JavaServer Pages specifications are developed by Sun under the Java Community Process.
Figure 4.1 shows the JBoss Web Server architecture. The brief description of architecture components is described
in the following sections.
JBoss Web Server currently uses the Apache Tomcat 5.5.x branch. While it supports the same Servlet and JSP Spe-
cification versions (i.e., servlet 2.4 and JSP 2.0) as Apache Tomcat 5.0.x, there are significant changes in many
areas under the hood, resulting in improved performance, stability, and total cost of ownership.
The Java servlet 2.5 and JSP 2.1 specifications are to be supported by Tomcat 6.0.x, planned for the second half of
7
Architecture Overview
2006.
JBoss Cache is a replicated and transactional cache. It is replicated since multiple JBossCache instances can be dis-
tributed (within the same JVM or across several JVMs whether they reside on the same machine or on different
machines on a network) and data is replicated across the whole group. It is transactional because a user can config-
ure a JTA transaction manager and make the cache operation transactional. Note that the cache can also be run
without any replication; this is the local mode.
Currently, it consists of two components: TreeCache and TreeCacheAop. TreeCache is a tree-structured cache that
provides replication and transaction context, while TreeCacheAop extends the functionality of TreeCache but be-
haves as a true object cache providing transparent and finer-grained object mapping into internal cache.
A clean room implementation of the Java Transaction API part of the J2EE specification, JBoss JTA is made up of
a number of a components and interfaces. The interfaces can be used when you change the transaction manager im-
plementation (i.e., plugin a thirdparty implementation).
A clean room implementation of the J2EE Connector API part of the J2EE specification, JBoss JCA handles the
deployment of resource adapters. These include DataSources and ConnectionFactorys and MessageListeners to and
from databases, legacy systems or JMS Servers
The JBoss Microkernel is a set of MBeans that runs on top of JBossMX. It has been designed to be totally modular
from the ground up. Support classes exists to extend the notion of an MBean into a Service or Deployer.
JBoss MX isJBoss implementation of the JMX technology. JBoss includes a clean room implementation of the
JMX API's published by Sun Microsystems. While implementing all the required management functions it is also
geared towards acting as a core library of the JBoss Microkernel. JBoss MX supports version 1.2 of the JMX spe-
cification (JSR 003) since JBoss versions 3.2.5 and 4.0.0. Support for the JMX Remote API (JSR 160) is under de-
velopment.
8
Architecture Overview
Tomcat Native is JNI based library for Operating System Abstraction. The core functionality of Tomcat Native is
provided by using Apache Portable Runtime (APR). The primary goal of APR is to provide an API to which soft-
ware developers may code and be assured of predictable if not identical behavior regardless of the platform on
which their software is built, relieving them of the need to code special-case conditions to work around or take ad-
vantage of platform-specific deficiencies or features.
SSL support is enabled by using the OpenSSL library. This gives much higher performance as well as hardware en-
cryption software support then standard Java offers. It also gives exixting users of Apache HTTPD a seamless
transition from mod_ssl.
Tomcat Native uses APR and OpenSSL to provide superior scalability, performance, and better integration with
native server technologies (see Figure 4.3). The Apache Portable Runtime is a highly portable library that is at the
heart of Apache HTTP Server 2.x. APR has many uses, including access to advanced IO functionality (such as
sendfile, epoll and TCP corking), OS level functionality (random number generation, system status, etc), and native
process handling (shared memory, NT pipes and Unix domain sockets).
9
Architecture Overview
Tomcat Native comes as a set of libraries compiled for the designated Operating System. JBoss Web Server down-
load comes with prebuild native libraries for the following platforms:
• WIN32
• WIN64/AMD64
• WIN64/IA64
• Linux i386
• Linux amd64
NativeProxy is Servlet abstraction that enables both in-process and out-of-process access to the legacy subsystems
regardless of the method that is used for the integrated within the JBoss Web Server (see Figure 4.4). NativeProxy
has integrated advanced application load balancer that offers both high availability and application segmantation
for remotely based subsystems.
10
Architecture Overview
Out of process mosules are accessed using Native proxy. Each of the module is run as a daemon either on the local
or remote machine. This gives much higer security and stabilty in case of faulty modules.
Proxy stream is a protocol very much similar to the Tomcat AJP/1.3 protocol, with additions for using Operating
system advanced connection mechanisms like Unix Domain Sockets or Microsoft Windows Named Pipes. It offers
both connection reuse and connection multiplexing. Unlike AJP/1.3 the data transferred can be encrypted, thus
rising the security without the need for special network hardware and topology.
The main purpose for Proxy Steam Protocol is to give transparent access to the out-of-process legacy subsystems
that can be hosted on the remote machine.
This componet is JNI based native abstraction layer for various http centic legacy subsystem. It is responsible for
loading the legacy applications inside the process address space of the running JVM.
This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs
on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each
rule to provide a really flexible and powerful URL manipulation mechanism. The URL manipulations can depend
on various tests, for instance server variables, environment variables, HTTP headers, time stamps and even external
database lookups in various formats can be used to achieve a really granular URL matching.
11
Architecture Overview
12
5
Configuring Connectors
Connectors are crucial components in the JBoss Web Server. They are outward interface of the server. For in-
stance, when a web browser client needs to connect to the server, it has to connect to one of the connectors. The
connectors are configured as XML elements in the server.xml file. In this chapter, we will cover HTTP, HTTPS
and AJP connectors.
<Connector port="8080"
maxThreads="250" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"/>
Attribute Description
address For servers with more than one IP address, this attrib-
ute specifies which address will be used for listening
on the specified port. By default, this port will be
used on all IP addresses associated with the server.
bufferSize The size (in bytes) of the buffer to be provided for in-
put streams created by this connector. By default,
buffers of 2048 bytes will be provided.
13
Configuring Connectors
Attribute Description
emptySessionPath If set to true, all paths for session cookies will be set
to /. This can be useful for portlet specification imple-
mentations, but will greatly affect performance if
many applications are accessed on a given server by
the client. If not specified, this attribute is set to false.
firstReadTimeout The first read of a request will be made using the spe-
cified timeout. If no data is available after the spe-
cified time, the socket will be placed in the poller.
Setting this value to 0 will increase scalability, but
14
Configuring Connectors
Attribute Description
15
Configuring Connectors
Attribute Description
scheme Set this attribute to the name of the protocol you wish
to have returned by calls to request.getScheme(). For
example, you would set this attribute to "https" for an
SSL Connector. The default value is "http".
16
Configuring Connectors
Attribute Description
server The Server header for the http response. Unless your
paranoid, you won't need this feature.
useSendfile Use kernel level sendfile for certain static files. The
default value is true.
17
Configuring Connectors
The HTTPS APR connector has the same basic attributes than the HTTP APR connector, but adds OpenSSL spe-
cific ones. For instance, here is an example of the HTTPS connector:
For the full details on using OpenSSL, please refer to OpenSSL documentations and the many books available for
it (see the Official OpenSSL website). The SSL specific attributes for the connector are listed in the following ta-
ble.
Attribute Description
SSLCertificateKeyFile Name of the file that contains the server private key.
The format is PEM-encoded. The default value is the
value of "SSLCertificateFile" and in this case both
certificate and private key have to be in this file
(NOT RECOMMENDED).
18
Configuring Connectors
Attribute Description
The AJP connector uses a socket poller for keepalive, increasing scalability of the server. As AJP is designed
around a pool of persistent (or almost persistent) connections, this will reduce significantly the amount of pro-
cessing threads needed by JBoss Web. Unlike the HTTP connector, the AJP connector cannot use sendfile to op-
timize static file processing. Below is an example configuration for an AJP connector.
<Connector port="8009"
emptySessionPath="true" enableLookups="false"
redirectPort="8443" protocol="AJP/1.3"/>
The following attributes are supported in the AJP connector. Many of the attributes are very similar to the HTTP
connector we have seen above.
19
Configuring Connectors
Attribute Description
address For servers with more than one IP address, this attrib-
ute specifies which address will be used for listening
on the specified port. By default, this port will be
used on all IP addresses associated with the server. A
value of 127.0.0.1 indicates that the Connector will
only listen on the loopback interface.
emptySessionPath If set to true, all paths for session cookies will be set
to /. This can be useful for portlet specification imple-
mentations, but will greatly affect performance if
many applications are accessed on a given server by
the client. If not specified, this attribute is set to false.
firstReadTimeout The first read of a request will be made using the spe-
cified timeout. If no data is available after the spe-
cified time, the socket will be placed in the poller.
Setting this value to 0 will increase scalability, but
will have a minor impact on latency (see the related
pollTime attribute). The default value is 100 (100ms).
Note: on Windows, the actual value of firstRead-
Timeout will be 500 + the specified value.
20
Configuring Connectors
Attribute Description
21
Configuring Connectors
Attribute Description
scheme Set this attribute to the name of the protocol you wish
to have returned by calls to request.getScheme(). For
example, you would set this attribute to "https" for an
SSL Connector. The default value is "http".
22
Configuring Connectors
Attribute Description
value is false.
23
6
URL Rewriting
One of the most popular module in the Apache Web Server is the mod_rewrite module, which allows the web mas-
ter to map any internal URL to arbitrary public URLs. The JBoss Web Server provides a servlet valve that imple-
ment the same functionalities as mod_rewrite.
In order to use the URL rewrite valve, you have to add the following XML element to the JBoss Web's server.xml,
or the web application's context.xml configuration file.
The valve will then use a rewrite.properties file for the rewrite conditions and rules. The rewrite.properties file loc-
ation depends on where you put the Valve element in the configuration file:
• If the Valve element is inside an Engine element in server.xml, the rewrite.properties file should be placed in a
folder with the same name as the Engine. This folder should be placed either in the classloader, or in the
$JBoss/server/default/conf directory (replace default with the configuration you use, if needed).
• If the Valve element is inside a Host element in server.xml, the rewrite.properties file should be placed in a
folder named engine_name/host_name, which is placed either in the classloader, or in the conf folder of the cur-
rent JBoss configuration.
• If the Valve element is inside the context.xml file for a web application, the rewrite.properties file should be
placed in the WEB-INF folder of the web application.
The rewrite.properties file contains a list of directives which closely resemble the directives used by mod_rewrite,
in particular the central RewriteRule and RewriteCond directives. For instance, the following rules in the re-
write.properties file make the server serve different files based on the client browser type in the HTTP request's
"User-Agent:" header.
If you use a browser which identifies itself as 'Mozilla' (including Netscape Navigator, Mozilla etc), then you get
the max homepage (which could include frames, or other special features). If you use the Lynx browser (which is
terminal-based), then you get the min homepage (which could be a version designed for easy, text-only browsing).
24
URL Rewriting
If neither of these conditions apply (you use any other browser, or your browser identifies itself as something non-
standard), you get the std (standard) homepage.
In the next two sections, we will discuss the syntax of the RewriteRule and RewriteCond directives.
6.1. RewriteCond
The RewriteCond directive defines a rule condition. One or more RewriteCond can precede a RewriteRule direct-
ive. The following rule is then only used if both the current state of the URI matches its pattern, and if these condi-
tions are met. Its syntax is as follows.
The TestString typically contains variables in the form of %{NAME_OF_VARIABLE}, where the
NAME_OF_VARIABLE refers to a server property or a property related to the current HTTP request. The follow-
ing
These variables all correspond to the similarly named HTTP MIME-headers and Servlet API methods. Most are
documented elsewhere in the Manual or in the CGI specification. Those that are special to the rewrite valve include
25
URL Rewriting
those below.
• THE_REQUEST: The full HTTP request line sent by the browser to the server (e.g., "GET /index.html HTTP/
1.1"). This does not include any additional headers sent by the browser.
• REQUEST_URI: The resource requested in the HTTP request line. (In the example above, this would be "/
index.html".)
• REQUEST_FILENAME: The full local filesystem path to the file or script matching the request.
• HTTPS: Will contain the text "on" if the connection is using SSL/TLS, or "off" otherwise.
• The variables SCRIPT_FILENAME and REQUEST_FILENAME contain the same value - the value of the fi-
lename field of the internal request_rec structure of the Apache server. The first name is the commonly known
CGI variable name while the second is the appropriate counterpart of REQUEST_URI (which contains the
value of the uri field of request_rec).
• ENV:variable: the variable can be the name of any Java system property, is also available.
• SSL:variable: the variable is the name of an SSL environment variable. This feature has not been implemented
yet.
• HTTP:header: the header can be any HTTP MIME-header name. It can always be used to obtain the value of a
header sent in the HTTP request. For instance, the %{HTTP:Proxy-Connection} symbol represents the value of
the HTTP header "Proxy-Connection:".
You can also insert back reference to the Nth matched group (in parentheses) in the current RewriteRule and last
matched RewriteCond regular expressions using the $N and %N symbols in the text string.
In addition, you can put arbitrary dynamic content into the text string via the RewriteMap directive. A RewriteMap
directive looks like the following:
The maps are implemented using an interface that users must implement. Its class name is
org.jboss.web.rewrite.RewriteMap, and its code is:
package org.jboss.web.rewrite;
26
URL Rewriting
Then, in the RewriteCond text string, we can use the form ${mapname:key|default}.
CondPattern is the condition pattern, a regular expression which is applied to the current instance of the TestString.
TestString is first evaluated, before being matched against CondPattern. CondPattern is a perl compatible regular
expression with the following additions.
• You can prefix the pattern string with a '!' character (exclamation mark) to specify a non-matching pattern.
• There are some special variants of CondPatterns. Instead of real regular expression strings you can also use one
of the following:
• '<CondPattern' (lexicographically precedes) treats the CondPattern as a plain string and compares it lexico-
graphically to TestString. True if TestString lexicographically precedes CondPattern.
• '>CondPattern' (lexicographically follows) treats the CondPattern as a plain string and compares it lexico-
graphically to TestString. True if TestString lexicographically follows CondPattern.
• '=CondPattern' (lexicographically equal) treats the CondPattern as a plain string and compares it lexico-
graphically to TestString. True if TestString is lexicographically equal to CondPattern (the two strings are
exactly equal, character for character). If CondPattern is "" (two quotation marks) this compares TestString
to the empty string.
• '-d' (is directory) treats the TestString as a pathname and tests whether or not it exists, and is a directory.
• '-f' (is regular file) treats the TestString as a pathname and tests whether or not it exists, and is a regular file.
• '-s' (is regular file, with size) treats the TestString as a pathname and tests whether or not it exists, and is a
regular file with size greater than zero.
• You can also set special flags for CondPattern by appending [flags] as the third argument to the RewriteCond
directive, where flags is a comma-separated list of any of the following flags:
• 'nocase|NC' (no case) makes the test case-insensitive - differences between 'A-Z' and 'a-z' are ignored, both
in the expanded TestString and the CondPattern. This flag is effective only for comparisons between Test-
String and CondPattern. It has no effect on filesystem and subrequest checks.
• 'ornext|OR' (or next condition) combines rule conditions with a local OR instead of the implicit AND.
An example of the OR flag is as follows. Without this flag you would have to write the condition/rule pair three
times.
6.2. RewriteRule
27
URL Rewriting
The RewriteRule directive is the real rewriting workhorse. The directive can occur more than once, with each in-
stance defining a single rewrite rule. The order in which these rules are defined is important - this is the order in
which they will be applied at run-time. The RewriteRule directive has the following syntax.
Pattern is a perl compatible regular expression, which is applied to the current URL, which is the value of the URL
when this rule is applied. This may not be the originally requested URL, which may already have matched a previ-
ous rule, and have been altered.
Like the regular expression in RewriteCond, the Pattern string here can also take the '!' prefix to negate a pattern.
When using the '!' character to negate a pattern, you cannot include grouped wildcard parts in that pattern. This is
because, when the pattern does NOT match (ie, the negation matches), there are no contents for the groups. Thus, if
negated patterns are used, you cannot use $N in the substitution string!
The Substitution of a rewrite rule is the string which is substituted for (or replaces) the original URL which Pattern
matched. In addition to plain text, it can include any server variable, back reference to matched parts, and Re-
writeMap extensions discussed in the previous section.
As already mentioned, all rewrite rules are applied to the Substitution (in the order in which they are defined in the
config file). The URL is completely replaced by the Substitution and the rewriting process continues until all rules
have been applied, or it is explicitly terminated by a flag.
There is a special substitution string named '-' which means: NO substitution! This is useful in providing rewriting
rules which only match URLs but do not substitute anything for them. It is commonly used in conjunction with the
C (chain) flag, in order to apply more than one pattern before substitution occurs.
Additionally you can set special flags for Substitution by appending [flags] as the third argument to the RewriteR-
ule directive. Flags is a comma-separated list of any of the following flags:
• 'chain|C' (chained with next rule): This flag chains the current rule with the next rule (which itself can be
chained with the following rule, and so on). This has the following effect: if a rule matches, then processing
continues as usual - the flag has no effect. If the rule does not match, then all following chained rules are
skipped. For instance, it can be used to remove the ".www" part, inside a per-directory rule set, when you let an
external redirect happen (where the ".www" part should not occur!).
• 'cookie|CO=NAME:VAL:domain[:lifetime[:path]]' (set cookie): This sets a cookie in the client's browser. The
cookie's name is specified by NAME and the value is VAL. The domain field is the domain of the cookie, such
as '.apache.org', the optional lifetime is the lifetime of the cookie in minutes, and the optional path is the path of
the cookie
• 'env|E=VAR:VAL' (set environment variable): This forces an environment variable named VAR to be set to the
value VAL, where VAL can contain regexp backreferences ($N and %N) which will be expanded. You can use
this flag more than once, to set more than one variable. The variables can later be dereferenced in many situ-
ations, most commonly from within XSSI (via <!--#echo var="VAR"-->) or CGI ($ENV{'VAR'}). You can
also dereference the variable in a later RewriteCond pattern, using %{ENV:VAR}. Use this to strip information
from URLs, while maintaining a record of that information.
28
URL Rewriting
• 'forbidden|F' (force URL to be forbidden): This forces the current URL to be forbidden - it immediately sends
back a HTTP response of 403 (FORBIDDEN). Use this flag in conjunction with appropriate RewriteConds to
conditionally block some URLs.
• 'gone|G' (force URL to be gone): This forces the current URL to be gone - it immediately sends back a HTTP
response of 410 (GONE). Use this flag to mark pages which no longer exist as gone.
• 'host|H=Host' (apply rewriting to host): Rather that rewrite the URL, the virtual host will be rewritten.
• 'last|L' (last rule): Stop the rewriting process here and don't apply any more rewrite rules. This corresponds to
the Perl last command or the break command in C. Use this flag to prevent the currently rewritten URL from
being rewritten further by following rules. For example, use it to rewrite the root-path URL ('/') to a real one,
e.g., '/e/www/'.
• 'next|N' (next round): Re-run the rewriting process (starting again with the first rewriting rule). This time, the
URL to match is no longer the original URL, but rather the URL returned by the last rewriting rule. This corres-
ponds to the Perl next command or the continue command in C. Use this flag to restart the rewriting process -
to immediately go to the top of the loop. Be careful not to create an infinite loop!
• 'nocase|NC' (no case): This makes the Pattern case-insensitive, ignoring difference between 'A-Z' and 'a-z' when
Pattern is matched against the current URL.
• 'noescape|NE' (no URI escaping of output): This flag prevents the rewrite valve from applying the usual URI
escaping rules to the result of a rewrite. Ordinarily, special characters (such as '%', '$', ';', and so on) will be es-
caped into their hexcode equivalents ('%25', '%24', and '%3B', respectively); this flag prevents this from hap-
pening. This allows percent symbols to appear in the output, as in RewriteRule /foo/(.*) /bar?arg=P1\%3d$1
[R,NE] which would turn '/foo/zed' into a safe request for '/bar?arg=P1=zed'.
• 'qsappend|QSA' (query string append: This flag forces the rewrite engine to append a query string part of the
substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the
query string via a rewrite rule.
• 'redirect|R [=code]' (force redirect): Prefix Substitution with http://thishost[:thisport]/ (which makes the new
URL a URI) to force a external redirection. If no code is given, a HTTP response of 302 (MOVED TEMPOR-
ARILY) will be returned. If you want to use other response codes in the range 300-400, simply specify the ap-
propriate number or use one of the following symbolic names: temp (default), permanent, seeother. Use this for
rules to canonicalize the URL and return it to the client - to translate ``/~'' into ``/u/'', or to always append a
slash to /u/user, etc. Note: When you use this flag, make sure that the substitution field is a valid URL! Other-
wise, you will be redirecting to an invalid location. Remember that this flag on its own will only prepend ht-
tp://thishost[:thisport]/ to the URL, and rewriting will continue. Usually, you will want to stop rewriting at this
point, and redirect immediately. To stop rewriting, you should add the 'L' flag.
• 'skip|S=num' (skip next rule(s)): This flag forces the rewriting engine to skip the next num rules in sequence, if
the current rule matches. Use this to make pseudo if-then-else constructs: The last rule of the then-clause be-
comes skip=N, where N is the number of rules in the else-clause. (This is not the same as the 'chain|C' flag!)
• 'type|T=MIME-type' (force MIME type): Force the MIME-type of the target file to be MIME-type. This can be
used to set up the content-type based on some conditions.
29
7
PHP
The PHP Module allows JBoss Web Server to run PHP scripts side-by-side with Java applications. It is a servlet
that calls a native embedded PHP engine with libraries extentions.
7.1. Installation
To install the PHP module, you have to download the binary library files for your specific platform from the JBoss
Web Server download page. If you do not see a pre-build binary for your platform, you can build it from the source
code package by running the buildphp.sh script.
Extract all the files from the downloaded tarball (or the build result), and put the PHP/lib/* files in your JBoss Web
Server installation directory. The add the following Listener element under the Server element of your conf/serv-
er.xml file.
<Listener className="org.apache.catalina.servlets.php.LifecycleListener"/>
<servlet>
<servlet-name>php</servlet-name>
<servlet-class>org.apache.catalina.servlets.php.Handler</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>6</load-on-startup>
</servlet>
<servlet>
<servlet-name>phps</servlet-name>
<servlet-class>org.apache.catalina.servlets.php.Highlight</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>php</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>phps</servlet-name>
<url-pattern>*.phps</url-pattern>
</servlet-mapping>
Finally, edit the bin/setenv.sh file to add the LD_LIBRARY_PATH variable and modify/add the java.library.path
parameter of the JVM:
30
PHP
CATALINA_OPTS="$CATALINA_OPTS -Djava.library.path=$CATALINA_HOME/PHP/lib"
LD_LIBRARY_PATH=$CATALINA_HOME/PHP/lib
export LD_LIBRARY_PATH
The webapps/php-examples.war war file of the PHP module tarball contains some php demo scripts. They are de-
ployed under /php-examples to use them you only need to modify the bin/setenv.sh as described above. You don't
have to modify the conf/web.xml nor the conf/server.xml files since the .war application itself configures the PHP
servlet and listener. You have to start and restart the servlet container because of the environment modifications. To
use the examples, try http://localhost:8080/php-examples/index.php.
extension_dir=/home/jfclere/SunOS_i386_tools/PHP/lib/php/extensions/
extension=openssl.so
extension=pdo_pgsql.so
extension=pgsql.so
31