Sikkepitje.nl

Sikkepitje.nl

this private cloud

PmWiki op NGINX met Clean URLs

20170426

Just another config

Plain simpele configuratie

Let speciaal op het afschermen van datadirectories. .htaccess werkt niet in Apache en moet ik omschrijven voor NGINX.

Nginx web root is ~/www1082/ Wiki in {DOCROOT}/w , URL is w/

Index-wrapper in {DOCROOT}/w/ maakt URL http://sikkepitje.nl:1082/w Index-wrapper in {DOCROOT} maakt URL http://sikkepitje.nl:1082 maar CSS laadt niet. Pubdir onbereikbaar?

Aha, ik heb hulp hier:

Checking NGINX config file syntax

 nginx -t -c /etc/nginx/sites-enabled/default

Basisconfiguratie

Eerst config werkend maken voor basisconfiguratie

In $DOCROOT/w/local/config.php:

 $EnablePathInfo = 0;

/etc/nginx/sites-enabled/default :

# Default server configuration
#
server {
        listen 1082 default_server;
        server_name sikkepitje.nl;
        charset utf-8;
        root /home/paul/www1082;
        index index.php index.html index.htm index.nginx-debian.html;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # config from pmwiki .htaccess files
        location ~ ^/w/(cookbook|docs|local|scripts|wiki.d|wikilib.d) {
                deny all;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}

Werkt! URL voorbeeld http://sikkepitje.nl:1082/w/pmwiki.php?n=Main.WikiSandbox

Clean URLs

Verder met configuratie van clean urls… Zodra ik in config.php verander:

 $EnablePathInfo = 1;

Dan worden de links op de hoofdpagina : http://sikkepitje.nl:1082/w/pmwiki.php/Main/WikiSandbox En nu werken deze links niet meer. Dus nu verder.

Ik verander in pmwiki config.php:

 $ScriptUrl = $UrlScheme.'://'.$_SERVER['HTTP_HOST'].'/w/pmwiki.php';

In

 $ScriptUrl = $UrlScheme.'://'.$_SERVER['HTTP_HOST'].'/w';

Ververs de hoofdpagina, dan veranderen de URLs in http://sikkepitje.nl:1082/w/Main/WikiSandbox

Toevoegen aan NGINX configuratie in server-block zorgt ervoor dat URL rewrite plaatsvindt.

        location /w {
                error_page 404 = @pmwiki;
                log_not_found off;
        }

        location @pmwiki {
                rewrite ^/w/(.*)$ /w/?n=$1 last;
        }

En werkt!

PmWiki in root

Nu het laatste loodje: het verwijderen van de "/w" uit de URL. PmWiki blijft in de "/w" folder staan, maar we bereiken hem via de hogere dir. Gewenste URL is http://sikkepitje.nl:1082:Main/WikiSandbox .

In {DOCROOT}/index.php:

<?php
chdir("w"); include_once("pmwiki.php");

In /etc/nginx/sites-enable/default:

# Default server configuration
#
server {
        listen 1082 default_server;
        server_name sikkepitje.nl;
        charset utf-8;
        root /home/paul/www1082;
        index index.php index.html index.htm index.nginx-debian.html;

        location / {
                error_page 404 = @pmwiki;
                log_not_found off;
        }

        location @pmwiki {
                rewrite ^/(.*)$ /?n=$1 last;
        }

        #location / {
        #       # First attempt to serve request as file, then
        #       # as directory, then fall back to displaying a 404.
        #       try_files $uri $uri/ =404;
        #}

        # config from pmwiki .htaccess files
        location ~ ^/(cookbook|docs|local|scripts|wiki.d|wikilib.d) {
                deny all;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}

Herstart NGINX met:

 $ sudo systemctl restart nginx.service

Werkt! Ik roep nu op: http://sikkepitje.nl:1082 De links op de hoofdpagina zijn: http://sikkepitje.nl:1082/Main/WikiSandbox