练习

9 篇文章 0 订阅

Apache的虚拟主机

1.手册
在安装的过程中,如果要查看apache的手册,可以先dnf install httpd-manual -y进行安装
在这里插入图片描述
2.设置不同站点下不同的文件对应,其虚拟主机让一个apache能够发布多个站点的测试页。

  • 建立一系列的站点测试页
mkdir -p /var/www/westos.com/{news,wenku}
  • 当访问new.westos.com时,设置访问到/var/www/westos.com/news/index.html
  • 当访问wenku.westos.com时,设置访问到/var/www/westos.com/wenku/index.html
echo"wenku'spage">/var/www/westos.com/wenku/index.html
echo"news'spage">/var/www/westos.com/news/index.html
echo"default'spage">/var/www/html/index.html
  • cd /etc/httpd/conf.d进入apache的子配置目录中
    虚拟主机的默认虚拟主机就做好了(没有指定过名称的就是默认)
vim/etc/httpd/Vhost.conf
< VirtualHost _default_:80>
DocumentRoot  "/var/www/html"
CustomLog logs/default.log  combined
</VirtualHost>
  conbined表示混合型日志,即为再default.log这个日志里囊括了4中类型,包括:它的access访问,deny拒绝,warning警告和error报错。他的四种日志都会记录在这一个文件
 < VirtualHost  _default_:80>注意要有空格

<VirtualHost*:80>
ServerName   wenku.westos.com
DocumentRoot  "/var/www/westos.com/wenku"
Custom Loglogs/wenku.log  combined
</VirtualHost>

<VirtualHost*:80>
ServerNamenews.westos.com
DocumentRoot "/var/www/westos.com/news"
CustomLog  logs/news.log  combined
</VirtualHost>

测试:在浏览器所在主机中
vim /etc/hosts
192.168.0.11www.westos.comwenku.westos.ocmnews.westos.com
firefoxhttp://www.westos.com
firefoxhttp://wenku.westos.com
firefoxhttp://news.westos.com
注意:再/etc/hosts里面设置域名,不忍浏览器会自动跳转到不知名的地方

Apache的语言支持

1.html 默认支持
2.php

  • dnf install php -y
    在这里插入图片描述
  • vim /var/www/html/index.php编写/var/www/html/index.php文件
    phpinfo()函数可以显示出php的所有相关信息,是排查配置php时是否出错或遗漏配置模块的主要方法之一。
<?php
		phpinfo();
?>

在这里插入图片描述

  • systemctl restart httpd
    在这里插入图片描述

  • 此时apache就可以识别php的模块了
    在这里插入图片描述
    3.perl
    perl语言是一个动态语言,是一个脚本型的语言。主要时让我们的系统支持cgi(comman gateway i)通用网关接口。
    这个网关接口的作用是:第三方程序可以通过这个接口,把数据传给apache,apache就可以通过传递进来的数据进行发布。

  • mkdir /var/www/html/cgidir

  • vim /var/www/html/cgidir/index.cgi
    动态的,注意此处是反向单引号

#!/usr/bin/perl
print  "Content-type:  text/html\n\n";
print `date`;
  • 给cgi文件执行权限,因为它是可执行脚本
    在这里插入图片描述

  • 此时执行会显示当前的时间,并且是动态的
    在这里插入图片描述
    此时我们进行访问的话就会发现代码是裸露出来的
    在这里插入图片描述

  • vim /etc/httpd/conf.d/vhost.conf
    在这里插入图片描述
    根据手册内容,可进行如下编写,来解决代码裸露的问题
    在这里插入图片描述

firefox http://172.25.254.23/cgidir/index.cgi
在这里插入图片描述

Apache的加密访问

http://是用明文传输的,为了保护我们的信息,我们要设置加密传输
【1】直接使用https:172.25.25.423访问,会显示如下界面
在这里插入图片描述
【2】生成证书

  • 生成私钥
