Question
Nginx with Kirby CMS at web root and WordPress in a subdirectory
Hey, I’m having some trouble setting up a site that uses Kirby CMS for the main site and WordPress in a subdirectory for a subsite.
I’ve done a lot of trial and error, and while the homepage and WordPress admin panel are working, WordPress inner pages are resulting in the Kirby CMS 404 page. I’ve tried the same configuration in a VM locally that has it working, but I can’t seem to get the subdirectory location block working on DigitalOcean.
I’ve included the server block from the nginx config below.
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.domain.com;
root /home/forge/www.domain.com/public;
# ssl info...
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/www.domain.com/server/*;
##############################
## Kirby configuration
##############################
if (!-e $request_filename){
rewrite ^/panel/(.*) /panel/index.php break;
}
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php last;
break;
}
location /content {
rewrite ^/content/(.*)\.(txt|md|mdown)$ /error redirect;
}
location /site {
rewrite ^/site/(.*) /error redirect;
}
location /kirby {
rewrite ^/kirby/(.*) /error redirect;
}
location ~* \.(ico|css|js|gif|jpeg|jpg|png|woff|ttf|otf|svg|woff2|eot)$ {
expires 1M;
add_header Pragma public;
add_header Cache-Control "public";
}
##############################
## End Kirby CMS configuration
##############################
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# Subsite
location /subdir {
try_files $uri $uri/ /subdir/index.php?$uri&$args;
}
# Kirby panel links
location /panel {
try_files \$uri \$uri/ /panel/index.php?\$uri&\$args;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/www.domain.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
Any suggestions?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×