Linux LAMP务器安装
Lamp服务器安装
wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.37.tar.bz2

tar工具解压httpd包
yum -y install bzip2 安装bzip2工具
tar -xjvf httpd-2.4.37.tar.bz2 解压
yum install apr apr-devel apr-util apr-util-devel -y 安装apr相关移植库模块
yum -y install pcre-devel

yum install gcc -y 安装gcc
yum install gcc-c++ -y


安装ARP
wget http://apache.website-solution.net//apr/apr-1.6.5.tar.bz2
yum -y install pcre-devel
预编译Apache,启用rewrite规则,启用动态加载库
./configure --prefix=/usr/local/apache2/ --enable-rewrite --enable-so

make 编译

make install 安装

/usr/local/apache2/bin/apachectl start 启动Apache服务


setenforce 0 关闭防火墙
systemctl stop firewalld.service
http://10.206.35.197 测试接见

Apache虚拟主机企业应用
1- 基于单IP多个socket端口
2- 基于多个IP地址一个端口
3- 基于单IP一个端口差别域名
<VirtualHost *:80> 虚拟主机设置起始
ServerAdmin webmaster@dummy-host.example.com 管理员邮件
DocumentRoot "/usr/local/apache2//docs/dummy-host.example.com" 虚拟主机公布目录
ServerName dummy-host.example.com 虚拟主机完整域名
ServerAlias www.dummy-host.example.com 别名
ErrorLog "logs/dummy-host.example.com-error_log" 错误日志路径及文件名
CustomLog "logs/dummy-host.example.com-access_log" common 接见日志路径及文件名
1-建立www.jf1.com及www.jf2.com公布目录,重启目录,划分建立index
mkdir -p /usr/local/apache2/htdocs/{jf1,jf2}/
/usr/local/apache2/bin/apachectl restart
echo "<h1>www.jf1.com Pages</h1>" >/usr/local/apache2/htdocs/jf1/index.html
echo "<h1>www.jf2.com Pages</h1>" >/usr/local/apache2/htdocs/jf2/index.html
2-在客户机上设置host将www.jf1com/www.jf2.com与10.206.35.197绑定


Apache rewrite规则实战
添加rewrite功效
1- 添加rewrite模块,基于源码安装,指定参数--enable-rewrite
2- 动态添加模块,以DSO模式安娜装,行使模块源码和Apach apxs工具完成rewrite模块的添加
在httpd.conf的全局设置段或者虚拟主机设置段设置如下下令,开起rewrite
vi /usr/local/apache2/conf/httpd.conf
RewriteEngine on
1- Apache rewrite末端标识符,用于rewrite规则末尾
R[=code](force redirect) 强制外部重定向
G(force URL to be gone) 强制URL为gone,返回410HTTP状态码
P(force proxy) 强制使用署理转发
L(last rul) 匹配当前规则为最后一条匹配规则,住手匹配后续规则
N(next round) 重新从第一条规则最先匹配
C(chained with next rule) 与下一条规则关联
T=MIME-type(force MIME type) 强制MIME类型
NC(no case) 不区分大小写
2- Apache rewrite规则常用表达式,用于匹配参数、字符吕及过滤设置
. 匹配任何单字符
[word] 匹配字符串word
[^word] 不匹配字符串word
jfedu|jfteach 可选择字符串jfedu|jfteach
? 匹配0到1个字符

  • 匹配0到多个字符
  • 匹配1到多个字符
    ^ 字符串最先标志
    $ 字符串竣事标志
    \n 转义符标志
    3- Apache rewrite变量,用于匹配HTTP请求信息、浏览器主机名、URL
    HTTP headers:HTTP_USER_AGENT,HTTP_REFERER,HTTP_COOKIE,HTTP_HOST,HTTP_ACCEPT;
    connection&request:REMOTE_ADDR,QUERY_STRING
    server internals:DOCUMENT_ROOT,SERVER_PORT,SERVER_PROTOCOL;
    system stuff:TIME_YEAR,TIME_MON,TIME_DAY.
    HTTP_USER_AGENT 用户使用的署理,例如浏览器
    HTTP_REFERER 见告服务器,从哪个面来接见的
    HTTP_COOKIE 客户端缓存,主要用于存储用户和密码等信息
    HTTP_HOST 匹配服务器ServerName域名
    HTTP_ACCETP 客户端的浏览器支持的MIME类型
    REMODE_ADDR 客户端的IP地址
    QUERY_STRING URL中接见的字符串
    DOCUMENT_ROOT 服务器公布目录
    SERVER_PORT 服务器端口
    SERVER_PROTOCOL 服务器端协议R
    4- Apache rewrite规则,以下设置在httpd.conf或者vhosts.conf
    将jfedu.net跳转至www.jfedu.net
    RewriteEngine on 启用rewrite引擎
    RewriteCond %{HTTP_HOST} ^jfedu.net[NC] 匹配jfedu.net开头的域名,NC忽略大小写
    RewriteRule ^/(.)$http://www.jfedu.net/$1 [L] (.)示意随便字符串,$1示意引用(.)的随便内容
    将www.jf1.com\www.jf2.com\jfedu.net跳转至www.jfedu.net.OR示意或者
    RewriteEngine on
    RewriteCond % {HTTP_HOST} www.jf1.com [NC,OR]
    RewriteCond % {HTTP_HOST} www.jf2.com [NC,OR]
    RewriteCond % {HTTP_HOST} ^jfedu.net [NC]
    RewriteRule ^/(.
    )$ http://www.jfedu.net/$1 [L]
    接见www,jfedu.net首页,跳转到www.jfedu.net/newindex/,R=301 示意永远重新定向
    RewriteEngine on
    RewriteRule ^/$ http://www.jfedu.net/newindex/ [L,R=301]
    接见/netindex/plus/view.php?aid=71跳转至http://www.jfedu.net/linux/
    RewriteEngine on
    RewriteCond % {QUERY_STRING} ^tid=(.+)$ [NC]
    RewriteRule ^/forum.php$ /jfedu/thread -new - %1.html? [R=301,L]
    接见www.jfedu.net首页,内容接见www.jfedu.net/newindex/ 然则浏览器URL地址不改变
    RewriteEngine on
    RewriteCond % {HTTP_HOST} ^www.jfedu.net [NC]
    RewriteRule ^ /s /newindex/ [L]
    接见/forun.php?tid=107258跳转至/jfedu/thread-new-107258.html
    RewriteEngine on
    RewriteCond % {QUERY_STRING} ^tid = (.+$ [NC]
    RewriteRule ^/form.pho$ /jfedu/thread-new-%1.html? [R=301,L]
    接见/xxx/123456跳转至/www?id=123456
    RewriteEngine on
    RewriteRule ^/(.+)$1?id=$2 [L,R=301]
    判断是否使用移动端接见网站,是则跳转到m.jfedu.net
    RewriteEngine on
    RewriteCond % {HTTP_USER_AGEN} ^iPhone [NC,OR]
    RewriteCond % {HTTP_USER_AGEN} ^Android [NC,OR]
    RewriteCond % {HTTP_USERAGEN} ^WAP [NC]
    RewriteRule ^ /$ http://m.jfedu.net/index.html [L,R=301]
    RewriteRule ^/(.*)/$ http://m.jfedu.net/$1 [L,R=301]
    接见/10690jfedu/123跳转至/index.php?tid/10690/iteams=123,[0-9]示意随便一个数字,+示意多个,(.+)示意任何多个字符
    RewriteEngine on
    RewriteRule ^/([0-9]+)/jfedu/(.
    )$ /index.php?tid/$1/itmes=$2 [L,R=301]