tar xf apr-1.6.2.tar.gz
tar xf apr-util-1.6.0.tar.gz
tar -xjf httpd-2.4.29.tar.bz2
mv apr-1.6.2 httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
yum -y install \
gcc \
gcc-c++ \
make \
pcre-devel \
expat-devel \
perl \
zlib-devel \
zlib
cd httpd-2.4.29
./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
make && make install
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
# chkconfig: 35 85 21 //35级别自动运行 第85个启动 第21个关闭
# description: Apache is a World Wide Web server
chkconfig --add httpd
vi /usr/local/httpd/conf/httpd.conf
ServerName
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/
systemctl stop firewalld.service
setenforce 0
service httpd start
netstat -anpt | grep 80
-------- 以下配置网页压缩--到之前的源代码目录----------
cd httpd-2.4.29
./configure --enable-deflate //增加压缩模块
重新安装
make && make install
vi /etc/httpd.conf
搜索mod_deflate.so
LoadModule deflate_module modules/mod_deflate.so
将前面的#号去掉
重启服务
service httpd restart
查看
apachectl -D DUMP_MODULES | grep deflate
修改配置文件
vi /etc/httpd.conf
文件末尾插入下面命令
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript image/png image/jpeg application/x-httpd-php application/x-javascript #文件类型
DeflateCompressionLevel 9 #压缩级别
SetOutputFilter DEFLATE #压缩类型
-----测试页----
切换目录
cd /usr/local/httpd/htdocs/
ll查看 删除所有
cd /usr/local/httpd/htdocs/
vim index.html
修改配置文件 将倒数第四行修改为1.jpg
将1.jpg图上上传到远程连接软件
vi /etc/httpd.conf
插入到最后一行
AddDefaultCharset utf-8
将图片上传到/目录
再从/目录移到/usr/local/httpd/htdocs/
-----------配置网页缓存---------
cd /usr/local/httpd/
./bin/apachectl -D DUMP_MODULES | grep expires
service httpd stop
在文件最后新增
vi /etc/httpd.conf
ExpiresActive On
ExpiresDefault "access plus 60 seconds"
----------------------------------------------------------------------------------------------
配置第二台:VM1网卡 yum仓库 挂载好磁盘
上传3个软件包到/目录下
tar xf apr-1.6.2.tar.gz
tar xf apr-util-1.6.0.tar.gz
tar -xjf httpd-2.4.29.tar.bz2
mv apr-1.6.2 httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
yum -y install \
gcc \
gcc-c++ \
make \
pcre-devel \
expat-devel \
perl \
zlib-devel \
zlib
cd httpd-2.4.29
./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
--------------------------------------------------------------------------
make && make install #
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd #
vi /etc/init.d/httpd #
# chkconfig: 35 85 21 //35级别自动运行 第85个启动 第21个关闭 #
# description: Apache is a World Wide Web server #
chkconfig --add httpd #
vi /usr/local/httpd/conf/httpd.conf #
ServerName #
ln -s /usr/local/httpd/conf/httpd.conf /etc/ #
ln -s /usr/local/httpd/bin/* /usr/local/bin/ #
systemctl stop firewalld.service #
setenforce 0 #
service httpd start #
netstat -anpt | grep 80 #
cd /httpd-2.4.29/
安装下一个服务
./configure --enable-expires
编译安装
make && make install
cd /usr/local/httpd/htdocs/
ll查看
编辑配置文件
vim index.html
插入
./bin/apachectl -D DUMP_MODULES | grep rewrite
vi /etc/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
将第二张图片命名为error.jpg 上传到第一台虚拟机中
------针对目录做防盗链处理------------在htdocs目录属性最后位置新增---
vim /etc/httpd.conf
搜索AllowOverride None
插入
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://192.168.1.100/*
RewriteCond %{HTTP_REFERER} !^http://bc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://bc.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.bc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.bc.com$ [NC]
RewriteRule .*\.(gif|jpg|swf|png)$ http://192.168.1.100/error.jpg [R,NC] //需要重定向到一个盗链主机可以访问的位置,否则看不出效果来。
重启服务
systemctl restart httpd
访问