在LAMP环境搭载Discuz!(下)

1.在虚拟主机中实现用户验证

[[email protected] logs]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>

DocumentRoot "/data/www"

ServerName www.123.com

ServerAlias www.aaa.com

#用户认证

<Directory *>

AllowOverride AuthConfig

AuthName "study"

AuthType Basic

AuthUserFile /data/.htpasswd  //存用户名和密码

require valid-user

</Directory>

#ErrorLog "logs/dummy-host.example.com-error_log"  //错误日志

#CustomLog "logs/dummy-host.example.com-access_log" common  //正常日志

</VirtualHost>

/data/.htpasswd文件的生成:

/usr/local/apache2/bin/htpasswd -c -m(md5)/data/.htpasswd  [username]  //第一次使用时要添加-c选项,若第二次还是用则会覆盖第一次的所产生的文件。

New password:

Re-typenew password:

[[email protected] mysql]# cat /data/.htpasswd

aming1:$apr1$60e7Z/11$31yiwDyX0iRSVGAuznpwn.

[[email protected] ~]# apache -t

Syntax OK

[[email protected] ~]# apache restart

注:

增加第二个用户的时候,就不要加-c了,因为-c是创建的意思,如果加上会把这个文件重写。

再次用浏览器进入论坛会出现以下窗口:

输入用户名和密码后就会进入论坛了。

2.配置域名跳转

在用户认证后添加以下内容:

#域名跳转

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www.123.com$

RewriteRule ^/(.*)$ http://www.aaa.com/$1 [R=301,L]

</IfModule>

如果是多个域名,可以这样设置:

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www.123.com [OR]

RewriteCond %{HTTP_HOST} ^www.456.com$

RewriteRule ^/(.*)$ http://www.aaa.com/$1 [R=301,L]

</IfModule>

通过输入curl命令则可以验证域名跳转成功,但是如果未指定用户名则不能跳转

[[email protected] logs]# curl -u aming1:123456 -x127.0.0.1:80 www.123.com -I

HTTP/1.1 301 Moved Permanently

Date: Sat, 02 May 2015 22:08:07 GMT

Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28

Location: http://www.aaa.com/

Cache-Control: max-age=0

Expires: Sat, 02 May 2015 22:08:07 GMT

Content-Type: text/html; charset=iso-8859-1

[[email protected] logs]# curl -u aming1:123456 -x127.0.0.1:80 www.aaa.com -I

HTTP/1.1 301 Moved Permanently

Date: Sat, 02 May 2015 22:08:14 GMT

Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28

X-Powered-By: PHP/5.3.28

location: forum.php

Cache-Control: max-age=0

Expires: Sat, 02 May 2015 22:08:14 GMT

Content-Type: text/html

以下为未输入用户名所得的结果:

[[email protected] mysql]# curl -x127.0.0.1:80 www.aaa.com -I
HTTP/1.1 401 Authorization Required
Date: Sat, 02 May 2015 22:02:56 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
WWW-Authenticate: Basic realm="study"
Content-Type: text/html; charset=iso-8859-1

[[email protected] mysql]# curl -x127.0.0.1:80 www.123.com -I
HTTP/1.1 301 Moved Permanently
Date: Sat, 02 May 2015 22:02:58 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Location: http://www.aaa.com/
Cache-Control: max-age=0
Expires: Sat, 02 May 2015 22:02:58 GMT
Content-Type: text/html; charset=iso-8859-1

注:301与302区别——301暂时,302永久 ,401 Authorization Requied需要认证

配置apache的访问日志

[[email protected] logs]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf

添加如下内容

#配置日志

ErrorLog "/usr/local/apache2/logs/dummy-host.example.com-error_log"

SetEnvIf Request_URI ".*\.gif$" 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/oem.discuz.qq.com-error_%Y%m%d.log 86400" combined env=!image-request

注:路径最好写绝对路径,同时也要写对,在实验时由于自己未写对路径就出现了错误。

若将生成日志的文件路径写错会出现以下错误。

[[email protected] logs]# curl -u aming1:123456 -x127.0.0.1:80 www.123.com -I

curl: (7) couldn‘t connect to host

[[email protected] logs]# curl -u aming1:123456 -x127.0.0.1:80 www.aaa.com -I

curl: (7) couldn‘t connect to host

