Forum

hiawatha behind ssl proxy (e.g. itself). PHP examples (wordpress, drupal, joomla...)

Mina
23 March 2015, 13:51
Hiawatha version: latest
Operating System: linux

Heya. So I will try and populate this with more CMS / e-shops and so on which are PHP based. Make sure your hiawatha rev proxy sends a X-Forward-For header and is used as a ssl temrination point (at least in these examples):

Wordpress 4.1.1:

In wp-config.php, add between DEBUG and require_once settings :
define('WP_DEBUG', false); 
...
/* Start insertion
Some rev-proxy magic boo boo sauce.
One should insist on encryption during logins in this day and age. */
define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);

// Check if behind a forwarder
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$list = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = $list[0]; // might be useful for your application
// Finally, add correct scheme state as forwarder/client
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
}
...
/* That's all, stop editing! Happy blogging. */

Drupal 7.35:

Install entirely in http, try https, you loose 'formatting'
in sites/default/settings.php:

change the rev proxy settings to true , add your array of rev proxy ip's:
[…]
$conf['reverse_proxy'] = TRUE;

/**
* Specify every reverse proxy IP address in your environment.
* This setting is required if $conf['reverse_proxy'] is TRUE.
*/
$conf['reverse_proxy_addresses'] = array('1.2.3.4');

/**
* Set this value if your proxy server sends the client IP in a header
* other than X-Forwarded-For.
*/
# $conf['reverse_proxy_header'] = 'HTTP_X_CLUSTER_CLIENT_IP';

[…], then also add the following to get https to work:

/* It seems as https is still an issue unfortunately, so try: */
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' &&
!empty($conf['reverse_proxy']) &&
in_array($_SERVER['REMOTE_ADDR'], $conf['reverse_proxy_addresses'])
) {
$_SERVER['HTTPS'] = 'on';
// if one has any port issues
//$_SERVER['SERVER_PORT'] = 443;
}

Joomla:

install, then in libraries/joomla/uri/uri.php (it could be somewhere else, I guess, but this is where I added it):
find

                                // Determine if the request was over SSL (HTTPS).
if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off'))
{
$https = 's://';
}

and PREPEND (insert BEFORE) this:
//might be useful
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$list = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = $list[0];
}
// let's flag ssl when frontend sets it
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS']='on';


Hope this helps.

Mina
mina
23 March 2015, 15:58
hihi.. thanks for editing I am sooo not pedantic about such things, I must admit. However, I have as long as have been alive, never been good with formatting on the internet!
mina
24 March 2015, 05:18
Note: Banshee was the only one of the CMS I have tried so far, which *does* work with https out of the box behind a rev-proxy. Hugo is our man! =D
Hugo Leisink
24 March 2015, 09:40
You're welcome. Please, spread the word about Hiawatha and Banshee.
This topic has been closed.