openssl  genrsa -out  /etc/pki/tls/private/www.lyq.com.key  2048  

在这里插入图片描述
2048可以通过man openssl genrsa查询
在这里插入图片描述

  • 生成证书签名文件
openssl  req  -new  -key   /etc/pki/tls/private/www.lyq.com.key  \  -out  /etc/pki/tls/certs/www.lyq.com.csr

在这里插入图片描述
【3】生成证书请求

openssl  x509-  req-  days365  -in  \
/etc/pki/tls/certs/www.lyq.com.csr\-signkey/etc/pki/tls/private/www.lyq.com.key\-out/etc/pki/tls/certs/www.lyq.com.crt
注意:
  x509证书格式
  -req请求
  -in加载签证名称

在这里插入图片描述

查看证书是否存在
在这里插入图片描述

有些不需要加密的

  • 建立目录
[root@haha conf.d]# mkdir -p /www/lyq.com/{wenku,news,login}
[root@haha conf.d]# echo "wenku's page" > /www/lyq.com//wenku/index.html
[root@haha conf.d]# echo "news's page" > /www/lyq.com//news/index.html
[root@haha conf.d]# echo "login's page" > /www/lyq.com//login/index.html

  • 更改后刷新目录
[root@haha conf.d]# semanage fcontext -a -t httpd_sys_content_t '/www(/.*)?'
[root@haha conf.d]# semanage fcontext -a -t httpd_sys_content_t '/www(/.*)?'
[root@haha conf.d]# cd
[root@haha ~]# restorecon -RvvF /www/

在这里插入图片描述
/www.westos.com.crtSSLCertificateKeyFile/etc/pki/tls/private/www.westos.com.keysystemctlrestarthttpd^(/.*)$##客户地址栏中输入的地址%{HTTP_HOST}##客户主机$1##RewriteRule后面跟的第一串字符的值

10.Squid+Apache

【1】squid正向代理
搭建了apache的主机设置其不能上网

  • haha:192.168.0.23
    搭建了apache的主机,但设置其不能上网
    在这里插入图片描述
  • xixi:172.25.254.33
    192.168.1.10
  • 真机:172.25.254.17

实验环境:
单网卡主机设定ip不能上网双网卡主机设定ip1可以连接单网卡主机,设定ip2可以上网

实验效果让单网卡主机不能上网但浏览器可以访问互联网页操作:

  • 在双网卡主机中yum install squid -y
    在这里插入图片描述
    viim/etc/squid/squid.conf
 56  http_access    allow    all   默认下是拒绝所有人访问
 59 http_port 3128   端口是3128
 62 cache_dir  ufs  /var/spool/squid 100 16  256  会在/var下建立个spool,在spool下建立一个squid目录  16个一级目录和256个二级目录,并且缓存大小不能超过100M,超过的话会把之前的缓存内容覆盖掉
  • systemctl restart squid

此时可进行查看,看目录是否建立成功:每个目录里有256个二级目录

  • firewall-cmd--permanent--add-port=3128/tcp + firewall-cmd--reload
    在这里插入图片描述
  • 在单网卡主机中选择

NetWorkProxy172.25.254.133128测试:在单网卡主机中pingwww.baidu.com不通在浏览器中访问www.baidu.com可以

【2】squid反向代理#
实验环境:192.168.1.23(haha)##Apache服务器192.168.1.10(xixi)##squid,没有数据负责缓存

xixi:172.25.254.33 修改配置文件,里面写haha。再听一下原理
haha:172.25.254.23
真机:172.25.254.17 火狐访问172.25.254.23

  • vim/etc/squid/squid.conf
    http_port 80 vhostvport##vhost支持虚拟域名vport支持虚拟端口
    #当192.168.0.12的80端口被访问会从192.168.0.11的80端口缓存数据cache_peer192.168.0.11parent 800proxy-onlysystemctlrestartsquid测试:firefoxhttp://192.168.0.12访问看到的时192.168.0.11上的数据
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值