Nginx XenForo SEO-Friendly URLs

Configure Nginx rewrite rules for XenForo friendly URLs, file permissions, MySQL settings, and FFMPEG integration on Centmin Mod.

Nginx Rewrites for XenForo Friendly URLs

For XenForo to use Friendly URLs via mod_rewrite you will find official Nginx rewrite rules here. You will need to add additional Nginx rewrite rules within your domain's Nginx vhost configuration file /usr/local/nginx/conf/conf.d/newdomain.com.conf. This file is created when you use Centmin Mod's menu option #2 to 'Add Nginx vhost domain'. Below Nginx rewrite rules are provided as-is, without support. If you need further help ask on Nginx forums or XenForo's Server Configuration and Hosting forums.

XenForo Permissions

If you are using Centmin Mod 123.09beta01+ or higher, it has a tools/autoprotect.sh cronjob to auto-protect your non-public web directories which have .htaccess 'deny from all' files. This can falsely block XenForo setups. You need to add .autoprotect-bypass files to XenForo directories. For XenForo 2 you need one bypass for /src directory too:

touch /home/nginx/domains/newdomain.com/public/library/.autoprotect-bypass
touch /home/nginx/domains/newdomain.com/public/internal_data/.autoprotect-bypass
touch /home/nginx/domains/newdomain.com/public/install/data/.autoprotect-bypass
touch /home/nginx/domains/newdomain.com/public/install/templates/.autoprotect-bypass
touch /home/nginx/domains/newdomain.com/public/src/.autoprotect-bypass

Backup your web root file and directory permissions before changing them:

getfacl -R -L --absolute-names /home/nginx/domains/newdomain.com/public > /home/nginx/domains/newdomain.com/backup/backup-permissions-$(date +"%d%m%y-%H%M%S").acl

Set correct file and directory permissions on XenForo installation:

find /home/nginx/domains/newdomain.com/public/ -type f -print0 | xargs -0 chmod 0644
find /home/nginx/domains/newdomain.com/public/ -type d -print0 | xargs -0 chmod 0755
find /home/nginx/domains/newdomain.com/public/internal_data/ -type f -print0 | xargs -0 chmod 0777
find /home/nginx/domains/newdomain.com/public/data/ -type f -print0 | xargs -0 chmod 0777
find /home/nginx/domains/newdomain.com/public/internal_data/ -type d -print0 | xargs -0 chmod 0777
find /home/nginx/domains/newdomain.com/public/data/ -type d -print0 | xargs -0 chmod 0777
chmod 0755 /home/nginx/domains/newdomain.com/public

open_basedir Restrictions

If you run XenForo 1.5 or XenForo Media Gallery Addon, you may encounter open_basedir restriction in effect errors. See FAQ item 26 for how to disable open_basedir globally or per Nginx vhost. The relevant line is in /usr/local/nginx/conf/php.conf:

fastcgi_param PHP_ADMIN_VALUE open_basedir=$document_root/:/usr/local/lib/php/:/tmp/;

Setting Up MySQL Database Settings

XenForo uses InnoDB MySQL Engine tables for best performance. Ensure your /etc/my.cnf has:

innodb=ON
default-storage-engine = InnoDB

For UTF-8 support, add under [mysqld] in /etc/my.cnf:

[mysqld]
 character-set-server=utf8

Then restart MySQL: service mysql restart or shortcut mysqlrestart

XenForo Media Gallery Addon & FFMPEG

If you run XenForo Media Gallery Addon, install the static FFMPEG binary and set the path in admin settings:

cd /home/nginx/domains/newdomain.com

# Download and extract static FFMPEG binary
if [ "$(uname -m)" = 'x86_64' ]; then
  wget -cnv https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
  tar xJvf ffmpeg-release-amd64-static.tar.xz
else
  wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-i686-static.tar.xz
  tar xJvf ffmpeg-release-i686-static.tar.xz
fi

# Rename and set permissions
mv ffmpeg-*-amd64-static staticffmpeg
chown -R nginx:nginx staticffmpeg

FFMPEG binary path: /home/nginx/domains/newdomain.com/staticffmpeg/ffmpeg

Nginx Rewrites for XenForo Friendly URLs

If XenForo is installed in public web root at /home/nginx/domains/newdomain.com/public, add these rewrites to /usr/local/nginx/conf/conf.d/newdomain.com.conf. Replace your existing location / {} context. For XenForo 2.x uncomment the 3 lines for /src/ location:

location / {
    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?$uri&$args;
}

location /install/data/ {
    internal;
}

location /install/templates/ {
    internal;
}

location /internal_data/ {
    internal;
}

location /library/ {
    internal;
}

# XenForo 2 uncomment / remove hash from next 3 lines
#location /src/ {
#    internal;
#}