0

I'm struggling a bit with some nginx configuration. Essentially I have one filesystem folder (/remote) that hosts web content at /, but on top of this I want virtual paths /w and /wiki that will host a MediaWiki instance out of a completely different filesystem folder (/local).

To put it another way, I am trying to have URLs processed like this:

  • /anything.php -> Run /remote/anything.php
  • /wiki/anything -> Rewrite to /w/index.php?title=anything
  • /w/index.php -> Run /local/mediawiki/index.php

The reason for this is that I'm putting the MediaWiki code on transient storage (recreated on each boot) but the data files (and the rest of the site) are on permanent storage, so have a different path.

I'm getting tripped up because of the multiple server root paths.

If I do this:

location /w/ {
    alias /local/mediawiki;

    location ~ [^/]\.php(/|$) {
        ...
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;

Then according to the nginx documentation, a request to /w/blah.php should have the /w dropped so that it is served from /local/mediawiki/blah.php. However while this may happen with static files, it does not with FastCGI files because SCRIPT_FILENAME tells PHP to run /local/mediawiki/w/blah.php - it does not chop off the /w part - so PHP FPM returns a 404 as it can't find the .php file.

Instead, I tried using rewrite but this doesn't work either:

location /w/ {
    rewrite ^/w/(.*)$ /mediawiki/$1 last;
}
location /mediawiki/ {
    internal;
    root /local;
    ...

This time the SCRIPT_FILENAME is correctly set to /local/mediawiki/blah.php except the other variables now change, so SCRIPT_NAME and DOCUMENT_URI become /mediawiki/blah.php instead of /w/blah.php, which is not correct as these don't relate to the request URLs.

What am I missing? Is there some way to set SCRIPT_FILENAME to better match the file nginx has identified, without having to use rewrite rules?

Malvineous
  • 1,095
  • 11
  • 28

1 Answers1

0

Can you please post the full NGINX config? I think it should be something like this

location ~ ^/(wiki|w)/ {
    root /local/mediawiki;
}

To tell more I need to understand how you pass scripts to php.

  • 1
    The full config file is rather long. The PHP stuff is just the standard FastCGI FPM code [straight out of the manual](https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/). – Malvineous Jun 17 '18 at 12:43