Struggling with configuration
Alan Chandler
alan at chandlerfamily.org.uk
Thu May 8 19:16:13 UTC 2014
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
More information about the nginx
mailing list