I found out if you actually read the docs, then it’s a lot easier to get working. None of the posts on the web about using Kohana under nginx were particularly helpful (due to the kohana site being located under a subdirectory), and as I took a while to get working I thought I’d post this as my findings in case it helps anyone else.
The Notepad++ Plugin Admin System lives under
/npp/pm/admin, which maps to a separate path
the physical filesystem. Requests to
/npp/pm/pluginadmin are all denied. The admin system uses the Kohana Framework,
which has an
app/ and a
www/ directory. The
www/ directory contains the main
index.php file, which is the start point for
every URL, and the
app/ directory contains all the controllers, models and views for the site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
Line 9 starts the main location for URLs starting with (~ is not a regular expression, but a /starts with/ marker)
One thing I’m still not terribly happy with is that should really be
^~ /npp/pm/admin/ - i.e. with the trailing slash.
Line 11 deals with exactly this case, that user requested exactly
/npp/pm/admin without the trailing slash, and sends a redirect
back to the user. This is the only thing that worked for me, Kohana seems to have a problem if the REQUEST_URI is not in it’s root,
even if if it it’s root without the slash. Huh.
Line 13 does the main internal redirection, to
/npp/pm/pluginadmin/www/. nginx will then re-evaluate which
location entry to use
after performing the rewrite. If I’d have added a
break; on the end, it would have ended the cycle of
rewrite - location selection - rewrite.
last on the end would mean that further rewrite rules in this location should not be performed, but the cycle should start again. nginx has an
automatic protection of 10 cycles to stop infinite loops. Adding
rewrite_log on; and setting the
error_log level to
notice writes the rewritten URIs to the error log, and can
be (and was) very useful for debugging.
Inside the new location block, line 20 states that this location is internal, and can only be used from internally rewritten requests.
try_files checks the file existance in order. Theorically, this should mean the
if() block isn’t necessary. However, it doesn’t seem to work without the
The last option is effectively a rewrite to the kohana
index.php script, without doing a further
try_files command is recommended for speed, and should be
used whenever possible.
The last embedded location just sends all .php files to the FastCGI server (I’m using spawn-fcgi).
If anyone has any ideas about getting rid of the first rewrite, or any other improvements, shout.