0

I've just done an install of moodle and it's using urls like this for its theme:

http://moodle.example.com/theme/styles.php/standard/1380191797/all

nginx isn't picking up that that's a call to a PHP file and baulks with a 404.

My current rewriting technique revolves around picking up references to /index.php which may seem antiquated but it has worked on a lot of fiddly things before. Here's my current config.

server {
        listen 80;
        server_name moodle.example.com;
        root   /websites/sbmoodle/moodle;
        index index.php;

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

        location ~ \.php($|/) {
                try_files $uri =404;
                include fastcgi_params;
                fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name$fastcgi_path_info;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
}

Now I look under the cold light of Stack Exchange, at it I feel like the php handler at the end (\.php($|/)) should be catching these. But nginx is still chucking out 404s. Why?

And yes, I have tested /theme/styles.php (without a following path) and it works fine.

Oli
  • 1,791
  • 17
  • 27

1 Answers1

1

RTMFM, Oli. Their wiki has a proper nginx configuration which appears to work. Here's the important stuff:

index index.html index.htm index.php;

location / {
        try_files $uri $uri/ /index.html;
}

location ~ \.php {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_param  PATH_INFO          $fastcgi_path_info;
    fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;

    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  SCRIPT_FILENAME    $document_root$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;

    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_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index  index.php;
}
Oli
  • 1,791
  • 17
  • 27