Nginx Vhost & Rewrites for IP.Board
This guide assumes you have already installed Centmin Mod v1.2.3+ and followed the Getting Started Guide.
The below IP.Board 3.x Nginx rules were originally sourced from Kirito's thread and modified for Centmin Mod Nginx installs. For IP.Board 4.1 setups, Centmin Mod Nginx rules are based on Jimmy's forum thread.
Notes
- For IP.Board without SEO URLs, no changes to Nginx vhost are needed for initial install.
- For SEO URLs, add Nginx rewrite rules to /usr/local/nginx/conf/conf.d/newdomain.com.conf (HTTP) or .ssl.conf (HTTPS).
- Centmin Mod automatically installs Nginx, PHP-FPM and MariaDB MySQL meeting all IP.Board system requirements.
Setting Up MySQL Database
Enable InnoDB and UTF-8 support in /etc/my.cnf:
innodb=ON
default-storage-engine = InnoDB
[mysqld]
character-set-server=utf8
Create the database and user:
mysqladmin -u root -p create ipf345
mysql -u root -p
MariaDB [(none)]> CREATE USER 'mysqlusername'@'localhost' IDENTIFIED BY 'mysqluserpassword';
MariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON ipf345.* TO 'mysqlusername'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
Preparing IP.Board 3.x Files
Upload the IP.Board zip file via SCP/SFTP, then via SSH:
cd /home/nginx/domains/newdomain.com/zipfiles
unzip board3_4_5.zip
cd board/upload
\cp -Rf * /home/nginx/domains/newdomain.com/public
cd /home/nginx/domains/newdomain.com/public
cp -a conf_global.dist.php conf_global.php
chmod 0777 conf_global.php
# Set directory permissions
webroot='/home/nginx/domains/newdomain.com/public'
find $webroot/{{uploads,cache,css_files,downloads,hooks,screenshots,blog,public/ipc_blocks,public/style_*}} -type d -exec chmod 0777 {{}} \;
find $webroot/{{uploads,cache,css_files,downloads,hooks,screenshots,blog,public/ipc_blocks,public/style_*}} -type f -exec chmod 0666 {{}} \;
# Rename admin directory for security
mv admin mynewadmin
mkdir admin
chown -R nginx:nginx /home/nginx/domains/newdomain.com/public/*
Create constants.php at web root defining the new admin directory:
<?php
define( 'CP_DIRECTORY', 'mynewadmin' );
?>
Nginx Rewrites for IP.Board 3.x (Web Root)
server {{
server_name newdomain.com www.newdomain.com;
access_log /home/nginx/domains/newdomain.com/log/access.log combined buffer=32k;
error_log /home/nginx/domains/newdomain.com/log/error.log;
root /home/nginx/domains/newdomain.com/public;
location / {{
try_files $uri $uri/ /index.php;
}}
location ~^(/page/).*(\.php)$ {{
try_files $uri $uri/ /index.php;
}}
# IP.Board PHP/CGI Protection
location ~^(/uploads/).*(\.php)$ {{ deny all; }}
location ~^(/hooks/).*(\.php)$ {{ deny all; }}
location ~^(/cache/).*(\.php)$ {{ deny all; }}
location ~^(/screenshots/).*(\.php)$ {{ deny all; }}
location ~^(/downloads/).*(\.php)$ {{ deny all; }}
location ~^(/blog/).*(\.php)$ {{ deny all; }}
location ~^(/public/style_).*(\.php)$ {{ deny all; }}
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
include /usr/local/nginx/conf/vts_server.conf;
}}
Restart Nginx: service nginx restart or shortcut ngxrestart
Nginx Rewrites for IP.Board 4.1.x (Web Root)
server {{
server_name newdomain.com www.newdomain.com;
access_log /home/nginx/domains/newdomain.com/log/access.log combined buffer=32k;
error_log /home/nginx/domains/newdomain.com/log/error.log;
root /home/nginx/domains/newdomain.com/public;
location / {{
try_files $uri $uri/ /index.php;
}}
location ~^(/page/).*(\.php)$ {{
try_files $uri $uri/ /index.php;
}}
# Allow Access to Interface Files
location ~ ^/applications/(blog|calendar|chat|cms|core|downloads|forums|gallery|nexus)/interface/.*\.(?:php\d*|phtml)$ {{
allow all;
include /usr/local/nginx/conf/php.conf;
}}
# Block Access to PHP/PHTML Files
location ~ ^/(uploads|datastore|system|plugins)/.*\.(?:php\d*|phtml)$ {{
allow 127.0.0.1;
deny all;
}}
# Block Access to Application PHP/PHTML Files
location ~ ^/applications/(blog|calendar|chat|cms|core|downloads|forums|gallery|nexus)/.*\.(?:php\d*|phtml)$ {{
allow 127.0.0.1;
deny all;
}}
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
include /usr/local/nginx/conf/vts_server.conf;
}}
Enabling ngx_pagespeed Module (Deprecated)
Deprecated
The ngx_pagespeed module has been deprecated and removed from all Centmin Mod branches. The NGINX_PAGESPEED='y' variable no longer works. This content is retained for historical reference.
To enable ngx_pagespeed, uncomment the include lines in your Nginx vhost:
# ngx_pagespeed & ngx_pagespeed handler
include /usr/local/nginx/conf/pagespeed.conf;
include /usr/local/nginx/conf/pagespeedhandler.conf;
include /usr/local/nginx/conf/pagespeedstatslog.conf;
Then enable via: pscontrol on
Verify with: curl -I http://yourdomain.com/ and look for the X-Page-Speed header.