Time for a howto OJS with nginx


I am struggeling getting ojs to work with nginx. I’d like the URLs, I had in apache to remain after the migration to nginx.

So I need

  • restful urls
  • default journal home page on “GET /

Now I am struggling with PATH_INFO. If I say disable_path_info = On in config.inc.php the restful urls seem to be gone. I get always redirected to index.php?journal=sr. If I switch disable_path_info = Off I get redirected to base_url[sr] and remain in a redirect loop. Whereas the old apache installation is redirecting me to /sr and then the rewrite rules do the rest.

Does anyone know how to get the PATH_INFO stuff work with ojs and nginx.

I would really like to make it work and then post a little howto here.

You’ll want disable_path_info to remain Off for restful urls. As noted in the option comments, the disable_path_info option really should only be used in broken server setups.

Is FastCGI enabled on your server? I don’t have personal experience with nginx, but I do note that the nginx site warns of many incorrect guides out there with nginx’s interaction with FastCGI:

FastCGI is enabled. Actually the same server is serving a several wordpress sites as virtual hosts without problems.

According to the link you posted I set up a test.php to control the $_SERVER environment which looks like this:

<?php var_export($_SERVER)?>

Now I have two OJS sites (both 2.4.8) with (besides base_url and database name) identical config.inc.php:

  • scienca-revuo.info, the working one. It’s an apache behind a proxying nginx .
  • testo.scienca-revuo.info, the not yet working plain nginx setup.

Now I do an identical http-request on test.php to check the $_SERVER environment.

joh@yksi <0> $ curl scienca-revuo.info/test.php/sr               
array (
  'HTTP_HOST' => 'scienca-revuo.info',
  'HTTP_X_REAL_IP' => '2a01:1e8:e170:fafa:bcab:7b90:b266:96e8',
  'HTTP_X_FORWARDED_FOR' => '2a01:1e8:e170:fafa:bcab:7b90:b266:96e8',
  'HTTP_CONNECTION' => 'close',
  'HTTP_USER_AGENT' => 'curl/7.43.0',
  'HTTP_ACCEPT' => '*/*',
  'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
  'SERVER_SIGNATURE' => '<address>Apache/2.4.10 (Debian) Server at scienca-revuo.info Port 80</address>
  'SERVER_SOFTWARE' => 'Apache/2.4.10 (Debian)',
  'SERVER_NAME' => 'scienca-revuo.info',
  'SERVER_ADDR' => '',
  'SERVER_PORT' => '80',
  'REMOTE_ADDR' => '',
  'DOCUMENT_ROOT' => '/srv/www/ojs/site',
  'REQUEST_SCHEME' => 'http',
  'CONTEXT_DOCUMENT_ROOT' => '/srv/www/ojs/site',
  'SERVER_ADMIN' => 'webmaster@scienca-revuo.info',
  'SCRIPT_FILENAME' => '/srv/www/ojs/site/test.php',
  'REMOTE_PORT' => '53496',
  'QUERY_STRING' => '',
  'REQUEST_URI' => '/test.php/sr',
  'SCRIPT_NAME' => '/test.php',
  'PATH_INFO' => '/sr',
  'PATH_TRANSLATED' => 'redirect:/index.php/sr/sr',
  'PHP_SELF' => '/test.php/sr',
  'REQUEST_TIME_FLOAT' => 1457374457.487,
  'REQUEST_TIME' => 1457374457,

and now the nginx one:

joh@yksi <0> $ curl testo.scienca-revuo.info/test.php/sr 
array (
  'USER' => 'www-data',
  'HOME' => '/var/www',
  'PATH_INFO' => '/sr',
  'SCRIPT_FILENAME' => '/srv/www/ojs/testo/test.php',
  'QUERY_STRING' => '',
  'CONTENT_TYPE' => '',
  'SCRIPT_NAME' => '/test.php',
  'REQUEST_URI' => '/test.php/sr',
  'DOCUMENT_URI' => '/test.php',
  'DOCUMENT_ROOT' => '/srv/www/ojs/testo',
  'SERVER_SOFTWARE' => 'nginx/1.6.2',
  'REMOTE_ADDR' => '2a01:1e8:e170:fafa:bcab:7b90:b266:96e8',
  'REMOTE_PORT' => '34500',
  'SERVER_ADDR' => '2001:4d88:2000:29::affe',
  'SERVER_PORT' => '80',
  'SERVER_NAME' => 'testo.scienca-revuo.info',
  'REDIRECT_STATUS' => '200',
  'HTTP_HOST' => 'testo.scienca-revuo.info',
  'HTTP_USER_AGENT' => 'curl/7.43.0',
  'HTTP_ACCEPT' => '*/*',
  'PHP_SELF' => '/test.php/sr',
  'REQUEST_TIME_FLOAT' => 1457374543.162689,
  'REQUEST_TIME' => 1457374543,

As you see, they are different, but what is the difference that decides whether it works or not.


If the request is making it to OJS 2.x, the application will primarily be concerned with SCRIPT_NAME and PATH_INFO. See:

Are you sure the HTTPS side of this server is configured correctly? One thing I notice is that a request which should be fulfilled by OJS is immediately redirecting to HTTPS, and then looping there.