Hi all
This is a cross post from the general discussion forum. Apologies if this is not the correct place to post, but I had no replies on the general discussion forum.
Current setup:
Nginx webserver 0.5.19 (http://www.nginx.net)
PHP 5.2.1 (cgi-fcgi)
PostgreSQL 8.2.3
Moodle 1.8.2 Stable (upgrade from 1.6.3 via 1.7.2)
Nginx proxies client requests to PHP running via the FastCGI that is listening
on a local port on the server. The problem I am having is that after our move
from a previous server (that was running Apache 1.3.x) I have had to disable
slasharguments, and fix paths in the database so that links to files on the
data store are accessed correctly (basically, changing "file.php" to
"file.php?file="). So, all data is now accessible. However, the problem lies in
existing data structures that contain relative paths e.g. an html document
referencing a swf file in the same uploaded directory. These are broken and I understand this to be a result of disabling "slasharguments".
I have replicated the same environment on my laptop, making sure that
slasharguments are enabled, as this is the area that needs fixing. I have been
looking at the code in the "file.php", but not understanding PHP very well, I
am struggling to see what is actually happening. When I click on a file that
has been uploaded successfully in a dummy course, I get the error, "404 Not
Found", served up by Nginx. The actual request path is:
http://moodle/moodle5/file.php/2/nginx.jpg
I wrote a PHP script to display what fastcgi parameters are
effectively being passed from Nginx via fastcgi to the PHP interpreter and
accessed the corresponding URL.
The current FastCGI parameters, defined in the Nginx virtual host config, are
as follows:
{
fastcgi_pass 127.0.0.1:1026;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/Users/username/Sites/Documents/moodle$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param SERVER_ADDR $server_addr;
}
Currently the output of the php script is as follows:
Server Name: moodle
Server Address: 127.0.0.1
Protocol: HTTP/1.1
Request Method: GET
------------------
Script Name: /Users/username/Sites/Documents/moodle/moodle5/clientip2.php
Query:
Path Translated: /moodle5/clientip2.php
Path Info: /moodle5/clientip2.php
Request URI: /moodle5/clientip2.php
What I am trying to ascertain here is where the problem is arising: is it with FCGI or with Nginx. Then I can begin to have a better chance at solving the issue.
Could anyone explain to me how "file.php" works, as I am very fuzzy with PHP? I recall reading a whole bunch of posts on these forums stating that IIS was originally having issues with slasharguments, and that in Apache 2, the directive AcceptPathInfo must be enabled either in the httpd.conf or in a .htaccess. This directive does not exist in Nginx, but I do see that the "PATH_INFO" is echoed in the above script, so I am a little confused. I have also toggled "cgi.fix_pathinfo" on and off, and when it is given the value of "1", "PATH_TRANSLATED" and "PATH_INFO" are no longer echoed out.
Thanks for reading, and any help would greatly be appreciated.
Mike
Relative Links/PATH_INFO/slasharguments problem
Number of replies: 8Re: Relative Links/PATH_INFO/slasharguments problem
Hi Mike,
I am struggling with the same problem. Have you been able to figure out why some parameters aren't being passed to PHP/FCGI from NginX?
I am struggling with the same problem. Have you been able to figure out why some parameters aren't being passed to PHP/FCGI from NginX?
Re: Relative Links/PATH_INFO/slasharguments problem
Hi Andrew
I'm close to fixing this. I've got the relative paths fixed (with slasharguments enabled of course), but right now, logins are broken as a result. I'm not far off, so when I have this fixed, I'll post a config. It's just some small tweaks in RegEx stuff I think.
Mike
I'm close to fixing this. I've got the relative paths fixed (with slasharguments enabled of course), but right now, logins are broken as a result. I'm not far off, so when I have this fixed, I'll post a config. It's just some small tweaks in RegEx stuff I think.
Mike
Re: Relative Links/PATH_INFO/slasharguments problem
I am running Moodle under FastCGI/nginx using the following config:
/etc/nginx/moodle_fastcgi.conf:
fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param REDIRECT_STATUS 200;/etc/nginx/sites-enabled/moodle.vhost:
server { listen 80; server_name pluripotent.reed.edu; access_log /var/log/nginx/moodle.access_log; error_log /var/log/nginx/moodle.error_log; set $webroot '/home/jason/Projects/moodle'; root $webroot; location / { index index.php; } location ~ .php { include /etc/nginx/moodle_fastcgi.conf; fastcgi_param SCRIPT_FILENAME $webroot$fastcgi_script_name; fastcgi_pass 127.0.0.1:8000; fastcgi_index index.php; } }I originally had a separate location { } block for each script that uses "slasharguments" but the above seems to handle all of them just fine so far (profile photos show up, file downloads work, TeX gets rendered, etc).
Re: Relative Links/PATH_INFO/slasharguments problem
Hi Jason
Thanks for the reply. Odd that you are able to get it working with your config (odd to me at least). What version of Nginx are you using?
I had to add a location as follows:
location ~ /file.php/ {
set $script $uri;
set $path_info "";
if ($uri ~ "^(.+\.php)(/.+)")
{
set $script $1;
set $path_info $2;
}
fastcgi_pass 127.0.0.1:1026;
#fastcgi_pass unix:/tmp/fastcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /Users/moodleuser/Sites/testlearn.rave.ac.uk$script;
fastcgi_param PATH_INFO $path_info;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param PATH_TRANSLATED $fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param SERVER_ADDR $server_addr;
}
It is still under test and slasharguments are enabled.
Do all your relative paths work ok? SCORM packages are alright?
Mike
Thanks for the reply. Odd that you are able to get it working with your config (odd to me at least). What version of Nginx are you using?
I had to add a location as follows:
location ~ /file.php/ {
set $script $uri;
set $path_info "";
if ($uri ~ "^(.+\.php)(/.+)")
{
set $script $1;
set $path_info $2;
}
fastcgi_pass 127.0.0.1:1026;
#fastcgi_pass unix:/tmp/fastcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /Users/moodleuser/Sites/testlearn.rave.ac.uk$script;
fastcgi_param PATH_INFO $path_info;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param PATH_TRANSLATED $fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param SERVER_ADDR $server_addr;
}
It is still under test and slasharguments are enabled.
Do all your relative paths work ok? SCORM packages are alright?
Mike
This forum post has been removed
The content of this forum post has been removed and can no longer be accessed.
Re: Relative Links/PATH_INFO/slasharguments problem
For the interested I was unable to get my nginx/php fast-cgi setup to support slash arguments using the above advice (I honestly suspect that it is something with the way that my version of php-cgi parses arguments). So in order to get slash arguments to work I used nginx to do a URL rewrite and convert requests using slash arguments into requests using the ?file= method. Our initial testing indicates that this rewrite works well and allows us to continue to have slash arguments enabled in Moodle.
(Credit for the method goes to John and his post on how to run Moodle on Solaris http://blogs.whardy.com/john/2008/01/02/moodle-on-solaris/)
Software Versions:
Redhat Enterprise Server 5.4
nginx 0.6.39-1.el5 (from EPEL)
php 5.1.6
Moodle 1.9.6+ (build 20091111)
FastCGI Parameters:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
nginx.conf location:
location ~ \.php(.*)$ {
include fastcgi_params;
fastcgi_index index.php;
if (!-e $request_filename) {
rewrite ^(.*\.php)(/)(.*)$ $1?file=$3 last;
}
fastcgi_param SCRIPT_FILENAME /var/moodle_www/html$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_read_timeout 250s;
}
(Credit for the method goes to John and his post on how to run Moodle on Solaris http://blogs.whardy.com/john/2008/01/02/moodle-on-solaris/)
Software Versions:
Redhat Enterprise Server 5.4
nginx 0.6.39-1.el5 (from EPEL)
php 5.1.6
Moodle 1.9.6+ (build 20091111)
FastCGI Parameters:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
nginx.conf location:
location ~ \.php(.*)$ {
include fastcgi_params;
fastcgi_index index.php;
if (!-e $request_filename) {
rewrite ^(.*\.php)(/)(.*)$ $1?file=$3 last;
}
fastcgi_param SCRIPT_FILENAME /var/moodle_www/html$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_read_timeout 250s;
}
Re: Relative Links/PATH_INFO/slasharguments problem
Oops, file.php requires a slash in front of file paths. If you use the rewrite I posted above you will get the error "No valid arguments supplied, path does not start with slash!" when a user tries to open a resource within a Moodle class.
So instead of:
rewrite ^(.*\.php)(/)(.*)$ $1?file=$3 last;
use:
rewrite ^(.*\.php)(/)(.*)$ $1?file=/$3 last;
So instead of:
rewrite ^(.*\.php)(/)(.*)$ $1?file=$3 last;
use:
rewrite ^(.*\.php)(/)(.*)$ $1?file=/$3 last;
Re: Relative Links/PATH_INFO/slasharguments problem
Hi Jeff Harwell
Thank You for this post.