1、apache监听88端口
(1)Apache 的主配置文件httpd.conf,端口改成88
Listen 88
(2)Apache 的虚拟主机配置文件 httpd-vhosts.conf(../conf/extra/)
(i)NameVirtualHost *:88
(ii)全局替换 :1,%s/:80/:88 《====》 :1,$s/:80/:88
2、apache跑动态网页(php相关)
主配置文件httpd.conf
(1)AddType application/x-httpd-php .php
(2)DirectoryIndex index.html index.htm index.php
3、apache由nginx代理访问
修改discuz.conf,blog.conf,pma.conf ——》nginx的vhosts目录下
(1)
server
{
listen 80;
server_name bbs.abc.com;
.....
root /data/bbs;
....
}
(2) location ~ \.php$ {
proxy_pass http://127.0.0.1:88;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
4、nginx跑静态对象(图片,js,css)
vim discuz.conf
配置图片缓存 7 天, nginx图片防盗链,不记录图片等静态页的日志
location ~* ^.+\.(gif|jpg|png|swf|flv|rar| zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$ {
expires 7d;
valid_referers none blocked server_names *.abc.com *.a.com *.b.com *.baidu.com *.google.com *.google.cn *.soso.com;
if ($invalid_referer) {
return 403;
}
access_log off;
}
5、nginx配置js,css缓存1天,不记录日志
location ~ .*\.(js|css)?$
{
expires 24h; 或者为1d
access_log off;
}
6、nginx配置discuz的伪静态
rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 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 ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
7、nginx记录日志
access_log /home/logs/discuz.log combined_realip;
注意:nginx.conf 在http模块中定义了log_format
8、nginx配置日志切割
vim /usr/local/sbin/logrotate.sh
内容:
#! /bin/bash
d=`date -d "-1 day" +%Y%m%d`
/bin/mv /home/logs/discuz.log /home/logs/discuz_$d.log
/etc/init.d/nginx reload >/dev/null 2>/dev/null
cd /home/logs
gzip discuz_$d.log
9、discuz和wordpress访问后台限制ip白名单
(1)discuz的后台: bbs.abc.com/admin.php
location ~ admin.php {
allow 白名单;
deny all;
proxy_pass http://127.0.0.1:88;
proxy_set_header Host $host;
}
(2)wordpress的后台: ls /data/blog/wp-admin/
location /wp-admin/ {
allow 白名单
deny all;
location ~ \.php$ {
proxy_pass http://127.0.0.1:88;
proxy_set_header Host $host;
}
}
10、phpadmin整个站点需要配置用户认证
(1)vim pma.conf
location / {
auth_basic "Auth";
auth_basic_user_file /usr/local/nginx/conf/htpasswd;
}
(2)/usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/htpasswd ljy
(3)重新加载,并访问
curl -x127.0.0.1:80 pma.abc.com
curl -x127.0.0.1:80 -uljy:123456 pma.abc.com
401:代表需要输入用户名和密码
11和12都在db机器上操作
11、写一个mysql备份的脚本,每天5点执行,需要远程拷贝到web机器上
(1)脚本 scriptname 内容
/usr/local/mysql/bin/mysqldump -uroot db1 > /home/db1.sql
/usr/local/mysql/bin/mysqldump -uroot db2 > /home/db2.sql
rsync /home/*.sql 远程web机器ip/data/mysqlbak/
(2)加入到任务列表
* 5 * * * /bin/bash scriptname
12、mysql服务器开启慢查询日志
my.cnf 的 mysqld 模块中添加
超过1秒就记录慢查询日志:long_query_time = 1
定义日志路径: log_slow_queries = /data/mysql/slow.log
13、把除了百度、google外的其他常见搜索引擎蜘蛛封掉,比如(bingbot/2.0、Sogou web spider/4.0、360Spider、YisouSpider、YandexBot/3.0)(nginx)
if ($http_user_agent ~‘bingbot/2.0|MJ12bot/v1.4.2|Spider/3.0|YoudaoBot|Tomato|Gecko/20100315‘) {
return 403;
}