IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> 3.3#Apache的管理及优化web -> 正文阅读

[开发工具]3.3#Apache的管理及优化web

1.Apache的作用

在web被访问时通常使用http://的方式
http:// ????????##超文本传输协议
http://??超文本传输协议提供软件:
Apache
nginx
stgw
jfe
Tengine

2.Apache的安装?

dnf install httpd.x86_64 -y

3.Apache的启用?

systemctl enable --now httpd ????????##开启服务并设定服务位开机启动
firewall-cmd --list-all ????????##查看火墙信息
firewall-cmd --permanent --add-service=http ????????##在火墙中永久开启http访问
firewall-cmd --permanent --add-service=https ????????##在火墙中永久开启https访问
firewall-cmd --reload ????????##刷新火墙使设定生效

4.Apache的基本信息?

服务名称:httpd
配置文件:
/etc/httpd/conf/httpd.conf ##主配置文件
/etc/httpd/conf.d/*.conf ##子配置文件
默认发布目录:
/var/www/html
默认发布文件:
/var/www/html/index.html
默认端口:
????????#http ?????? ? ?80
????????#https???????? 443
用户:
apache
日志:
/etc/httpd/logs

5.Apache的基本配置

1.Apache端口修改

vim /etc/httpd/conf/httpd.conf
Listen 8080
firewall-cmd --permanent --add-port=8080/tcp ?
firewall-cmd --reload
systemctl restart httpd
http://172.25.254.100:8080

#2.默认发布文件##

vim /var/www/html/index.html
? ? ? ? index
vim /var/www/html/westos.html
? ? ? ? westos
vim /etc/httpd/conf/httpd.conf
????????DirectoryIndex westos.html index.html
systemctl restart httpd

#3.默认发布目录

/var/www/html

mkdir /var/www/westos
mv /var/www/westos /var
vim /etc/httpd/conf/httpd.conf
DocumentRoot "/var/westos"? ? ? ? ##默认发布目录
<Directory "/var/westos">
Require all granted? ? ? ??
</Directory>
systemctl restart httpd
firefox http://172.25.254.31

6.Apache的访问控制

#实验素材#
mkdir /var/www/html/westos
vim /var/www/html/westos/index.html
<h1>westosdir's page</h1>
firefox http://172.25.254.31/westos/

#1.基于客户端ip的访问控制#

#ip白名单#
<Directory "/var/www/html/westos">
Order Deny,Allow
Allow from 192.168.0.10
Deny from All
</Directory>

#ip黑名单#
<Directory "/var/www/html/westos">
Order Allow,Deny
Allow from All
Deny from 192.168.0.10
</Directory>

#2.基于用户认证#

vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/westos">
AuthUserfile /etc/httpd/htpasswdfile???????? ##指定认证文件
AuthName "Please input your name and password"???????? ##认证提示语
AuthType basic???????? ##认证类型
Require user admin???????? ##允许通过的认证用户 2选1
Require valid-user ????????##允许所有用户通过认证 2选1
</Directory>
htpasswd -cm /etc/httpd/htpasswdfile admin ????????##生成认证文件
注意:
/etc/httpd/htpasswdfile存在那么在添加用户时不要加-c参数否则会覆盖源文件内容

?

7.Apache的虚拟主机

mkdir -p /var/www/westos.com/{news,wenku}
echo "wenku's page" >/var/www/westos.com/wenku/index.html
echo "news's page" > /var/www/westos.com/news/index.html
echo "default's page" > /var/www/html/index.html
vim /etc/httpd/conf.d/vhost.conf
<VirtualHost _default_:80>
DocumentRoot "/var/www/html"
CustomLog logs/default.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName wenku.westos.com
DocumentRoot "/var/www/westos.com/wenku"
CustomLog logs/wenku.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName news.westos.com
DocumentRoot "/var/www/westos.com/news"
CustomLog logs/news.log combined
</VirtualHost>
systemctl restart httpd
测试:
在浏览器所在主机中
vim /etc/hosts
172.25.254.31? www.westos.com wenku.westos.ocm news.westos.com
firefox http://www.westos.com
firefox http://wenku.westos.com
firefox http://news.westos.com

?

8.Apache的语言支持 ######

#php#

vim /var/www/html/index.php
<?php
phpinfo();
?>
dnf install php -y
systemctl restart httpd
firefox http://192.168.0.11/index.php

?#cgi#

mkdir /var/www/html/cgidir
vim /var/www/html/cgidir/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
vim /etc/httpd/conf.d/vhost.conf
<Directory "/var/www/html/cgidir">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
firefox http://172.25.254.31/cgidir/index.cgi
在浏览器所在真实主机访问该index.cgi文件时,页面直接显示的是该文件的文本内容,即index.cgi文件中的代码不执行,这表明Apache不支持perl语言

?编写httpd服务的主配置文件,在文件最后添加对于/var/www/html/cgi目录,指定触发器识别该目录下以.cgi结尾的文件并执行CGI,接着重启httpd服务,给index.cgi文件赋予可执行权限

?

#wsgi#

书写wsgi的测试文件
#vim /var/www/html/wsgi/index.wsgi
def application(env, westos):
? westos('200 ok',[('Content-Type', 'text/html')])????????##注意首行缩进两个字符
? return [b'hello westos ahhahahahah!']? ? ##注意首行缩进两个字符
在浏览器所在真实主机访问该index.wsgi文件时,页面不发布文件内容,直接提示下载该文件,即index.wsgi脚本不执行,这表明Apache不具备执行该脚本的能力

?这时我们需要从软件仓库中下载安装python-mod_wsgi插件,安装完成后重启httpd服务,此时再次访问该index.wsgi文件需要用指定参数(域名)去进行访问

dnf install python3-mod_wsgi
systemctl restart httpd
vim /etc/httpd/conf.d/vhost
<VirtualHost *:80>
ServerName wsgi.westos.org
WSGIScriptAlias / /var/www/html/wsgi/index.wsgi
</VirtualHost>

?

?在浏览器所在真实主机中访问wsgi.westos.org时,index.wsgi脚本执行,页面显示hello westos,此时Apache具备执行index.wsgi脚本的能力,支持python语言

###### 9.Apache的加密访问 ######

##安装加密插件
dnf install mod_ssl -y##生成证书
##command 1
openssl genrsa -out /etc/pki/tls/private/www.westos.com.key 2048
#生成私钥
openssl req -new -key /etc/pki/tls/private/www.westos.com.key \
-out /etc/pki/tls/certs/www.westos.com.csr
##生成证书签名文件
openssl x509 -req -days 365 -in \
/etc/pki/tls/certs/www.westos.com.csr \
-signkey /etc/pki/tls/private/www.westos.com.key \
-out /etc/pki/tls/certs/www.westos.com.crt
#生成证书
x509 证书格式
-req 请求
-in 加载签证名称
-signkey
/etc/pki/tls/private/www.westos.com.key
?
##command 2
openssl req --newkey rsa:2048 \
-nodes -sha256 -keyout /etc/httpd/westos.org.key \
-x509 -days 365 -out /etc/httpd/westos.org.crt
vim /etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
ServerName login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1
</VirtualHost>
<VirtualHost *:443>
ServerName login.westos.com
DocumentRoot "/www/westos.com/login"
CustomLog logs/login.log combined
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
</VirtualHost>
systemctl restart httpd
^(/.*)$ ##客户地址栏中输入的地址
%{HTTP_HOST} ##客户主机
$1
##RewriteRule后面跟的第一串字符的值
在这里插入图片描述

?在这里插入图片描述在这里插入图片描述在这里插入图片描述

?出于安全性考虑,当客户主机使用非加密方式访问时我们需要将其转换成加密方式来进行访问?,在httpd的共享位置/var/www目录中建立login目录,在该目录下编写其发布文件index.html,编写虚拟主机配置文件/etc/httpd/vhost.conf如下,重启httpd服务

?在这里插入图片描述

在这里插入图片描述

?在这里插入图片描述在这里插入图片描述

?在浏览器所在真实主机中访问login.westos.org时,浏览器会以加密方式https转入登录页面,该页面默认发布/var/www/login目录下的index.html文件

10.Squid+Apache?

#squid 正向代理#

实验环境:
单网卡主机设定ip不能上网
双网卡主机设定ip1可以连接单网卡主机,设定ip2可以上网
实验效果
让单网卡主机不能上网但浏览器可以访问互联网页
操作:
在双网卡主机中
dnf install squid -y
vim /etc/squid/squid.conf
59 http_access allow all
65 cache_dir ufs /var/spool/squid 100 16 256
systemctl restart squid
firewall-cmd --permanent --add-port=3128/tcp
firewall-cmd --reload在单网卡专辑中选择
NetWork Proxy
172.25.254.30 3128
测试:
在单网卡主机中
ping www.baidu.com
不通
在浏览器中访问www.baidu.com可以
实验步骤:

1)在真实主机中连上无线网,开启防火墙地址伪装功能,将真实主机变为路由器

在这里插入图片描述

2)编写westosb的网卡配置文件,设定其网关为真实主机ip,为westosb配置DNS解析,重启网络,开启连接,此时虚拟主机westosb和真实主机可以通信,且westosb可以上网(ping 通百度)
在这里插入图片描述

在这里插入图片描述

?在这里插入图片描述

?3)编写westosa的网卡配置文件,此时虚拟主机westosa和真实主机可以通信,但不能上网(ping 不通百度)

在这里插入图片描述

?4)在westosb中安装代理软件squid,编写配置文件,开启代理服务squid并设定服务开机时自动启动,在防火墙中永久开启squid访问

?在这里插入图片描述

?在这里插入图片描述

?在这里插入图片描述

?5)在westosa的浏览器页面中的网络设置里手动输入代理http服务器IP和使用的通信端口号

在这里插入图片描述

?在这里插入图片描述

6)代理设置完成后westosa仍然不能上网(ping 不通百度),但可以浏览www.baidu.com

在这里插入图片描述

?

#squid反向代理#

实验环境:
172.25.254.20
##Apache服务器
172.25.254.30
##squid,没有数据负责缓存
vim /etc/squid/squid.conf
http_port 80 vhost vport ##vhost 支持虚拟域名 vport 支持虚拟端口
#当172.25.254.30的80端口被访问会从172.25.254.20的80端口缓存数据
cache_peer 172.25.254.20 parent 80 0 proxy-only
systemctl restart squid
测试:
firefox http:/172.25.254.30
访问看到的时172.25.254.20上的数据
步骤:
1)在westosb中编写squid的配置文件并重启,在防火墙中永久开启http访问
在这里插入图片描述
在这里插入图片描述

?2)在真实主机浏览器中访问westosb,显示westosa默认共享目录/var/www/html下index.html中的内容

?

?

  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2021-08-14 14:18:45  更:2021-08-14 14:21:13 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/17 18:29:00-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码