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.

Re: Working rewrite rules for nginx.

Posted on: 13/05/22 08:04pm
By: joelbarrios

Recently moved my geeklog (+6,000 posts, +10,000 forum posts, +2500 users, 60 MB database, almost 20 years of data) to a new URL at https://blog.alcancelibre.org . New server uses Nginx+PHP-FPM. So, here you have the full Nginx/PHP-FPM configuration needed for Geeklog 2.2.*.
=======

Configuration for Nginx virtual host:

PHP Formatted Code

server {
    listen 80;
    # Let certbot deal with the https support.
   server_name www.yourdomain.net;
    root /home/username/public_html;
    access_log /var/log/nginx/yourdomain-access_log main;
    error_log /var/log/nginx/yourdomain-error_log notice;
    charset UTF-8;
    # The value of client_max_body_size has to be the same as the values
   # of PHP upload_max_filesize and post_max_size
   client_max_body_size 128M;
    client_body_buffer_size 128M;
    server_tokens off;
    # This file has the options for gzip compression.
   # See: https://ubiq.co/tech-blog/how-to-enable-nginx-gzip-compression/
   include /etc/nginx/default.d/gzip.conf;
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-XSS-Protection "1; mode=block" always;
    add_header X-Content-Type-Options "nosniff" always;
    # Make sure your all the external components form third-party CDNS of your
   # layout theme are listed here. Otherwise your website will not display!
   # Enable and test. Disable again if you do not know how to get all the external CDNs.
   # add_header Content-Security-Policy: "default-src 'self' https://code.jquery.com https://cdnjs.cloudflare.com https://analytics.google.com";

    location / {
        index index.html index.htm index.php;
        error_page 404 /404.php;
        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/(.*)/(\d{1,})/(\d{1,})$" /directory.php?topic=$1&year=$2&month=$3 last;
        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }

        location = /robots.txt {
            log_not_found off;
            access_log off;
        }

        location ~/\.(ht|git) {
            deny all;
        }

        location /.well-known {
            default_type "text/plain";
        }

        location ~ ^/install/(.+\.php)$ {
            allow 127.0.0.1;
            # Put your IP address here
           allow 192.168.100.6;
            deny all;
            #allow all;
       }
    }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_intercept_errors on;
                include fastcgi_params;
                fastcgi_param SERVER_NAME $host;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass 127.0.0.1:8500;
                # The values for upload_max_filesize and post_max_size MUST be the
               # same as nginx client_max_body_size
               fastcgi_param PHP_VALUE "upload_max_filesize=128M \n post_max_size=128M";
                fastcgi_index index.php;
                # Installation or upgrades may fail if these ones have lower values
               fastcgi_read_timeout 600;
                proxy_buffers 16 16k;
                proxy_buffer_size 16k;
                proxy_connect_timeout 3600s;
                proxy_read_timeout 3600;
                proxy_send_timeout 3600;
         }
}
 


Configuration for PHP-FPM:

PHP Formatted Code

[geeklog]
user = username
group = username
listen = localhost:8500
pm = dynamic
pm.max_children = 9999
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 5
php_admin_value[upload_tmp_dir] = /home/username/tmp
php_admin_value[session.save_path] = /home/username/tmp
php_admin_flag[log_errors] = on
php_admin_value[error_log] = /home/username/logs/php-fpm-error_log
php_value[error_reporting] = E_ALL|E_NOTICE
php_value[max_execution_time] = 7200
; You will need at least 512M to install or upgrade
php_value[memory_limit] = 1024M
; Set your own time zone
php_value[date.timezone] = America/Mexico_City
php_value[expose_php] = off
; Installation or upgrades may fail if these ones have lower values
php_value[request_terminate_timeout] = 600
php_value[max_input_time] = 360
php_value[max_input_vars] = 4000
 

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