server {
listen 80;
server_name example.com;
root /var/www/flarum;
index index.php index.html index.htm;
# security config
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
fastcgi_hide_header X-Powered-By;
server_tokens off;
# gizp config
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types application/atom+xml
application/javascript
application/json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/svg+xml
image/x-icon
text/css
#text/html -- text/html is gzipped by default by nginx
text/plain
text/xml;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
# php config
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param HTTP_MOD_REWRITE On;
}
# url rewrite
location / { try_files $uri $uri/ /index.php?$query_string; }
location /api { try_files $uri $uri/ /api.php?$query_string; }
location /admin { try_files $uri $uri/ /admin.php?$query_string; }
# expires config
location ~* \.html$ {
expires -1;
}
location ~* \.(?:ico|css|js|gif|bmp|jpe?g|mp4|pdf|mp3|png|svg|ttf|woff|woff2|otf|eot)$ {
access_log off;
expires 30d;
add_header Pragma public;
add_header Cache-Control "public, mustrevalidate, proxy-revalidate";
}
# deny control
location /flarum {
deny all;
return 404;
}
location ~ /assets/.*\.(php)?$ {
deny all;
}
}
代码压缩包放在有道云了。
一些注意事项:
PHP 5.6+ (mbstring, pdo_mysql, openssl, json, gd, dom, fileinfo)
MySQL 5.5+
安装方式
Flarum beta 版本将以 Composer 的方式进行安装,无法通过上传 PHP 代码的传统方式,故安装过程需要登录 SSH 终端。
附带一个ubuntu下搭建 LNMP环境
安装环境准备
sudo apt-get update && sudo apt-get upgrade # 更新包源及系统依赖
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/nginx # 添加 NGINX 源
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php # 添加 PHP 源
sudo apt-get update # 更新源
sudo apt-get install nginx # 安装 NGINX
sudo apt-get install php7.0-fpm php7.0-mysql php7.0-gd php7.0-dom php7.0-mbstring php7.0-curl php7.0-xml # 安装 PHP 7.0 及所需拓展库
sudo apt-get install mysql-server-5.6 # 安装 MySQL 5.6 并设定 root 用户密码
创建 MySQL 用户及数据库
mysql -u root -p # 登录数据库 root 用户
create user 'username'@'localhost'; # 创建数据库用户,替换 username 为你的用户名
set password for 'username'@'localhost' = password('123456'); # 为用户设置密码
create database flarum; # 创建数据库
grant all privileges on flarum.* to 'username'@'localhost'; # 为用户赋予数据库操作权限
flush privileges; # 刷新配置使权限生效