1

I'll be honest - I'm new at using Nginx, but it seems simple enough. I just installed a Mediawiki on my server, applied the database, etc, and it's up and running at http://wiki.rebirthgaming.org/index.php?title=Main_Page

I want to use short URLs, though. I've used the redwerks tool to build my nginx config and applied the changes to the LocalSettings.php. The nginx.conf settings work - the site is running right now with those settings. However, when I add these settings to LocalSettings.php, I get 404

The localsettings that I add which 404's are:

$wgArticlePath      = "/$1";
$wgUsePathInfo      = true;
$wgScriptExtension  = ".php";
$wgGenerateThumbnailOnParse = false;

My nginx.conf is as follows:

server {
   listen 80;
   server_name wiki.rebirthgaming.org;

   root /var/www/wiki.rebirthgaming.org;
   index index.php;

    location / {
        try_files $uri $uri/ wiki.rebirthgaming.org;

        # Do this inside of a location so it can be negated
        location ~ \.php$ {
            try_files $uri $uri/ =404; # Don't let php execute non-existent php files
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
        }
    }

    location /images {
        # Separate location for images/ so .php execution won't apply

        location ~ ^/images/thumb/(archive/)?[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ {
            # Thumbnail handler for MediaWiki
            # This location only matches on a thumbnail's url
            # If the file does not exist we use @thumb to run the thumb.php script
            try_files $uri $uri/ @thumb;
        }
    }
    location /images/deleted {
        # Deny access to deleted images folder
        deny    all;
    }

    # Deny access to folders MediaWiki has a .htaccess deny in
    location /cache       { deny all; }
    location /languages   { deny all; }
    location /maintenance { deny all; }
    location /serialized  { deny all; }

    # Just in case, hide .svn and .git too
    location ~ /.(svn|git)(/|$) { deny all; }

    # Hide any .htaccess files
    location ~ /.ht { deny all; }

    # Uncomment the following code if you wish to hide the installer/updater
    ## Deny access to the installer
    #location /mw-config { deny all; }

    # Handling for the article path
    location wiki.rebirthgaming.org {
        include /etc/nginx/fastcgi_params;
        # article path should always be passed to index.php
        fastcgi_param SCRIPT_FILENAME   $document_root/index.php;
        fastcgi_pass  127.0.0.1:9000;
    }

    # Thumbnail 404 handler, only called by try_files when a thumbnail does not exist
    location @thumb {
        # Do a rewrite here so that thumb.php gets the correct arguments
        rewrite ^/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /thumb.php?f=$1&width=$2;
        rewrite ^/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /thumb.php?f=$1&width=$2&archived=1;

        # Run the thumb.php script
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME   $document_root/thumb.php;
        fastcgi_pass  127.0.0.1:9000;
    }
 }  


}

I want my URLs to look like this: wiki.rebirthgaming.org/Main_Page

I've been trying to figure this out all day, trying different settings etc, but it always fails when making the localsettings changes.

Tim Burton
  • 11
  • 2

1 Answers1

0

I think you actually need a rewrite rule inside your location block. For reference, here's an abbreviated version of what I have:

server {

   location / {
        try_files $uri $uri/ @mediawiki;
   }


   location @mediawiki {
         rewrite ^/([^?]*)(?:\?(.*))? /index.php?title=$1&$2 last;
   }
}
server_kitten
  • 386
  • 3
  • 13