投稿 评论 顶部

LNMP环境搭建BBS论坛及伪静态

佚名 网络安全

我们在mysql备份 LNMP环境中的数据库迁移为独立的服务器的基础上搭建BBS论坛:?

[root@bqh-117 ~]# mysql -uroot -p123456Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.5.32 MySQL Community Server (GPL)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               || wordpress          |+--------------------+5 rows in set (0.00 sec)mysql> create database bbs;      #创建库Query OK, 1 row affected (0.00 sec)mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || bbs                || mysql              || performance_schema || test               || wordpress          |+--------------------+6 rows in set (0.00 sec)mysql> grant all on bbs.* to bbs@'192.168.0.%' identified by '123456'; #授权Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;   #刷新授权生效Query OK, 0 rows affected (0.00 sec)mysql> select user,host from mysql.user;+-----------+-------------+| user      | host        |+-----------+-------------+| root      | 127.0.0.1   || bbs       | 192.168.0.% || wordpress | 192.168.0.% || root      | ::1         ||           | bqh-117     || root      | bqh-117     ||           | localhost   || root      | localhost   |+-----------+-------------+8 rows in set (0.00 sec)mysql> 

此时我们可以通过118机器用已授权的用户远程登录一下数据库:

[root@bqh-118 ~]# mysql -ubbs -p123456 -h 192.168.0.117  #-h  指定远程IP地址Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.5.32 MySQL Community Server (GPL)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || bbs                || test               |+--------------------+3 rows in set (0.00 sec)

?nginx环境配置:

[root@bqh-118 conf]# vim nginx.confworker_processes  1;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;    keepalive_timeout  65; server {        listen       80;        server_name  www.jywbbs.com;        root  html/bbs;        location / {            index  index.php index.html index.htm; 
    }
location ~ .*\.(php|php5)?$ {
     root html/bbs; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } error_page 500 502 503 504 /50x.html; }}

[root@bqh-118 conf]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful
[root@bqh-118 conf]# /application/nginx/sbin/nginx -s reload

?下面我们下载bbs程序:

[root@bqh-118 bbs]# wget -q http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UTF8.zip[root@bqh-118 bbs]# ll总用量 12196-rw-r--r-- 1 root root 12486773 9月  13 2017 Discuz_X3.2_SC_UTF8.zip[root@bqh-118 bbs]# unzip -o Discuz_X3.2_SC_UTF8.zip  #-o 覆盖当前同名文件或目录,工作中慎用。[root@bqh-118 bbs]# ll总用量 12208-rw-r--r--  1 root root 12486773 9月  13 2017 Discuz_X3.2_SC_UTF8.zipdrwxr-xr-x  2 root root     4096 5月  31 2016 readmedrwxr-xr-x 12 root root     4096 5月  31 2016 uploaddrwxr-xr-x  4 root root     4096 5月  31 2016 utility

授权:

[root@bqh-118 html]# chown -R nginx.nginx config/ data/ uc_*

然后我们做hosts地址解析:

同样在windows系统,配置一下host在“C:\Windows\System32\drivers\etc”下的hosts中配置一下域名解析

此时我们打开浏览器输入:www.jywbbs.com或192.168.0.118

?此时我们可以管控一下权限:下面是删除后,从新授权。

[root@bqh-117 ~]# mysql -uroot -p123456Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 9Server version: 5.5.32 MySQL Community Server (GPL)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> drop user bbs@'192.168.0.%';Query OK, 0 rows affected (0.00 sec)mysql> grant insert,delete,update,select,drop on bbs.* to bbs@'192.168.0.%' identified by '123456';Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

登录论坛后台,发布一篇稿子,上传一个图片,获取图片路径:

[root@bqh-118 bbs]# find ./ -type f -name "*.jpg" -mmin -5   #查看最近5分钟内上传带.jpg的图片路径

用户上传的数据:

将来挂载到NFS上的:

图片路径:data/attachment/forum

头像目录:uc_server/data/avatar

把安装文件删除掉,防止其他用户通过web从新安装bbs。

[root@bqh-118 bbs]# rm -rf install/

配置BBS论坛实现列表、内容页等伪静态:

查看当前的 Rewrite 规则:

