Apache 2.4: Configuring mod_proxy_fcgi for remote server

Configure Apache 2.4 fastCGI with mod_proxy_fcgi module for a remote GAS server.

If you are configuring mod_proxy_fcgi to connect to a remote GAS server, the requirement for the modules and the configuration details are similar to those described in Apache 2.4: mod_proxy_fcgi; you just need to configure the Apache configuration file as shown in the examples here.

Add the following lines to the Apache configuration file:
Note: Starting with Apache 2.4.11, you can add the enablereuse=on option in the ProxyPass configuration line, in order to recycle connections to the fastcgi dispatcher.
...
<IfModule mod_proxy_fcgi.c>
  #No PATH_INFO with mod_proxy_fcgi unless this is set
  SetEnvIf Request_URI . proxy-fcgi-pathinfo=1

  ProxyPass /gas/ http://<gas-server-ip>:<gas-server-port>/gas/ enablereuse=on
  Alias /gas /opt/gas/bin/fastcgidispatch 
</IfModule>
... 
  • <gas-server-ip> is the address of the remote server where the GAS is running.
  • <gas-server-port> is the port where fastcgidispatch is listening.
  • /gas/ directory is just a virtual directory, no need to create one
  • The Alias directive specifies where documents are stored in the local file system

Rewrite-rule for authorization headers

If you are using authorization headers, you need to be aware of the following:
  • Authorization headers need to be base64 encoded.
  • A rewrite rule (see Apache 2.4 documentation) can be created and a ProxyPassReverse directive set in order to adjusts or rewrite URLs on the fly before forwarding them on to the client.

    For example, an authorization request will cause a redirect to an authentication server and Apache adjusts this URL to the local URL before forwarding the HTTP redirect response to the client. For more details on Apache directives, see Apache 2.4 documentation.

...
<IfModule mod_proxy_fcgi.c>
  #No PATH_INFO with mod_proxy_fcgi unless this is set
  SetEnvIf Request_URI . proxy-fcgi-pathinfo=1

  # Need to rewrite authorization header
  RewriteEngine on
  RewriteRule .* - [E=HTTP_AUTHORIZATION:% {HTTP:Authorization}] 

  ProxyPass /gas/ http://<gas-server-ip>:<gas-server-port>/gas/ enablereuse=on
  Alias /gas /opt/gas/bin/fastcgidispatch 
  ProxyPassReverse /gas/ http://<gas-server-ip>:<gas-server-port>/gas/ 
</IfModule>
...