Subject: Working rewrite rules for nginx.

Posted on: 08/01/16 06:18pm
By: joelbarrios

I'm migrating from Apache to Nginx. So far Geeklog works pretty good in my tests. I'm pleased to share with you the rewrite rules needed to make work the url rewrite of geeklog. Just put them inside location / { ... }.

CONFIG Formatted Code
rewrite ^/article.php/(.*)$ /article.php?story=$1 last;
rewrite ^/staticpages/index.php/(.*)$ /staticpages/index.php?page=$1 last;
rewrite ^/links/portal.php/link/(.*)$ /links/portal.php?what=link&item=$1 last;
rewrite "^/directory.php/all/(\d{1,})/(\d{1,})$" /directory.php?topic=all&year=$1&month=$2 last


If you run Geeklog as nonroot directory, such as location /geeklog { ... }, use these ones:

CONFIG Formatted Code
rewrite ^/geeklog/article.php/(.*)$ /geeklog/article.php?story=$1 last;
rewrite ^/geeklog/staticpages/index.php/(.*)$ /geeklog/staticpages/index.php?page=$1 last;
rewrite ^/geeklog/links/portal.php/link/(.*)$ /geeklog/links/portal.php?what=link&item=$1 last;
rewrite "^/geeklog/directory.php/all/(\d{1,})/(\d{1,})$" /geeklog/directory.php?topic=all&year=$1&month=$2 last;
 


Dirk, please it would be worderful if these get included in Geeklog documentation. Will spare lots of suffering to Nginx users.

Enjoy!

Re: Working rewrite rules for nginx.

Posted on: 29/07/16 10:05pm
By: Dan Stoner

THANK YOU for this.

I tried migrating from apache to nginx a while back and failed. These rules solve the issue I was having where the initial site would load ok but would get 404 for any article when I had search engine friendly urls enabled.

I now have geeklog running with nginx and php-fpm. Cool

Re: Working rewrite rules for nginx.

Posted on: 05/08/16 10:10pm
By: ivy

Hi,

Please see more hiroron's site about nginx.

Session error fix:
https://www.winkey.jp/article.php/20130507134319996

Activate Expires and Deflate
https://www.winkey.jp/article.php/20140522171355469


Re: Working rewrite rules for nginx.

Posted on: 15/09/16 09:41pm
By: Dan Stoner

One more bit I found on this topic.

I noticed lines such as this in my nginx error log:

PLAIN Formatted Code

2016/09/15 21:14:21 [error] 4431#0: *79935 open() "/var/www/path/to/site/blog/directory.php/running/2016/1" failed (20│··
: Not a directory), client: 128.227.144.179, server: thatlinuxbox.com, request: "GET /blog/directory.php/running/2016/1 HTTP/1.1│··
", host: "thatlinuxbox.com", referrer: "http://thatlinuxbox.com/blog/directory.php"
 


Browsing the site, from the Directory page, if one selects a topic other than "All" and then tries to view a particular month, the request will fail.

Changing the hard-coded "all" to instead capture the supplied topic name seems to work.

Change this line:

CONFIG Formatted Code

rewrite "^/directory.php/all/(\d{1,})/(\d{1,})$" /directory.php?topic=all&year=$1&month=$2 last;
 


to this:

CONFIG Formatted Code

rewrite "^/directory.php/(.*)/(\d{1,})/(\d{1,})$" /directory.php?topic=$1&year=$2&month=$3 last;
 


Thanks again joelbarrios for sharing your original set of rules.

Geeklog - Forum
https://www.geeklog.net/forum/viewtopic.php?showtopic=96233