Struggling with configuration

Hi

I am porting some stuff that I had working under Apache to now run under
Nginx and I have a particular case that I don’t know how to deal with.

I have a physical directory structure like this

dev/
dev/myapp/
dev/myapp/web/

in this directory is an index.php file with the following early in its
processing
require_once($_SERVER[‘DOCUMENT_ROOT’].’/forum/SSI.php’);

dev/test-base/
dev/test-base/forum/

In this directory is an smf forum, and there is an SSI.php file in here

my nginx configuration for this

server {
listen 80;
server_name apps.home;
root /home/alan/dev/test-base/;
error_log /var/log/nginx/app.error.log debug;
rewrite_log on;
location / {
try_files $uri $uri/ =404;
index index.html;
}

 location /forum {
     try_files $uri /forum/index.php;
 }

 location /myapp {
     alias /home/alan/dev/myapp/web;
     try_files $uri /myapp/index.php;
     location ~* ^/myapp/(.+\.php)$ {
            fastcgi_pass unix:/var/run/php5-fpm-alan.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME

$document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

 }
 include php.conf
 include common.conf;

}

where php.conf is

Pass all .php files onto a php-fpm/php-fcgi server.

location ~ .php$ {
try_files $uri =404;

 fastcgi_split_path_info ^(.+\.php)(/.+)$;
 #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

 include fastcgi_params;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_intercept_errors on;

 fastcgi_pass unix:/var/run/php5-fpm-alan.sock;

}

What seems to be happening is that myapp/index.php is being called with
$SERVER[‘DOCUMENT_ROOT’] pointing to the alias location and NOT the
location defined by the root directive. Yet the directive reference for
the alias directive says that the document root doesn’t change.

What is the correct approach for solving this problem - I don’t have a
physical directory structure that maps neatly on to the url space, but I
need for my applications to be able to reference files relative to the
base directory for the site.

*PS I just saw that there is a bug with alias and try_files. So I am
doing it wrong by using them. My main question still remains. What is
the correct approach for solving this type of problem?


Alan Chandler
http://www.chandlerfamily.org.uk

On 08/05/14 20:16, Alan Chandler wrote:

dev/myapp/web/
my nginx configuration for this

}
include php.conf


I eventually found a solution. Whether it is the right one I don’t
know, but I have to redefine document root after I have included the
common fastcgi_params file.

 location = /myapp {
     rewrite ^ /myapp/ permanent;
 }

 location /myapp/ {
     alias /home/alan/dev/myapp/web/;
     index index.php;
 }

 location ~ ^/myapp/(.*\.php)$ {
     alias /home/alan/dev/myapp/web/$1;
     include fastcgi_params;
     fastcgi_param DOCUMENT_ROOT /home/alan/dev/test-base;
     fastcgi_index index.php;
 #    fastcgi_intercept_errors on;
     fastcgi_pass unix:/var/run/php5-fpm-alan.sock;
 }


Alan Chandler
http://www.chandlerfamily.org.uk

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs