| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>Configuring Jetty for FastCGI</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty"><link rel="up" href="fastcgi.html" title="Chapter 17. FastCGI Support"><link rel="prev" href="fastcgi.html" title="Chapter 17. FastCGI Support"><link rel="next" href="advanced-extras.html" title="Chapter 18. Provided Servlets, Filters, and Handlers"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><link rel="stylesheet" href="css/highlighter/foundation.css"><script src="js/highlight.pack.js"></script><script> |
| hljs.initHighlightingOnLoad(); |
| </script><link type="text/css" rel="stylesheet" href="css/font-awesome/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small"> |
| Version: 9.4.28-SNAPSHOT</span></td><td style="width: 50%"></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Configuring Jetty for FastCGI</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="fastcgi.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a> </td><th width="60%" align="center">Chapter 17. FastCGI Support<br><a accesskey="p" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></th><td width="20%" align="right"> <a accesskey="n" href="advanced-extras.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at |
| <span class="website">www.webtide.com</span></a></h5><p> |
| private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... |
| scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development |
| </p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="configuring-fastcgi"></a>Configuring Jetty for FastCGI</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="configuring-fastcgi.html#configuring-fastcgi-http2">Configuring Jetty to Proxy HTTP/2 to FastCGI</a></span></dt></dl></div><p>In this section you will see how to configure Jetty to serve WordPress via FastCGI.</p><p>The first step is to have WordPress installed on your server machine, for example under <code class="literal">/var/www/wordpress</code>. |
| For more information about how to install WordPress, please refer to the <a class="link" href="https://codex.wordpress.org/Installing_WordPress" target="_top">WordPress Installation Guide</a>.</p><p>The second step is to install <code class="literal">php-fpm</code> and make sure it is configured to listen on a TCP socket; typically it is configured to listen to <code class="literal">localhost:9000</code>.</p><p>The third step is to install Jetty, for example under <code class="literal">/opt/jetty</code>, called in the following <code class="literal">$JETTY_HOME</code>. |
| Refer to <a class="xref" href="quick-start-getting-started.html#jetty-downloading" title="Downloading Jetty">Downloading Jetty</a> for more information about how to install Jetty.</p><p>The fourth step is to create a Jetty base directory (see <a class="xref" href="startup-base-and-home.html" title="Managing Jetty Base and Jetty Home">Managing Jetty Base and Jetty Home</a>), called in the following <code class="literal">$JETTY_BASE</code>, where you setup the configuration needed to support FastCGI in Jetty, and configure the <code class="literal">fcgi</code>, <code class="literal">http</code> and <code class="literal">deploy</code> modules, so that Jetty will be able to accept HTTP requests from browsers, convert them in FastCGI, and proxy them to <code class="literal">php-fpm</code>:</p><div class="screenexample"><pre class="screen">$ mkdir -p /usr/jetty/wordpress |
| $ cd /usr/jetty/wordpress |
| $ java -jar $JETTY_HOME/start.jar --add-to-start=fcgi,http,deploy</pre></div><p>Therefore <code class="literal">$JETTY_BASE=/usr/jetty/wordpress</code>.</p><p>The fifth step is to deploy the web application that provides the proxying of client requests to the FastCGI server, <code class="literal">php-fpm</code>. |
| Typically this is done by deploying a <code class="literal">*.war</code> file in the <code class="literal">$JETTY_BASE/webapps</code> directory. |
| For FastCGI there is no web application that needs developed - all the work has already been done for you by Jetty. |
| As such you only need to deploy a Jetty context XML file that configures the web application directly. |
| Copy and paste the following content as <code class="literal">$JETTY_BASE/webapps/jetty-wordpress.xml</code>:</p><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code><?xml version="1.0" encoding="UTF-8"?> |
| <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> |
| <Configure class="org.eclipse.jetty.servlet.ServletContextHandler"> |
| |
| <New id="root" class="java.lang.String"> |
| <Arg>/var/www/wordpress</Arg> |
| </New> |
| |
| <Set name="contextPath">/</Set> |
| <Set name="resourceBase"><Ref refid="root" /></Set> |
| <Set name="welcomeFiles"> |
| <Array type="string"><Item>index.php</Item></Array> |
| </Set> |
| |
| <Call name="addFilter"> |
| <Arg>org.eclipse.jetty.fcgi.server.proxy.TryFilesFilter</Arg> |
| <Arg>/*</Arg> |
| <Arg> |
| <Call name="of" class="java.util.EnumSet"> |
| <Arg><Get name="REQUEST" class="javax.servlet.DispatcherType" /></Arg> |
| </Call> |
| </Arg> |
| <Call name="setInitParameter"> |
| <Arg>files</Arg> |
| <Arg>$path /index.php?p=$path</Arg> |
| </Call> |
| </Call> |
| |
| <Call name="addServlet"> |
| <Arg> |
| <New class="org.eclipse.jetty.servlet.ServletHolder"> |
| <Arg>default</Arg> |
| <Arg> |
| <Call name="forName" class="java.lang.Class"> |
| <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg> |
| </Call> |
| </Arg> |
| <Call name="setInitParameter"> |
| <Arg>dirAllowed</Arg> |
| <Arg>false</Arg> |
| </Call> |
| </New> |
| </Arg> |
| <Arg>/</Arg> |
| </Call> |
| |
| <Call name="addServlet"> |
| <Arg>org.eclipse.jetty.fcgi.server.proxy.FastCGIProxyServlet</Arg> |
| <Arg>*.php</Arg> |
| <Call name="setInitParameter"> |
| <Arg>proxyTo</Arg> |
| <Arg>http://localhost:9000</Arg> |
| </Call> |
| <Call name="setInitParameter"> |
| <Arg>prefix</Arg> |
| <Arg>/</Arg> |
| </Call> |
| <Call name="setInitParameter"> |
| <Arg>scriptRoot</Arg> |
| <Arg><Ref refid="root" /></Arg> |
| </Call> |
| <Call name="setInitParameter"> |
| <Arg>scriptPattern</Arg> |
| <Arg>(.+?\\.php)</Arg> |
| </Call> |
| </Call> |
| |
| </Configure></code></pre><p>An explanation of the above contents:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">Linne 6 specifies the WordPress installation directory, in this example <code class="literal">/var/www/wordpress</code> (as defined in the first step).</li><li class="listitem">Line 9 it is specified the context path at which WordPress will be served, in this example at the root context path <code class="literal">/</code>.</li><li class="listitem">Line 10 specifies the resource base of the context, also set to the WordPress installation directory. |
| This allows Jetty to serve static resources directly from the WordPress installation directory.</li><li class="listitem">Line 12 specifies the welcome file as <code class="literal">index.php</code>, so that Jetty can perform the proper redirects in case of URIs ending with the <code class="literal">/</code> character.</li><li class="listitem">Line 15 specifies the <code class="literal">TryFilesFilter</code>, a Servlet Filter that has been inspired by the <a class="link" href="http://wiki.nginx.org/HttpCoreModule#try_files" target="_top">try_files</a> functionality offered by Nginx. |
| This filter tries to serve the resource from the file system first, and if the resource is not found it forwards the request as <code class="literal">index.php?p=$path</code>, which will match the proxy servlet defined below. |
| Refer to the <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.4.28-SNAPSHOT/org/eclipse/jetty/fcgi/server/proxy/TryFilesFilter.html" target="_top">TryFilesFilter</a> documentation for further information.</li><li class="listitem">Line 29specifies Jetty’s <code class="literal">DefaultServlet</code> to serve static content such as CSS files, JavaScript files, etc. <code class="literal">DefaultServlet</code> will serve these files by looking in the resource base of the context, defined at line 10 (see above).</li><li class="listitem">Line 47 specifies the <code class="literal">FastCGIProxyServlet</code>, a Servlet that proxies HTTP requests arriving from clients to FastCGI requests to the FastCGI server.</li><li class="listitem">Line 52 specifies the TCP address of the FastCGI server (<code class="literal">php-fpm</code>), where HTTP requests are forwarded as FastCGI requests.</li><li class="listitem">Line 60 specifies once again the WordPress installation directory, so that the <code class="literal">FastCGIProxyServlet</code> can pass this information to the FastCGI server.</li><li class="listitem">Line 64 specifies a regular expression that matches request URIs performed to this servlet, in addition to the standard URL mapping defined by Servlet at line 49. |
| Refer to the <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.4.28-SNAPSHOT/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.html" target="_top">FastCGIProxyServlet</a> documentation for further information.</li></ul></div><p>The last step is to start Jetty (see <a class="xref" href="startup.html" title="Chapter 9. Starting Jetty">Chapter 9, <i>Starting Jetty</i></a>) and navigate to <code class="literal">http://localhost:8080</code> with your browser and enjoy WordPress:</p><div class="screenexample"><pre class="screen">$ cd $JETTY_BASE |
| $ java -jar /opt/jetty/start.jar</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="configuring-fastcgi-http2"></a>Configuring Jetty to Proxy HTTP/2 to FastCGI</h3></div></div></div><p>In order to configure Jetty to listen for HTTP/2 requests from clients that are HTTP/2 enabled and forward them to the FastCGI server as FastCGI requests, you need to enable the <code class="literal">http2</code> module, which in turn will require a TLS connector and consequently a keystore to read the key material required by TLS.</p><p>Enabling the <code class="literal">http2</code> is easy; in additions to the modules you have enabled above, add the <code class="literal">http2</code> module:</p><div class="screenexample"><pre class="screen">$ cd $JETTY_BASE |
| $ java -jar $JETTY_HOME/start.jar --add-to-start=http2</pre></div><p>The command above adds the <code class="literal">http2</code> module (and its dependencies) to the existing modules and uses the default Jetty keystore to provide the key material required by TLS. |
| You will want to use your own keystore with your own private key and certificate for your own domain.</p><p>Remember that by adding the <code class="literal">http2</code> module, you will start two JVMs: one that reads the configuration, and one that has the ALPN boot boot jar in the boot classpath, as explained in <a class="xref" href="http2-configuring.html" title="Configuring HTTP/2">Configuring HTTP/2</a>.</p><p>Since now your site will run over TLS, you need to make sure that the WordPress URL is also configured so. |
| If you have followed the steps of the <a class="link" href="configuring-fastcgi.html" title="Configuring Jetty for FastCGI">previous section</a>, your WordPress site is served at <code class="literal">http://localhost:8080</code>. |
| You will need to change that to be <code class="literal">https://localhost:8443</code> from the WordPress administration web interface, or follow the <a class="link" href="http://codex.wordpress.org/Changing_The_Site_URL" target="_top">WordPress instructions</a> to do so without using the administration web interface.</p><p>The minimal modules required to run WordPress with Jetty on HTTP/2 are therefore: <code class="literal">http2</code>, <code class="literal">http</code>, <code class="literal">fcgi</code> and <code class="literal">deploy</code>. |
| These will setup a clear text connector on port 8080 for HTTP/1.1 and a TLS connector on port 8443 for HTTP/2 and HTTP/1.1.</p><p>At this point, you can start Jetty (see <a class="xref" href="startup.html" title="Chapter 9. Starting Jetty">Chapter 9, <i>Starting Jetty</i></a>), hit <code class="literal">http://localhost:8080</code> with your browser and enjoy WordPress via HTTP/2 using a HTTP/2 enabled browser:</p><div class="screenexample"><pre class="screen">$ cd $JETTY_BASE |
| $ java -jar $JETTY_HOME/start.jar</pre></div><p>If you don’t have a HTTP/2 enabled browser, WordPress will still be available over HTTP/1.1.</p></div></div><script type="text/javascript"> |
| SyntaxHighlighter.all() |
| </script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="fastcgi.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a> </td><td width="20%" align="center"><a accesskey="u" href="fastcgi.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right"> <a accesskey="n" href="advanced-extras.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 17. FastCGI Support </td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></td><td width="40%" align="right" valign="top"> Chapter 18. Provided Servlets, Filters, and Handlers</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout"> |
| See an error or something missing? |
| <span class="callout"><a href="http://github.com/eclipse/jetty.project">Contribute to this documentation at |
| <span class="website"><i class="fa fa-github" aria-hidden="true"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2020-03-10)</i></span></div></p></body></html> |