First I would strongly recommend to not use subfolder, but to prefer using two subdomains instead. It's much easier to setup, easier to maintain and more isolated.
That being said I've been successfully using two location blocks, one for each app. The forum is installed with the "customizing paths" instructions to remove the public folder. The second location block just needs the /forum prefix in the rule and path. The Flarum sensitive file rules also need to be prefixed with the subfolder.
My servers are managed through Laravel Forge, so most of the configuration was pre-generated by Forge. I only added a second location block and added the sensitive files rules. I personally don't use the .nginx.conf file shipped with Flarum because my nginx defaults cover all of those already, but this will vary from setup to setup.
Here's an excerpt from my Forge configuration. I kept the surrounding configuration to give context to the location blocks:
EDIT: my Flarum is simply inside a folder named forum inside of the Wordpress document root if that's not obvious from the config file.
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name wordpress-flarum-demo.http418.ch;
root /home/forge/wordpress-flarum-demo.http418.ch/;
# I removed the SSL configuration from here
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 (DO NOT REMOVE!)
include forge-conf/wordpress-flarum-demo.http418.ch/server/*;
# Wordpress
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# Flarum
location /forum/ {
try_files $uri $uri/ /forum/index.php?$query_string;
}
location ~* ^/forum/(\.git|composer\.(json|lock)|auth\.json|config\.php|flarum|storage|vendor|workbench) {
deny all;
return 404;
}
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/wordpress-flarum-demo.http418.ch-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}