Skip to content

Instantly share code, notes, and snippets.

@bastianallgeier
Last active November 30, 2023 10:14
Show Gist options
  • Star 46 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save bastianallgeier/c2e1f1e519f5f2943ec4 to your computer and use it in GitHub Desktop.
Save bastianallgeier/c2e1f1e519f5f2943ec4 to your computer and use it in GitHub Desktop.
nginx setup
# 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;
}
@wottpal
Copy link

wottpal commented Oct 14, 2016

Hey @JimmyRittenborg, thanks for your improvements on this nginx config. How would all this look if Kirby is installed in a subdirectory of my domain? Do I have to add the dir-name in every rule or is there a simpler way? (Wrapping everything in location ~ /subdir { .. } doesn't seem to work :(

Dennis

@dnspnjrs
Copy link

dnspnjrs commented Jun 2, 2017

Hi all. Ive been searching and searching. Finally ended up here with this answer.

I have a nginx server configured on localhost and kirby running. For the most part it runs fine but ive encounterd a little annoying detail. It doesnt seem to work with a few specific links:

localhost:8080/panel/ - works
localhost:8080/panel - does not work

Any body an idea on why this would be failing?

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

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

Edit:

The redirect in nginx does work in some way. but it directs to localhost/panel instead of localhost:8080/panel.

@setagana
Copy link

setagana commented Jul 6, 2017

@JimmyRittenborg Are you able to share your full .conf file including the above code? I'm new to nginx and struggling to see how this comes together with things like error pages and fastcgi. Many thanks in advance.

@automaticalldramatic
Copy link

@wottpal can you share what you did for a sub-directory configuration. I couldn't get panel to work on nginx running on AWS

@dcschmid
Copy link

dcschmid commented Feb 1, 2020

Is there a nginx config for kirby 3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment