Configuring Drupal to use a proxy server when making external HTTP requests

Diagram of two computers communicating through a central proxy server.

The upcoming release of Drupal 7.17 adds proxy server support to drupal_http_request. This allows drupal to route all external HTTP requests, made with the drupal_http_request function, through a proxy server.


With the addition of proxy server support, core modules such as Aggregator, OpenID and Update and contrib modules such as Browscap, Media and Twitter Block can now function properly inside of a restricted environment, such as a corporate network, when configured to use an appropriate proxy.


The proxy support added to drupal_http_request supports a number of configurable settings. These settings include:

  • proxy_server - The IP address or hostname of the proxy server.
  • proxy_port - The port number used by the proxy server for client connections.
  • proxy_username - A username used for proxy authentication.
  • proxy_password - A password used for proxy authentication.
  • proxy_user_agent - A string which can be used by the proxy server to identify connection requests.
  • proxy_exceptions - An list of IP addresses or hostnames. Exceptions will be accessed directly, not via proxy.


Proxy settings are stored in persistent variables which can be configured using a variety of different methods.

Hard coding the configuration settings in settings.php

This approach required modifying settings.php. Open up settings.php, found in the sites/default folder, and search for a block of text beggining with "External access proxy settings" and followed by a number of lines beginning with $conf which are commented out (prefixed by a # character).

To configure individual proxy settings, uncomment (remove the # character) from the beginning of the line and adjust the value following the = character to match your desired configuration.

This method is best used when the proxy settings should not be able to overriden or in a staged environment when one or more stage (development, staging, production) required unique proxy settings.

Setting the configuration variables manually using the variable_set function

Persistent variables can be set by using the variable_set function. To set each setting, simply call variable_set with the name of the proxy setting followed by the desired value.

This method is best used when the proxy settings need to be modified by a custom module or installation profile.

Using the HTTP proxy module

The easiest way to configure the proxy settings is to use the HTTP proxy module. HTTP proxy exposes the proxy settings on an administration form for simple and fast modification.

This method is best used in an environment where proxy configuration settings must be frequently changed, such as when testing a new proxy server. To avoid the performance penalty of running another module, the HTTP proxy module can be enabled, used to make proxy configuration changes and then disabled. Any changes made by the module will persist.