配置静态文件缓存

[[email protected] logs]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf

添加如下内容

#配置静态文件缓存

<IfModule mod_expires.c>

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/javascript "now plus 2 hours"

ExpiresByType application/x-shockwave-flash "now plus 2 hours"

ExpiresDefault "now plus 0 min"

</IfModule>

注:我们在设置js文件时格式为x-javascript,curl后不能达到我们要的效果,我们将其该为javascript就可以了。

[[email protected] www]# curl -u aming1:123456 -x127.0.0.1:80 www.aaa.com/2.js -I
HTTP/1.1 200 OK
Date: Sat, 02 May 2015 22:43:13 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Last-Modified: Sat, 02 May 2015 22:41:14 GMT
ETag: "23277-0-5152106b3c108"
Accept-Ranges: bytes
Cache-Control: max-age=0
Expires: Sat, 02 May 2015 22:43:13 GMT
Content-Type: application/javascript

[[email protected] www]# curl -u aming1:123456 -x127.0.0.1:80 www.aaa.com/2.js -I
HTTP/1.1 200 OK
Date: Sat, 02 May 2015 22:44:14 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Last-Modified: Sat, 02 May 2015 22:41:14 GMT
ETag: "23277-0-5152106b3c108"
Accept-Ranges: bytes
Cache-Control: max-age=7200
Expires: Sun, 03 May 2015 00:44:14 GMT
Content-Type: application/javascript

这里补充说明一点,最后一行已经告诉了我们文件类型,比如这里是 Content-Type: application/javascript,如果对于 css 文件,则为 Content-Type: text/css ,对于 jpg/jpeg 文件,则为 Content-Type: image/jpeg ,只需要将该类型配置到 ExpiresByType 中就可以对相应文件进行缓存了。

配置防盗链

添加如下内容:

#配置防盗链

SetEnvIfNoCase Referer "^http://www.123.com" local_ref

SetEnvIfNoCase Referer ".*www.aaa.com" local_ref

SetEnvIfNoCase Referer "^$" local_ref

<filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif)">

Order Allow,Deny

Allow from env=local_ref

</filesmatch>

实验结果:

[[email protected] www]# curl -u aming1:123456 -e"www.aaa.com/safsaf" -x127.0.0.1:80 www.aaa.com/1.txt -I

HTTP/1.1 200 OK

Date: Sat, 02 May 2015 22:59:35 GMT

Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28

Last-Modified: Sat, 02 May 2015 15:22:31 GMT

ETag: "2325b-a-5151ae5c57002"

Accept-Ranges: bytes

Content-Length: 10

Cache-Control: max-age=0

Expires: Sat, 02 May 2015 22:59:35 GMT

Content-Type: text/plain

[[email protected] www]# curl -u aming1:123456 -e"http://www.123.com/safsaf" -x127.0.0.1:80 www.aaa.com/1.txt -I

HTTP/1.1 200 OK

Date: Sat, 02 May 2015 23:00:34 GMT

Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28

Last-Modified: Sat, 02 May 2015 15:22:31 GMT

ETag: "2325b-a-5151ae5c57002"

Accept-Ranges: bytes

Content-Length: 10

Cache-Control: max-age=0

Expires: Sat, 02 May 2015 23:00:34 GMT

Content-Type: text/plain

[[email protected] www]# curl -e "www.baidu.com" -u aming1:123456 -x127.0.0.1:80 www.aaa.com/1.txt -I

HTTP/1.1 403 Forbidden

Date: Sat, 02 May 2015 22:57:23 GMT

Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28

Content-Type: text/html; charset=iso-8859-1

[[email protected] www]# curl -e "www.qq.com" -u aming1:123456 -x127.0.0.1:80 www.aaa.com/1.txt -I

HTTP/1.1 403 Forbidden

Date: Sat, 02 May 2015 22:57:44 GMT

Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28

Content-Type: text/html; charset=iso-8859-1

访问控制

<Directory /data/www/>

Order deny,allow

Deny from all

Allow from 127.0.0.1

</Directory>

针对请求的uri去限制

<filesmatch "(.*)admin(.*)">

Order deny,allow

Deny from all

Allow from 127.0.0.1

</filesmatch>

某个某陆下禁止解析php

<Directory /data/www/path>

php_admin_flag engine off

