Hello,
Kirby is working nicely (including accessing panel thanks to /edition slug) with this nginx config :
location / {
# Path to source
alias /var/www/kirby/www/;
# Default indexes and catch-all
index index.php index.html;
try_files $uri $uri/ /index.php?$args =404;
# Prevent useless logs
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny access to hidden files and directories
location ~ ^/(.+/|)\.(?!well-known\/) {
deny all;
}
# Execute and serve PHP files
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php/php8.2-fpm-kirby.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
# Remove index.php from URL needed on some cms
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?q=$1 last;
}
}
# Security headers
add_header X-Frame-Options "DENY" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
# Block bad bots
if ($http_user_agent ~* "(BlackWidow|ChinaClaw|larbin|HTTrack|Wget|WebCopier|Go!Zilla|Zeus|EmailSiphon|EmailWolf|Express WebPictures)") {
return 403;
}
# Disable access to hidden files except .well-known
location ~ /\.(?!well-known) {
deny all;
}
# Restrict access to system and content files
location ~* ^/(site|kirby)/ {
deny all;
}
location ~* ^/content/.*\.(txt|md|mdown)$ {
deny all;
}
# Disable directory listing
autoindex off;
# Disable ETags
etag off;
# MIME and charset
include mime.types;
default_type application/octet-stream;
And that works perfectly. It serves all pages and I can acces Kirby admin panel when I visit kirby.domain.tld/edition (I choose this slug in Kirby config file).
Now, I made this plugin ( GitHub - jonathan-reisdorf/kirby-static-site-generator: Static site generator plugin for Kirby 3/4/5. With this plugin you can create a directory with assets, media and static html files generated from your pages. The result is an even faster site. · GitHub ) build a static version of my website in the /var/www/kirby/static/ directory.
What I would like is for nginx to serve the static website and I want also nginx to server kirby panel when the user visit kirby.domain.tld/edition .
Here is what I wrote (but doesn’t work so far) :
location / {
# Path to source
root /var/www/kirby/static/;
# Default indexes and catch-all
index index.php index.html;
try_files $uri $uri/ /index.php?$args =404;
# Prevent useless logs
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny access to hidden files and directories
location ~ ^/(.+/|)\.(?!well-known\/) {
deny all;
}
# redirect /edition (no slash) to /edition/
location = /edition {
return 301 /edition/;
}
# handle /edition PHP app (top-level location)
location ^~ /edition/ {
alias /var/www/kirby/www/;
index index.php index.html;
try_files $uri $uri/ /edition/index.php?$args =404;
# Remove index.php from URL needed on some cms
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?q=$1 last;
}
}
# PHP processing for files under /edition
location ~ [^/edition]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php/php8.2-fpm-kirby.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
# Security headers
add_header X-Frame-Options "DENY" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
# Block bad bots
if ($http_user_agent ~* "(BlackWidow|ChinaClaw|larbin|HTTrack|Wget|WebCopier|Go!Zilla|Zeus|EmailSiphon|EmailWolf|Express WebPictures)") {
return 403;
}
# Disable access to hidden files except .well-known
location ~ /\.(?!well-known) {
deny all;
}
# Restrict access to system and content files
location ~* ^/(site|kirby)/ {
deny all;
}
location ~* ^/content/.*\.(txt|md|mdown)$ {
deny all;
}
# Disable directory listing
autoindex off;
# Disable ETags
etag off;
# MIME and charset
include mime.types;
default_type application/octet-stream;
It does serve well the static website but when I go to /edition (to reach kirby panel), my web browser download /var/www/kirby/www/index.php file instead of running it.
Any idea how to make nginx work with static and kirby panel?