Nginx Web Serverrewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;if (!-e $request_filename) {    return 404;}
Apache Web Server(独立主机用户)
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3&%1</IfModule>
Apache Web Server(虚拟主机用户)# 将 RewriteEngine 模式打开RewriteEngine On# 修改以下语句中的 /discuz 为您的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 /RewriteBase /discuz# Rewrite 系统规则请勿修改RewriteCond %{QUERY_STRING} ^(.*)$RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1RewriteCond %{QUERY_STRING} ^(.*)$RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1RewriteCond %{QUERY_STRING} ^(.*)$RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1RewriteCond %{QUERY_STRING} ^(.*)$RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1RewriteCond %{QUERY_STRING} ^(.*)$RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1RewriteCond %{QUERY_STRING} ^(.*)$RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1RewriteCond %{QUERY_STRING} ^(.*)$RewriteRule ^blog-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1RewriteCond %{QUERY_STRING} ^(.*)$RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1RewriteCond %{QUERY_STRING} ^(.*)$RewriteRule ^([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ plugin.php?id=$1:$2&%1IIS Web Server(独立主机用户)[ISAPI_Rewrite]# 3600 = 1 hourCacheClockRate 3600RepeatLimit 32# Protect httpd.ini and httpd.parse.errors files# from accessing through HTTPRewriteRule ^(.*)/topic-(.+)\.html(\?(.*))*$ $1/portal\.php\?mod=topic&topic=$2&$4RewriteRule ^(.*)/article-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/portal\.php\?mod=view&aid=$2&page=$3&$5RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=forumdisplay&fid=$2&page=$3&$5RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&$6RewriteRule ^(.*)/group-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=group&fid=$2&page=$3&$5RewriteRule ^(.*)/space-(username|uid)-(.+)\.html(\?(.*))*$ $1/home\.php\?mod=space&$2=$3&$5RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/home\.php\?mod=space&uid=$2&do=blog&id=$3&$5RewriteRule ^(.*)/(fid|tid)-([0-9]+)\.html(\?(.*))*$ $1/index\.php\?action=$2&value=$3&$5RewriteRule ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html(\?(.*))*$ $1/plugin\.php\?id=$2:$3&$5IIS7 Web Server(独立主机用户)<rewrite> <rules> <rule name="portal_topic"> <match url="^(.*/)*topic-(.+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/portal.php\?mod=topic&amp;topic={R:2}&amp;{R:3}" /> </rule> <rule name="portal_article"> <match url="^(.*/)*article-([0-9]+)-([0-9]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/portal.php\?mod=view&amp;aid={R:2}&amp;page={R:3}&amp;{R:4}" /> </rule> <rule name="forum_forumdisplay"> <match url="^(.*/)*forum-(\w+)-([0-9]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/forum.php\?mod=forumdisplay&amp;fid={R:2}&amp;page={R:3}&amp;{R:4}" /> </rule> <rule name="forum_viewthread"> <match url="^(.*/)*thread-([0-9]+)-([0-9]+)-([0-9]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/forum.php\?mod=viewthread&amp;tid={R:2}&amp;extra=page%3D{R:4}&amp;page={R:3}&amp;{R:5}" /> </rule> <rule name="group_group"> <match url="^(.*/)*group-([0-9]+)-([0-9]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/forum.php\?mod=group&amp;fid={R:2}&amp;page={R:3}&amp;{R:4}" /> </rule> <rule name="home_space"> <match url="^(.*/)*space-(username|uid)-(.+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/home.php\?mod=space&amp;{R:2}={R:3}&amp;{R:4}" /> </rule> <rule name="home_blog"> <match url="^(.*/)*blog-([0-9]+)-([0-9]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/home.php\?mod=space&amp;uid={R:2}&amp;do=blog&amp;id={R:3}&amp;{R:4}" /> </rule> <rule name="forum_archiver"> <match url="^(.*/)*(fid|tid)-([0-9]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/index.php\?action={R:2}&amp;value={R:3}&amp;{R:4}" /> </rule> <rule name="plugin"> <match url="^(.*/)*([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/plugin.php\?id={R:2}:{R:3}&amp;{R:4}" /> </rule> </rules></rewrite>Zeus Web Servermatch URL into $ with ^(.*)/topic-(.+)\.html\?*(.*)$if matched then set URL = $1/portal.php?mod=topic&topic=$2&$3endifmatch URL into $ with ^(.*)/article-([0-9]+)-([0-9]+)\.html\?*(.*)$if matched then set URL = $1/portal.php?mod=view&aid=$2&page=$3&$4endifmatch URL into $ with ^(.*)/forum-(\w+)-([0-9]+)\.html\?*(.*)$if matched then set URL = $1/forum.php?mod=forumdisplay&fid=$2&page=$3&$4endifmatch URL into $ with ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html\?*(.*)$if matched then set URL = $1/forum.php?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&$5endifmatch URL into $ with ^(.*)/group-([0-9]+)-([0-9]+)\.html\?*(.*)$if matched then set URL = $1/forum.php?mod=group&fid=$2&page=$3&$4endifmatch URL into $ with ^(.*)/space-(username|uid)-(.+)\.html\?*(.*)$if matched then set URL = $1/home.php?mod=space&$2=$3&$4endifmatch URL into $ with ^(.*)/blog-([0-9]+)-([0-9]+)\.html\?*(.*)$if matched then set URL = $1/home.php?mod=space&uid=$2&do=blog&id=$3&$4endifmatch URL into $ with ^(.*)/(fid|tid)-([0-9]+)\.html\?*(.*)$if matched then set URL = $1/index.php?action=$2&value=$3&$4endifmatch URL into $ with ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html\?*(.*)$if matched then set URL = $1/plugin.php?id=$2:$3&$4endif

并把Nginx Web Server rewrite插入到nginx.conf

[root@bqh-118 ~]# vim /application/nginx/conf/nginx.confworker_processes  1;   events {                   worker_connections  1024; }          http {         include       mime.types;      default_type  application/octet-stream;     sendfile        on;     keepalive_timeout  65;     server {         listen       80;         server_name  www.jywbbs.com;         root  html/bbs;    location / {             index  index.php index.html index.htm;rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;if (!-e $request_filename) {    return 404; }}        location ~ .*\.(php|php5)?$ {        root html/bbs;           fastcgi_pass 127.0.0.1:9000;       fastcgi_index index.php;       include fastcgi.conf;         }        error_page   500 502 503 504  /50x.html;     }}[root@bqh-118 conf]# vim nginx.conf[root@bqh-118 conf]# /application/nginx/sbin/nginx -tnginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is oknginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful[root@bqh-118 conf]# /application/nginx/sbin/nginx -s reload

此时我们打开内容页网址已成伪静态url:

ok,bbs论坛搭建、url伪静态配置成功!