Skip to content Skip to navigation

OJS Virtual Host Proxy Configuration

Posted by: 

Overview

Configuring Open Journal Systems (OJS) to work with Stanford's Virtual Host Proxy (aka, "vanity URL") service requires some configuration tweaks to get all paths working properly. When installing a new instance of OJS (or adding a new journal to an existing installation, with its own virtual host proxy), you'll need to make changes to the following files to get it working:

  • index.php
  • config.inc.php
  • classes/core/Request.inc.php

The instructions below assume that you have a working OJS installation, and want your vanity URL to point to your journal. Let's assume you have OJS installed in the cgi-bin directory of your AFS group called publicknowledge. Let's also say that your journal is called Ephemera, and you want https://ephemera.stanford.edu to point to your journal.

Step 1: Request a Virtual Host Proxy

Go to http://vanityurl.stanford.edu to request a virtual host proxy for your journal from ITS.

Enter the following information on the form:

  • Virtual Host Name: ephemera
  • Website Address: https://www.stanford.edu/group/publicknowledge/cgi-bin/index.php/ephemera/
  • Virtual Host Type: Proxy
  • Additional Configuration: Please configure this proxy to use SSL, i.e., https://ephemera.stanford.edu
Screenshot of virtual host proxy request form

Configuration options for requesting the virtual host proxy.

Step 2: Modify index.php

Add the following lines to index.php, right after the opening <?php tag:

// mrmarco: take care of PHP < 5.24 bug when run under CGI
$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];

The first few lines of your index.php should therefore look like this:

<?php
// mrmarco: take care of PHP < 5.24 bug when run under CGI
$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
 
/**
 * @mainpage OJS API Reference
 * 

Step 3: Modify config.inc.php

Comment out disable_path_info

Find the line that reads:

disable_path_info = On
and comment it out so that it reads:
; disable_path_info = On

Add an index base_url and a base_url for your journal

Add the following lines to the base_url section:

base_url[index] = https://www.stanford.edu/group/publicknowledge/cgi-bin
base_url[ephemera] = https://ephemera.stanford.edu

Step 4: Modify Request.inc.php

In classes/core/Request.inc.php, modify the getServerHost function (starting at line 189) to the following:

	/**
	 * Get the server hostname in the request.
	 * @return string
	 */
	function getServerHost($default = 'localhost') {
		static $serverHost;
		if (!isset($serverHost)) {
			$serverHost = 
            // mrmarco: removed test for HTTP_X_FORWARDED_HOST
            // isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST']
		    // :
                (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST']
				: (isset($_SERVER['HOSTNAME']) ? $_SERVER['HOSTNAME']
				: $default));
			HookRegistry::call('Request::getServerHost', array(&$serverHost));
		}
		return $serverHost;
	}