Problems to get Kirby work on nginx

Hi,
I have some problems to get Kirby work on nginx.
I have an really basic config file:

server {
    listen 80;
    server_name documentation;
    root /var/www/documentation;
}

My Problem now is that every subpage is loading as https. But I dont really know why it use https.
On the Kirby .htaccess file I set the RewriteBase on folder /documentation.

Hope someone can help me.
I someone needs more deeper information for problem solving please ask.

Kind regards

Here’s what you need. Kirby does some strange redirects.
Here’s my entire conf file, grab what you need.

server {
    listen 80;
    server_name kirby.dt.dev kirby.dt.dev.192.168.0.9.xip.io;
    root /users/toddsby/sites/kirby;
    charset utf-8;
    access_log off;
    error_log  /usr/local/logs/kirby.dt.dev-error.log error;

    fastcgi_buffers 16 16k; 
    fastcgi_buffer_size 32k;

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

    index index.html index.htm index.php;

    # block content
    location ~ ^/content/(.*).(txt|md|mdown)$ {
        rewrite ^/content/(.*).(txt|md|mdown)$ /error redirect;
    }
     
    # block all files in the site folder from being accessed directly
    location ~ ^/site/(.*)$ {
        rewrite ^/site/(.*)$ /error redirect;
    }
     
    # block all files in the kirby folder
    location ~ ^/kirby/(.*)$ {
        rewrite ^/kirby/(.*)$ /error redirect;
    }
     
    # site links
    location / {
        try_files $uri $uri/ /index.php?$uri&$args;
    }
     
    # panel links
    location /panel {
        try_files $uri $uri/ /panel/index.php?$uri&$args;
    }
     
    # deny access to .htaccess files
    location ~ /\.ht {
        deny all;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_pass unix:/usr/local/php-fpm.sock;
        fastcgi_index index.php;
    }

    location ~ /\.ht {
        deny all;
    }
}

First of all, nginx doesn’t use .htaccess (that’s an Apache file). Secondly, the config you posted appears to be missing a few pieces of information, such as how to process php files.

Speaking of PHP, you’ll need to know if your fastcgi_pass is setup to use ports or sockets. The code toddsby linked is assuming sockets, and i’ll link one for ports.

Assuming your server name is “yoursite.local” rather than “documentation”, consider the following:

listen 80;
server_name yoursite.local;
root /srv/www/kirby;
index index.php index.html;

That section tells nginx which port the server is listening on, the domain name it’s responding to, the location of server files, and the default files to serve if not specified by the web browser.


location ~ ^/content/(.*).(txt|md|mdown)$ {
    rewrite ^/content/(.*).(txt|md|mdown)$ /error redirect;
  }

  location ~ ^/site/(.*)$ {
    rewrite ^/site/(.*)$ /error redirect;
  }

  location / {
    try_files $uri $uri/ /index.php?$uri&$args;
  }

  location /panel {
    try_files $uri $uri/ /panel/index.php?$uri&&$args;
  }

  location ~ /\.ht {
    deny all;
  }

Those are the various rules found in the .htaccess file, but rewritten for nginx.


location ~* \.php$ {
    fastcgi_pass 127.0.0.1:9000;
  }

This tells nginx what to do with PHP files (pass them to fastcgi, which is listening on port 9000).


All of that would go in your server block.

The big question, however, is why your configuration is attempting to serve ssl pages. My guess is that if you were to look in your sites-available directory for nginx, you’ll find multiple server configurations that are overlapping on basic settings like listening ports and server names. Check that directory and see what you have setup.

Hey,

in the current Kirby version is a bug, who is responsible for the https issue.

The bug will be fix in the next Kirby version

Regards Lukas

1 Like