]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_proxy_fcgi.xml
check: merge warning fixes from feature branch
[apache] / docs / manual / mod / mod_proxy_fcgi.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
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
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
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.
21 -->
22
23 <modulesynopsis metafile="mod_proxy_fcgi.xml.meta">
24
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>
32
33 <summary>
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>
37
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>
41
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
48     framework in use.</p>
49
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
54       large.</p>
55     </note>
56 </summary>
57
58 <seealso><program>fcgistarter</program></seealso>
59 <seealso><module>mod_proxy</module></seealso>
60 <seealso><module>mod_authnz_fcgi</module></seealso>
61
62 <section id="examples"><title>Examples</title>
63     <p>Remember, in order to make the following examples work, you have to
64     enable <module>mod_proxy</module> and <module>mod_proxy_fcgi</module>.</p>
65
66     <example><title>Single application instance</title>
67     <highlight language="config">
68 ProxyPass "/myapp/" "fcgi://localhost:4000/"
69     </highlight>
70     </example>
71
72     <p> <module>mod_proxy_fcgi</module> disables connection reuse by
73     default, so after a request has been completed the connection will NOT be
74     held open by that httpd child process and won't be reused.  If the
75     FastCGI application is able to handle concurrent connections
76     from httpd, you can opt-in to connection reuse as shown in the following
77     example:</p>
78
79     <example><title>Single application instance, connection reuse (2.4.11 and later)</title>
80     <highlight language="config">
81 ProxyPass "/myapp/" "fcgi://localhost:4000/" enablereuse=on
82     </highlight>
83     </example>
84
85     <p> The following example passes the request URI as a filesystem
86     path for the PHP-FPM daemon to run. The request URL is implicitly added
87     to the 2nd parameter. The hostname and port following fcgi:// are where
88     PHP-FPM is listening.  Connection pooling is enabled.</p>
89     <example><title>PHP-FPM</title>
90     <highlight language="config">
91 ProxyPassMatch "^/myapp/.*\.php(/.*)?$" "fcgi://localhost:9000/var/www/" enablereuse=on
92     </highlight>
93     </example>
94
95     <p> The following example passes the request URI as a filesystem
96     path for the PHP-FPM daemon to run. In this case, PHP-FPM is listening on
97     a unix domain socket (UDS).  Requires 2.4.9 or later. With this syntax,
98     the hostname and optional port following fcgi:// are ignored.</p>
99     <example><title>PHP-FPM with UDS</title>
100     <highlight language="config">
101 # UDS does not currently support connection reuse
102 ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php5-fpm.sock|fcgi://localhost/var/www/"
103     </highlight>
104     </example>
105
106     <p>The balanced gateway needs <module>mod_proxy_balancer</module> and
107     at least one load balancer algorithm module, such as
108     <module>mod_lbmethod_byrequests</module>, in addition to the proxy
109     modules listed above.  <module>mod_lbmethod_byrequests</module> is the
110     default, and will be used for this example configuration.</p>
111
112     <example><title>Balanced gateway to multiple application instances</title>
113     <highlight language="config">
114 ProxyPass "/myapp/" "balancer://myappcluster/"
115 &lt;Proxy "balancer://myappcluster/"&gt;
116     BalancerMember "fcgi://localhost:4000"
117     BalancerMember "fcgi://localhost:4001"
118 &lt;/Proxy&gt;
119     </highlight>
120     </example>
121
122       <p>You can also force a request to be handled as a reverse-proxy
123         request, by creating a suitable Handler pass-through. The example
124         configuration below will pass all requests for PHP scripts to the
125         specified FastCGI server using reverse proxy.
126         This feature is available in Apache HTTP Server 2.4.10 and later. For performance
127        reasons, you will want to define a <a href="mod_proxy.html#workers">worker</a>
128        representing the same fcgi:// backend. The benefit of this form is that it
129        allows the normal mapping of URI to filename to occur in the server, and the
130        local filesystem result is passed to the backend.  When FastCGI is
131        configured this way, the server can calculate the most accurate
132        PATH_INFO.
133       </p>
134     <example><title>Proxy via Handler</title>
135       <highlight language="config">
136 &lt;FilesMatch "\.php$"&gt;
137     # Note: The only part that varies is /path/to/app.sock
138     SetHandler  "proxy:unix:/path/to/app.sock|fcgi://localhost/"
139 &lt;/FilesMatch&gt;
140
141 # Define a matching worker.
142 # The part that is matched to the SetHandler is the part that
143 # follows the pipe. If you need to distinguish, "localhost; can
144 # be anything unique.
145 &lt;Proxy fcgi://localhost/ enablereuse=on max=10&gt;
146 &lt;/Proxy&gt;
147
148 &lt;FilesMatch ...&gt;
149     SetHandler  "proxy:fcgi://localhost:9000"
150 &lt;/FilesMatch&gt;
151
152 &lt;FilesMatch ...&gt;
153     SetHandler  "proxy:balancer://myappcluster/"
154 &lt;/FilesMatch&gt;
155       </highlight>
156    </example>
157 </section>
158
159 <section id="env"><title>Environment Variables</title>
160     <p>In addition to the configuration directives that control the
161     behaviour of <module>mod_proxy</module>, there are a number of
162     <dfn>environment variables</dfn> that control the FCGI protocol
163     provider:</p>
164     <dl>
165         <dt>proxy-fcgi-pathinfo</dt>
166         <dd>When configured via <directive module="mod_proxy"
167         >ProxyPass</directive> or  <directive module="mod_proxy"
168         >ProxyPassMatch</directive>, <module>mod_proxy_fcgi</module> will not
169         set the <var>PATH_INFO</var> environment variable. This allows
170         the backend FCGI server to correctly determine <var>SCRIPT_NAME</var>
171         and <var>Script-URI</var> and be compliant with RFC 3875 section 3.3.
172         If instead you need <module>mod_proxy_fcgi</module> to generate
173         a "best guess" for <var>PATH_INFO</var>, set this env-var.
174         This is a workaround for a bug in some FCGI implementations.  This
175         variable can be set to multiple values to tweak at how the best guess
176         is chosen (In 2.4.11 and later only):
177         <dl>
178           <dt>first-dot</dt>
179           <dd>PATH_INFO is split from the slash following the
180               <em>first</em> "." in the URL.</dd>
181           <dt>last-dot</dt>
182           <dd>PATH_INFO is split from the slash following the
183               <em>last</em> "." in the URL.</dd>
184           <dt>full</dt>
185           <dd>PATH_INFO is calculated by an attempt to map the URL to the
186               local filesystem.</dd>
187           <dt>unescape</dt>
188           <dd>PATH_INFO is the path component of the URL, unescaped /
189               decoded.</dd>
190           <dt>any other value</dt>
191           <dd>PATH_INFO is the same as the path component of the URL.
192               Originally, this was the only proxy-fcgi-pathinfo option.</dd>
193          </dl>
194         </dd>
195     </dl>
196 </section>
197
198 <directivesynopsis>
199 <name>ProxyFCGIBackendType</name>
200 <description>Specify the type of backend FastCGI application</description>
201 <syntax>ProxyFCGIBackendType FPM|GENERIC</syntax>
202 <default>ProxyFCGIBackendType FPM</default>
203 <contextlist><context>server config</context>
204 <context>virtual host</context><context>directory</context>
205 <context>.htaccess</context></contextlist>
206 <compatibility>Available in version 2.5 and later</compatibility>
207
208 <usage>
209 <p>This directive allows the type of backend FastCGI application to be
210 specified. Some FastCGI servers, such as PHP-FPM,  use historical quirks of
211 environment variables to identify the type of proxy server being used.  Set
212 this direcive to "GENERIC" if your non PHP-FPM application has trouble
213 interpreting environment variables such as SCRIPT_FILENAME or PATH_TRANSLATED
214 as set by the server.</p>
215
216 <p>One example of values that change based on the setting of this directive is
217 SCRIPT_FILENAME. When using <module>mod_proxy_fcgi</module> historically,
218 SCRIPT_FILENAME was prefixed with the string "proxy:fcgi://". This variable is
219 what some generic FastCGI applications would read as their script input, but
220 PHP-FPM would strip the prefix then remember it was talking to Apache.  In
221 2.4.21 through 2.4.25, this prefix was automatically stripped by the server,
222 breaking the ability of PHP-FPM to detect and interoperate with Apache in some
223 scenarios.</p> 
224 </usage>
225 </directivesynopsis>
226
227 <directivesynopsis>
228 <name>ProxyFCGISetEnvIf</name>
229 <description>Allow variables sent to FastCGI servers to be fixed up</description>
230 <syntax>ProxyFCGISetEnvIf <var>conditional-expression</var>
231     <var>environment-variable-name</var>
232     <var>value-expression</var></syntax>
233 <contextlist><context>server config</context>
234 <context>virtual host</context><context>directory</context>
235 <context>.htaccess</context></contextlist>
236 <compatibility>Available in version 2.5 and later</compatibility>
237
238 <usage>
239 <p>Just before passing a request to the configured FastCGI server, the core of
240 the web server sets a number of environment variables based on details of the
241 current request. FastCGI programs often uses these environment variables
242 as inputs that determine what underlying scripts they will process, or what
243 output they directly produce.</p>
244 <p>Examples of noteworthy environment variables are:</p>
245 <ul>
246   <li>SCRIPT_NAME</li>
247   <li>SCRIPT_FILENAME</li>
248   <li>REQUEST_URI</li>
249   <li>PATH_INFO</li>
250   <li>PATH_TRANSLATED</li>
251 </ul>
252
253 <p>This directive allows the environment variables above, or any others of 
254 interest, to be overridden.  This directive is evaluated after the initial
255 values for these variables are set, so they can be used as input into both
256 the condition expressions and value expressions.</p>
257 <p>Parameter syntax:</p>
258 <dl>
259 <dt>conditional-expression</dt> 
260 <dd>Specifies an expression that controls whether the environmen variable that
261    follows will be modified.  For information on the expression syntax, see 
262    the examples that follow or the full specification at the 
263    <a href="../expr.html">ap_expr</a> documentation.
264    </dd>
265 <dt>environment-variable-name</dt> 
266 <dd> Specifies the CGI environment variable to change,
267    such as PATH_INFO.</dd>
268 <dt>value-expression</dt>
269 <dd>Specifies the replacement value for the preceding environment variable.  Backreferences, such as "$1",
270 can be included from regular expression captures in <var>conditional-expression</var></dd>
271 </dl>
272   
273 <example>
274 # A basic, unconditional override<br/>
275 ProxyFCGISetEnvIf "true" PATH_INFO "/example"<br/>
276 <br/>
277 # Use an environment variable in the value<br/>
278 ProxyFCGISetEnvIf "true" PATH_INFO "%{reqenv:SCRIPT_NAME}"<br/>
279 <br/>
280 # Use captures in the conditions and backreferences in the replacement<br/>
281 ProxyFCGISetEnvIf "reqenv('PATH_TRANSLATED') =~ m#(/.*prefix)(\d+)(.*)#" PATH_TRANSLATED "$1$3"<br/>
282 </example>
283
284 </usage>
285 </directivesynopsis>
286
287 </modulesynopsis>