Location - or how to setup sites in subfolders

Edho Arief edho at myconan.net
Sun Apr 29 20:22:56 UTC 2012


2012/4/30 Daniel L. Miller <dmiller at amfes.com>:
> Note that I tried to add the "if" construct in php.conf based on a previous
> post - and I gotta believe there's a better way to do this.  With or without
> the if construct, the above site works - but only for egroupware.  Revising
> the site file to:
> server {
>    server_name www.amfeslan.local egroupware.amfeslan.local;
>    root /var/www;
>    index index.html;
>
>    client_max_body_size 8M;
>
>    location / {
>       try_files $uri $uri/ /index.php?$args;
>    }
>
>    location ^~ /egroupware {
>       root /opt/egroupware;
>       index index.php;
>       rewrite ^/egroupware/(.*)$ /$1 last;
>       try_files $uri $uri/ /index.php$args;
>    }
>
>    include global/php.conf;
> }
>
> Doesn't work right.  Can some kind soul help me not only fix this - but get
> a better understanding of how to build these generic constructs?  Based on
> experience with other servers, I can't believe folder-based controls in
> nginx can be as difficult as I seem to be making it!

Put "location ~ \.php$ { }" inside each "location ^~ /appname/ { }"
block instead of globally so it looks like this:

location ^~ /egroupware/ {
  # if index.php's path is /opt/egroupware/index.php,
  # use "root /opt" instead
  root /opt/egroupware;
  index index.php;
  # and remove this
  rewrite ^/egroupware/(.*)$ /$1 last;
  # and update this accordingly
  try_files $uri $uri/ /index.php$args;
  location ~ \.php($|/) {
    ...
  }
}

Also remember that some applications may need to know that it's
running in a subdirectory or it will generate incorrect link (eg.
/something.php instead of /app/something.php).



More information about the nginx mailing list