1. 下载discuz!
mkdir /data/www
cd /data/www
wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GBK.zip
unzip Discuz_X3.2_SC_GBK.zip
mv upload/* .
2. 配置第一个虚拟主机
删除httpd.conf中的这行前面的警号
#Include conf/extra/httpd-vhosts.conf
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
加入如下配置:
DocumentRoot "/data/www"
ServerName
修改为Allow from all,否则403报错 /usr/local/apache2/config/httpd.conf
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all #修改为Allow from all
/usr/local/apache2/bin/apachectl -t
/usr/local/apache2/bin/apachectl restart #修改配置文件后记得重启服务
3. 配置mysql,给Discuz!增加一个账户
给mysql root账户设置密码,然后命令行进入mysql,创建新的库,并创建一个新的帐号对该库有所有权限:
/usr/local/mysql/bin/mysql -uroot #登陆mysql
> create database aming; #创建数据库,名字为aming
> grant all on aming.* to 'aming'@'localhost' identified by '654321'; #把aming库授权给aming这个用户,用户密码为123456,授权并创建用户及用户密码
> quit
3.1 如何为mysql设置密码
/usr/local/mysql/bin/mysqladmin -uroot password '123456' #设置密码
/usr/local/mysql/bin/mysql -uroot -p123456 #使用密码登陆
4. 安装Discuz!
先绑定hosts
192.168.11.190 #将虚拟机IP指向该网址
浏览器输入:
根据提示,修改对应目录的权限
cd /data/www
chown -R daemon:daemon data/ uc_server/data/ uc_client/data config #让这几个目录支持apache运行帐号可写
5. 为某个虚拟主机配置用户认证
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
AllowOverride AuthConfig
AuthName "自定义的"
AuthType Basic
AuthUserFile /data/.htpasswd # 这里的/data/.htpasswd你可以随便写一个路径或名字,没有限制
require valid-user
/usr/local/apache2/bin/htpasswd -c /data/.htpasswd aming #创建密码,首次创建需要-c , -m是MD5加密
6. 配置域名跳转
RewriteEngine on
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^/(.*)$ $1 [R=301,L]
如果是多个域名,可以这样设置:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [OR] #[OR]前必须有一个空格
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^/(.*)$ $1 [R=301,L]
7. 配置apache的访问日志
ErrorLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/1.com-error_%Y%m%d.log 86400" #|/usr/local/apache2/bin/rotatelogs -l 是切割工具,固定写法
SetEnvIf Request_URI ".*\.gif$" image-request #image-request 是自定义的
SetEnvIf Request_URI ".*\.jpg$" image-request
SetEnvIf Request_URI ".*\.png$" image-request
SetEnvIf Request_URI ".*\.bmp$" image-request
SetEnvIf Request_URI ".*\.swf$" image-request
SetEnvIf Request_URI ".*\.js$" image-request
SetEnvIf Request_URI ".*\.css$" image-request
CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/1.com-access_%Y%m%d.log 86400" combined env=!image-request #env=!image-request 表示除image-request以外,取反
8. 配置静态文件缓存
ExpiresActive on
ExpiresByType image/gif "access plus 1 days"
ExpiresByType image/jpeg "access plus 24 hours"
ExpiresByType image/png "access plus 24 hours"
ExpiresByType text/css "now plus 2 hour"
ExpiresByType application/x-javascript "now plus 2 hours"
ExpiresByType application/javascript "now plus 2 hours"
ExpiresByType application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"
或者使用mod_headers模块实现
# htm,html,txt类的文件缓存一个小时
header set cache-control "max-age=3600"
# css, js, swf类的文件缓存一个星期
header set cache-control "max-age=604800"
# jpg,gif,jpeg,png,ico,flv,pdf等文件缓存一年
header set cache-control "max-age=29030400"
9. 配置防盗链
SetEnvIfNoCase Referer "^http://" local_ref #local_ref 是自定义的
SetEnvIfNoCase Referer "" local_ref
SetEnvIfNoCase Referer "^$" local_ref
Order Allow,Deny
Allow from env=local_ref #env=local_ref 匹配这个
curl -u aming1:123456 -e "
" -x127.0.0.1:80
/1.txt -I #测试防盗链
10. 访问控制
Order deny,allow
Deny from all
Allow from 127.0.0.1
针对请求的uri去限制
Order deny,allow
Deny from all
Allow from 127.0.0.1
某个某陆下禁止解析php
php_admin_flag engine off
Order deny,allow
Deny from all
11. apache rewrite相关
apache 限制指定user_agent
配置如下
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^.*Firefox/4.0* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*Tomato Bot/1.0* [NC]
RewriteCond %{REQUEST_URI} !^/404*
RewriteRule .* /404.html
请注意,你的404.html千万别再跳转到其他页面了,否则很有可能就会死循环了。
其实rewrite到404.html 并不是很好的办法,而apache的rewrite功能有一项就是forbidden ,那就是 F
配置如下
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^*Firefox/4.0* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^*Tomato Bot/1.0* [NC]
RewriteRule .* - [F]
apache 限制某些目录不能访问通过rewrite实现
配置如下
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^.*Firefox/4.0* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*Tomato Bot/1.0* [NC]
RewriteCond %{REQUEST_URI} !^/404*
RewriteRule .* /404.html
请注意,你的404.html千万别再跳转到其他页面了,否则很有可能就会死循环了。
其实rewrite到404.html 并不是很好的办法,而apache的rewrite功能有一项就是forbidden ,那就是 F
配置如下
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^*Firefox/4.0* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^*Tomato Bot/1.0* [NC]
RewriteRule .* - [F]
apache rewrite 出现死循环
配置如下
RewriteCond %{REQUEST_URI} !^/111
RewriteRule ^(.*) /111/$1 [R,L]
discuz伪静态配置:
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/topic-(.+)\.html$ /portal.php?mod=topic&topic=$1&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/article-([0-9]+)-([0-9]+)\.html$ /portal.php?mod=view&aid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/forum-(\w+)-([0-9]+)\.html$ /forum.php?mod=forumdisplay&fid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/group-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=group&fid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/space-(username|uid)-(.+)\.html$ /home.php?mod=space&$1=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/blog-([0-9]+)-([0-9]+)\.html$ /home.php?mod=space&uid=$1&do=blog&id=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/archiver/(fid|tid)-([0-9]+)\.html$ /archiver/index.php?action=$1&value=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ /plugin.php?id=$1:$2&%1
阅读(666) | 评论(0) | 转发(0) |