Dear forum-members,

I would like to configure drupal to use a proxy-server when making external http-requests. I found this after googling a while for drupal 7.x:
---------------------------
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.
---------------------------

However: after making the needed changes in the settings.php and restarting httpd drupal still didn't use the proxy-server. These are the relevant lines I changed in the /var/www/html/sites/default/settings.php:

$conf['proxy_server'] = 'http://proxy.company.nl';
$conf['proxy_port'] = 8080;
$conf['proxy_username'] = '';
$conf['proxy_password'] = '';
$conf['proxy_user_agent'] = 'NULL';
$conf['proxy_exceptions'] = array('127.0.0.1', 'localhost');

Am I doing something wrong here?

Hope to hear from anyone!

Regards,

Giel

Comments

john_b’s picture

I would test the proxy connection outside Drupal, maybe using curl. There are some ideas here http://stackoverflow.com/questions/9445489/linux-curl-command-with-proxy

If you still cannot connect, you know it is not a Drupal problem!

If you can connect, this might be useful https://www.drupal.org/project/http_proxy

Digit Professionals specialising in Drupal, WordPress & CiviCRM support for publishers in non-profit and related sectors

giel.smits@rivm.nl’s picture

Hello John,
Curl and wget do work fine, so it seems to be a drupal/php problem....
Regards,
Giel

john_b’s picture

you are sending 'NULL' as a string, rather than sending NULL. Sending a non-compliant user agent may be an issue for your proxy.

Digit Professionals specialising in Drupal, WordPress & CiviCRM support for publishers in non-profit and related sectors

giel.smits@rivm.nl’s picture

Sorry, after commenting that line it still doesn't work:

$conf['proxy_server'] = 'proxy.domain.com';
$conf['proxy_port'] = 8080;
# $conf['proxy_username'] = '';
# $conf['proxy_password'] = '';
# $conf['proxy_user_agent'] = 'NULL';
$conf['proxy_exceptions'] = array('127.0.0.1', 'localhost');

john_b’s picture

Don't you need to send user name and password?

Why not just send
$conf['proxy_user_agent'] = NULL;
instead of
$conf['proxy_user_agent'] = 'NULL';
(if your proxy requires you to send a NULL user agent in the headers: best check!)

If that does not work, see some issues others have had https://api.drupal.org/comment/11994#comment-11994

Digit Professionals specialising in Drupal, WordPress & CiviCRM support for publishers in non-profit and related sectors

giel.smits@rivm.nl’s picture

Hello John,
Thanks for your suggestions. I got it to work when I use the proxy-ip-address though:

$conf['proxy_server'] = '131.224.251.70';
$conf['proxy_port'] = 8080;
# $conf['proxy_username'] = '';
# $conf['proxy_password'] = '';
# $conf['proxy_user_agent'] = 'NULL';
$conf['proxy_exceptions'] = array('127.0.0.1', 'localhost');

Strange, because dns-resolution works fine........

Anyone any suggestions why I can't use the dns-name in the settings.php?

Regards,

Giel

dibiler’s picture

could it be because you didn't add the http:// to the proxy_server url in the first place?

dgtlmoon’s picture

Stepping through drupal_http_request I can see that your "proxy_server" should NOT have the protocol prepended (no http:// etc)

Also note that the proxy must support HTTP/1.0 (in Drupal 7)

dgtlmoon’s picture

if you're accessing HTTPS sites (such as media_youtube) etc, you should use the chr module!

hemangi.gokhale’s picture

Thanks @dgtlmoon, it worked like a charm!

myself.csingh’s picture

Thank you @dgtlmoon, it started working for me.

anil_89’s picture

Hi All,

If you are in proxy network than just need to mentioned below mentioned two setting in you settings.php file in drupal 8

$settings['http_client_config']['proxy']['http'] = 'xx.xx.xx.xx:portnumber';
$settings['http_client_config']['proxy']['https'] = 'xx.xx.xx.xx:portnumber';