Anyone get the Patterns plugin working correctly with nginx?

Anyone get the Patterns plugin working correctly with nginx? I’ve logged an issue in it’s Github. We are using it, even with these limitations, it would just be nice to get it working properly.

Did you get this working at all? I’ve just switched to using nginx, which means some pattern pages are no longer appearing. These URLs work:

  • /patterns/
  • /patterns/common/ (a folder of patterns)
  • /patterns/common/
  • /patterns/common/breadcrumb/breadcrumb.scss|png|jpg (basically any non-php file)

But these do not (I get an unstyled File not found. error):

  • /patterns/common/breadcrumb/breadcrumb.html.php
  • /patterns/common/breadcrumb/breadcrumb.config.php

Is there something I need to add to my nginx config to get these types of files to work? These are the relevant lines I have so far:

location ~ \.php$ {
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
}

# Don't hint these as folders
rewrite ^/kirby$ /error last;

# Block all files in the site and kirby folder from being accessed directly
rewrite ^/kirby/(.*)$ /error last;

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

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

# Prevent clients from accessing hidden files (starting with a dot)
location ~ (?:^|/)\. {
  deny all;
}

Whoop! I seem to have fixed the issue I was having! Turns out it’s a case of adjusting your nginx config (uncovered after reading the discussion about a similar issue with the Slim framework) to include try_files $uri $uri/ /index.php$is_args$args;. For example, I changed this…

location ~ \.php$ {
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
}

to this…

location ~ \.php$ {
  try_files $uri $uri/ /index.php$is_args$args;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
}

Not entirely sure why this works… I think perhaps there are some arguments added to the URL internally, that nginx needs to know about.