I am trying to set up Flarum alongside another php application (Dokuwiki, in my case), with the following routes:
/ -> dokuwiki
/bbs -> flarum
Unfortunately, I have tried many variations, but cannot get it to work. Either I get 500 due to redirection cycle, get 404 error, directs to my root app, or get "Primary script unknown" from PHP.
Here's my (minimum) site config:
server {
listen 80;
root /var/www/dokuwiki;
index index.php index.html index.html;
location /bbs {
alias /var/www/flarum/public;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#Remember to comment the below out when you're installing, and uncomment it when done.
location ~ /(conf/|bin/|inc/|vendor/|install.php) { deny all; }
#Support for X-Accel-Redirect
location ~ ^/data/ { internal ; }
location ~ ^/lib.*\.(js|css|gif|png|ico|jpg|jpeg)$ {
expires 365d;
}
location / {
try_files $uri $uri/ @dokuwiki;
}
location @dokuwiki {
rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
rewrite ^/(.*) /doku.php?id=$1&$args last;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
This gives the following 404 error in logs:
[error] 393975#393975: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.6, server: , request: "GET /bbs/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php8.1-fpm.sock:", host: "library.local"
And this is the config closest to working... others get 500, or doesn't read the correct index.php
at all.