2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="mod_proxy_fcgi.xml.meta">
25 <name>mod_proxy_fcgi</name>
26 <description>FastCGI support module for
27 <module>mod_proxy</module></description>
28 <status>Extension</status>
29 <sourcefile>mod_proxy_fcgi.c</sourcefile>
30 <identifier>proxy_fcgi_module</identifier>
31 <compatibility>Available in version 2.3 and later</compatibility>
34 <p>This module <em>requires</em> the service of <module
35 >mod_proxy</module>. It provides support for the
36 <a href="http://www.fastcgi.com/">FastCGI</a> protocol.</p>
38 <p>Thus, in order to get the ability of handling the <code>FastCGI</code>
39 protocol, <module>mod_proxy</module> and
40 <module>mod_proxy_fcgi</module> have to be present in the server.</p>
42 <p>Unlike <a href="http://httpd.apache.org/mod_fcgid/">mod_fcgid</a>
43 and <a href="http://www.fastcgi.com/">mod_fastcgi</a>,
44 <module>mod_proxy_fcgi</module> has no provision for starting the
45 application process; <program>fcgistarter</program> is provided
46 (on some platforms) for that purpose. Alternatively, external launching
47 or process management may be available in the FastCGI application
50 <note type="warning"><title>Warning</title>
51 <p>Do not enable proxying until you have <a
52 href="mod_proxy.html#access">secured your server</a>. Open proxy
53 servers are dangerous both to your network and to the Internet at
58 <seealso><program>fcgistarter</program></seealso>
59 <seealso><module>mod_proxy</module></seealso>
61 <section id="examples"><title>Examples</title>
62 <p>Remember, in order to make the following examples work, you have to
63 enable <module>mod_proxy</module> and <module>mod_proxy_fcgi</module>.</p>
65 <example><title>Single application instance</title>
66 <highlight language="config">
67 ProxyPass /myapp/ fcgi://localhost:4000/
71 <p> <module>mod_proxy_fcgi</module> disables connection reuse by
72 default, so after a request has been completed the connection will NOT be
73 held open by that httpd child process and won't be reused. If the
74 FastCGI application is able to handle concurrent connections
75 from httpd, you can opt-in to connection reuse as shown in the following
78 <example><title>Single application instance, connection reuse</title>
79 <highlight language="config">
80 ProxyPass /myapp/ fcgi://localhost:4000/ enablereuse=on
84 <p> The following example passes the request URI as a filesystem
85 path for the PHP-FPM daemon to run. The request URL is implicitly added
86 to the 2nd parameter. The hostname and port following fcgi:// are where
87 PHP-FPM is listening. Connection pooling is enabled.</p>
88 <example><title>PHP-FPM</title>
89 <highlight language="config">
90 ProxyPassMatch ^/myapp/.*\.php(/.*)?$ fcgi://localhost:9000/var/www/ enablereuse=on
94 <p> The following example passes the request URI as a filesystem
95 path for the PHP-FPM daemon to run. In this case, PHP-FPM is listening on
96 a unix domain socket (UDS). Requires 2.4.9 or later. With this syntax,
97 the hostname and optional port following fcgi:// are ignored.</p>
98 <example><title>PHP-FPM with UDS</title>
99 <highlight language="config">
100 # UDS does not currently support connection reuse
101 ProxyPassMatch ^/(.*\.php(/.*)?)$ "unix:/var/run/php5-fpm.sock|fcgi://localhost/var/www/"
105 <p>The balanced gateway needs <module>mod_proxy_balancer</module> and
106 at least one load balancer algorithm module, such as
107 <module>mod_lbmethod_byrequests</module>, in addition to the proxy
108 modules listed above. <module>mod_lbmethod_byrequests</module> is the
109 default, and will be used for this example configuration.</p>
111 <example><title>Balanced gateway to multiple application instances</title>
112 <highlight language="config">
113 ProxyPass /myapp/ balancer://myappcluster/
114 <Proxy balancer://myappcluster/>
115 BalancerMember fcgi://localhost:4000
116 BalancerMember fcgi://localhost:4001
121 <p>You can also force a request to be handled as a reverse-proxy
122 request, by creating a suitable Handler pass-through. The example
123 configuration below will pass all requests for PHP scripts to the
124 specified FastCGI server using reverse proxy.
125 This feature is available in Apache HTTP Server 2.4.10 and later. For performance
126 reasons, you will want to define a <a href="../mod_proxy.html#workers">worker</a>
127 representing the same fcgi:// backend. The benefit of this form is that it
128 allows the normal mapping of URI to filename to occur in the server, and the
129 local filesystem result is passed to the backend. When FastCGI is
130 configured this way, the server can calculate the most accurate
133 <example><title>Proxy via Handler</title>
134 <highlight language="config">
135 <FilesMatch \.php$>
136 # Note: The only part that varies is /path/to/app.sock
137 SetHandler "proxy:unix:/path/to/app.sock|fcgi://localhost/"
139 # Define a matching worker.
140 # The part that is matched to the SetHandler is the part that
141 # follows the pipe. If you need to distinguish, "localhost; can
142 # be anything unique.
143 <Proxy fcgi://localhost/ enablereuse=on max=10>
146 <FilesMatch ...>
147 SetHandler "proxy:fcgi://localhost:9000"
150 <FilesMatch ...>
151 SetHandler "proxy:balancer://myappcluster/"
157 <section id="env"><title>Environment Variables</title>
158 <p>In addition to the configuration directives that control the
159 behaviour of <module>mod_proxy</module>, there are a number of
160 <dfn>environment variables</dfn> that control the FCGI protocol
163 <dt>proxy-fcgi-pathinfo</dt>
164 <dd>When configured via <directive module="mod_proxy"
165 >ProxyPass</directive> or <directive module="mod_proxy"
166 >ProxyPassMatch</directive>, <module>mod_proxy_fcgi</module> will not
167 set the <var>PATH_INFO</var> environment variable. This allows
168 the backend FCGI server to correctly determine <var>SCRIPT_NAME</var>
169 and <var>Script-URI</var> and be compliant with RFC 3875 section 3.3.
170 If instead you need <module>mod_proxy_fcgi</module> to generate
171 a "best guess" for <var>PATH_INFO</var>, set this env-var.
172 This is a workaround for a bug in some FCGI implementations. This
173 variable can be set to multiple values to tweak at how the best guess
177 <dd>PATH_INFO is split from the slash following the
178 <em>first</em> "." in the URL.</dd>
180 <dd>PATH_INFO is split from the slash following the
181 <em>last</em> "." in the URL.</dd>
183 <dd>PATH_INFO is calculated by an attempt to map the URL to the
184 local filesystem.</dd>
186 <dd>PATH_INFO is the path component of the URL, unescaped /
188 <dt>any other value</dt>
189 <dd>PATH_INFO is the same as the path component of the URL.
190 Originally, this was the only proxy-fcgi-pathinfo option.</dd>