http协议与apache

一、URL(统一资源定位符)

URI: Uniform Resource Identifier 统一资源标识,分为URL 和 URN

作用:用于描述某服务器某特定资源位置 资源的具体位置

格式:协议://主机名:端口/url

二、HTTP 请求访问的完整过程

1.建立连接 :三次握手
2.接收请求

A 一个客户多次发起请求

使用持久连接来进行优化 一次连接多次下载

B 同一时间来了多个客户

高并发
3.处理请求
4.访问资源
5.构建响应报文
6.发送响应报文
7.记录日志

三、http协议的版本及区别

http 0.9版本 只支持下载 方法只有get 不支持长连接

http 1.0版本 加入了多种方法不止有get下载 ,post上传等 不支持长连接

http1.1 版本 加入了长连接

四、http三种工作模式及其特点

prefork 多进程工作模式 客户量少的场景

work 多进程和多线程的混合模式 客户量多的场景

event 多进程和多线程的混合模式,引入Epoll 客户量多的场景

五、http状态码1(信息类):表示接收到请求并且继续处理

1(信息类):表示接收到请求并且继续处理

2(响应成功):表示动作被成功接收、理解和接受

3(重定向类):为了完成指定的动作,必须接受进一步处理

4(客户端错误类):请求包含错误语法或不能正确执行

5(服务端错误类):服务器不能正确执行一个正确的请求

六、httpd常见配置

1.修改主站点

bash 复制代码
vim  /etc/httpd/conf/httpd.conf

95 ServerName www.example.com:80   
#开启 95 否则会报错
119 DocumentRoot "/var/www/html"   
#注释  119
120 DocumentRoot "/opt"
#选择主站点位置
<Directory "/opt">
    Require all granted
</Directory>
#同意所有人访问站点

cd  /opt
echo "cc"  > index.html

curl   192.168.133.10
#测试是否能成功访问

2.设置别名目录

bash 复制代码
vim  /etc/httpd/conf/httpd.conf

alias   /news    /data/cxk
#设置别名,访问/news就是访问/data/cxk
<Directory "/data">
     Require all granted
</Directory>

cd  /data
mkdir   cxk
echo   cxk   >  /data/cxk/index.html

curl   192.168.91.100/news   
#测试别名是否设置成功

3.让客户端可以通过多个ip地址或域名或端口访问服务器站点

1.基于端口
bash 复制代码
cp  /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf     /etc/httpd/conf.d/     
#复制模板文件
mv   /etc/httpd/conf.d/httpd-vhosts.conf      /etc/httpd/conf.d/vhosts.conf 
vim  /etc/httpd/conf.d/vhosts.conf 


<VirtualHost 192.168.91.100:80>
    DocumentRoot "/opt/cxk"
    ServerName www.cxk.com
    ErrorLog "/opt/cxk/log/error-cxk.log"
    CustomLog "/opt/cxk/log/access-cxk.log" common
</VirtualHost>

<VirtualHost 192.168.91.100:9527>
    DocumentRoot "/opt/wyf"
    ServerName www.wyf.com
    ErrorLog "/opt/wyf/log/error-wyf.log"
    CustomLog "/opt/wyf/log/access-wyf.log" common
</VirtualHost>

<Directory "/opt">
     Require all granted
</Directory>

listen  9527


cd  /opt
mkdir  {cxk,wyf}/log   -p 
echo ckx > cxk/index.html
echo wyf > wyf/index.html
systemctl  restart  httpd
curl  192.168.91.100
curl  192.168.91.100:9527
2.基于ip地址
bash 复制代码
vim  /etc/httpd/conf.d/vhosts.conf
 
 
<VirtualHost 192.168.91.100>
    DocumentRoot "/opt/cxk"
    ServerName www.cxk.com
    ErrorLog "/opt/cxk/log/error-cxk.log"
    CustomLog "/opt/cxk/log/access-cxk.log" common
</VirtualHost>

<VirtualHost 192.168.91.111>
    DocumentRoot "/opt/wyf"
    ServerName www.wyf.com
    ErrorLog "/opt/wyf/log/error-wyf.log"
    CustomLog "/opt/wyf/log/access-wyf.log" common
</VirtualHost>

<Directory "/opt">
     Require all granted
</Directory>

listen  9527


ifconfig   ens33:0  192.168.91.111/24
systemctl  restart  httpd
3.基于域名
bash 复制代码
vim  /etc/httpd/conf.d/vhosts.conf 

<VirtualHost 192.168.91.100>
    DocumentRoot "/opt/cxk"
    ServerName www.cxk.com
    ErrorLog "/opt/cxk/log/error-cxk.log"
    CustomLog "/opt/cxk/log/access-cxk.log" common
</VirtualHost>

<VirtualHost 192.168.91.100>
    DocumentRoot "/opt/wyf"
    ServerName www.wyf.com
    ErrorLog "/opt/wyf/log/error-wyf.log"
    CustomLog "/opt/wyf/log/access-wyf.log" common
</VirtualHost>

<Directory "/opt">
     Require all granted
</Directory>

listen  9527

systemctl   resstart  httpd


#对面客户端的操作:
vim   /etc/hosts
192.168.91.100  www.cxk.com   www.wyf.com

curl  www.cxk.com
curl  www.wyf.com
相关推荐
YuMiao1 天前
gstatic连接问题导致Google Gemini / Studio页面乱码或图标缺失问题
服务器·网络协议
不可能的是2 天前
前端 SSE 流式请求三种实现方案全解析
前端·http
Jony_4 天前
高可用移动网络连接
网络协议
chilix4 天前
Linux 跨网段路由转发配置
网络协议
gihigo19986 天前
基于TCP协议实现视频采集与通信
网络协议·tcp/ip·音视频
古译汉书6 天前
【IoT死磕系列】Day 7:只传8字节怎么控机械臂?学习工业控制 CANopen 的“对象字典”(附企业级源码)
数据结构·stm32·物联网·http
白太岁6 天前
通信:(5) 电路交换、报文交换与分组交换
运维·服务器·网络·网络协议
EasyGBS6 天前
国标安全升级:GB28181平台EasyGBS支持GB35114协议的应用场景与核心优势
网络协议·安全·gb28181·gb35114
凯酱6 天前
Windows防火墙入站规则IP白名单
windows·网络协议·tcp/ip
james的分享6 天前
大数据领域核心 SQL 优化框架Apache Calcite介绍
大数据·sql·apache·calcite