<filesmatch "(.*)php">

Order deny,allow

Deny from all

</filesmatch>

</Directory>

时间: 2024-08-11 07:48:43

在LAMP环境搭载Discuz!(下)的相关文章

在LAMP环境搭载Discuz!(上)

1.下载Discuz! [[email protected] ~]# mkdir /data/www [[email protected] www]#  cd /data/www [[email protected] www]#  wget  http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GBK.zip [[email protected] www]#  unzip Discuz_X3.2_SC_GBK.zip [[email pr

基于LAMP环境搭建Discuz

========================写在前面的话========================= 1.LAMP环境搭建请查看这篇日志:http://blog.163.com/wangke_email/blog/static/150335003201610315142268/ 2.这只是一篇简单的Discuz安装教程,深入内容以后会讲到. 3.Discu-3.2下载路径:http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UT

利用yum 安装 lamp环境搭载 cacti监控和memcached数据库

今天测试了一下yum安装lamp和cacti监/控已经memcached数据库 首先介绍下我的系统环境 centos6.7 x86-64 1安装cacti yum install cacti 安装cacti 会自动安装lamp环境, 2接下来是memcached的安装步骤 yum install -y epel-release  --安装epel扩展源 里面有提供memcached libmemcached包 yum install -y libevent  memcached libmemca

LAMP环境及Discuz论坛系统安装

第一步:下载Apache.MySQL.PHP wget http://mirrors.sohu.com/apache/httpd-2.2.31.tar.gz wget http://mirrors.sohu.com/php/php-5.3.27.tar.gz wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz 第二步:先安装MySQL 解压缩mysql安装包 tar -zxvf

阿里ECS下LAMP环境的搭建、discuz和pressword的安装

这是菜鸟写的.. ECS:阿里云服务免费试用,配置: CPU: 1核 内存: 1024 MB 带宽:1Mbps 系统:CentOS 6.5 64bit 软件版本: mysql  Ver 14.14 Distrib 5.5.45, for linux2.6 (x86_64) using readline 5.1 Apache/2.4.16 (Unix) PHP 5.5.27 (cli) 一.LAMP环境搭建 进入www.mysql.com,依次点击Downloads ->Community (GP

在LAMP环境下搭建Discuz论坛网站

作为一名Linux菜鸟学员,我在搭建好LAMP环境后,闲来无聊,尝试建站,因此选择Discuz论坛站点.在搭建站点时,首先下载Discuz套件,1.wgethttp://download.comsenz.com/DiscuzX/3.1/Discuz_X3.1_TC_UTF8.zip 2.unzip Discuz_X3.1_TC_UTF8.zip将压缩文件解压,解压后得到一个upload文件. 3.cp -r ./upload /var/www/html 4.service httpd start

lamp 环境下搭建 个人博客

lamp环境下 1.下载discuz  包 2.解压后将 upload 拷贝到 /usr/local/appache2/htdocs 下 chmod -R 777 upload/ 3.新建数据库  mysql create database discuz; 4.建用户 create user discuz identified by 'sn123456'; 5.赋权 grant all on discuz.* to discuz; 用discuz用户登录数据库 6.安装discuz http:/

64位CentOS 6.5下搭建LAMP环境详细步骤

1.确认搭建LAMP所需的环境是否已经安装: [[email protected] ~]#rpm -q make gcc gcc-c++ zlib-devel libtool libtool-ltdl libtool-ltdl-devel bisonncurses-devel 备注:安装libpng时需要zlib-devel           安装php时需要libtool.libtool-ltdl.libtool-ltdl-devel           安装mysql时需要bison.nc

ubuntu server 14.04 LTS下搭建LAMP环境之最详细笔记之一U盘安装双系统

前言: 一直在WIN上使用PHP,不喜欢用WAMP,每次都是手动在windows配置环境,偶尔有一次装了小红帽玩了两天,感觉不是很习惯就换了回来,过了没几天见讨论LAMP环境,于是安装了ubuntu的desktop版本.安装好了环境使用了一下感觉也没有多大的意思,因为那一段时间没有怎么使用PHP,就这样又忽略掉了这一次学习的机会,直到上周日朋友最近在学习这方面的知识,说是要将一个老式电脑安装一个linux来玩玩.本文原创博客地址:http://www.cnblogs.com/unofficial