handling subdirectories location

Francis Daly francis at daoine.org
Mon Jun 8 22:46:35 UTC 2015


On Mon, Jun 08, 2015 at 02:07:54PM -0300, Thiago Farina wrote:

Hi there,

> What I'm trying to do is something like the following:
> 
> http://domainame.com/site1/index.php
> http://domainame.com/site2/index.php
> http://domainame.com/site3/index.php

In nginx, one request is handled in one location.

See http://nginx.org/r/location, for example, for the rules by which
one location is chosen.

In this case, you probably want one

  location ^~ /site1/ {}

block, plus one

  location ^~ /site2/ {}

block; and nested in those, one or more blocks which relate to requests
which should be handled by php.

If you want "every request should be handled by /site1/index.php",
you write one configuration. If you want "every request that ends
in .php should be handled by a matching file", you write a different
configuration. If you want "every request that ends in .php, or that
includes the string '.php/', should be handled by a matching file,
you write yet another configuration.

>From what I've read in these mails, I'm afraid that I do not know what
exactly it is that you want.

For example: does "/foo/index.php/secure/login" refer to exactly that
request; or to any request that starts with "/foo/index.php/;", or to
any request that starts with "/foo/" and does not exactly name a file
on the filesystem; or to something else?


Possibly something like

  root /var/www/html;
  include fastcgi.conf;
  location ^~ /site1/ {
    location ~ \.php($|/) {
      fastcgi_split_path_info (.*.php)(/.*);
      fastcgi_pass unix:php.sock;
    }
  }
  location ^~ /site2/ {
    location ~ \.php($|/) {
      fastcgi_split_path_info (.*.php)(/.*);
      fastcgi_pass unix:php.sock;
    }
  }

will do some of what you want.

Note that trying to configure a "php app" to work in a subdirectory does
require help from the php app. Some insist on being installed in /.

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list