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
相关推荐
moonless02221 天前
FastAPI框架,这一小篇就能搞懂精髓。
http·fastapi
是Dream呀2 天前
时序数据库选型指南:Apache IoTDB企业级解决方案深度解析
apache·时序数据库·iotdb
一个天蝎座 白勺 程序猿2 天前
Apache IoTDB(5):深度解析时序数据库 IoTDB 在 AINode 模式单机和集群的部署与实践
数据库·apache·时序数据库·iotdb·ainode
FPGA_Linuxer2 天前
FPGA 40 DAC线缆和光模块带光纤实现40G UDP差异
网络协议·fpga开发·udp
real 12 天前
传输层协议UDP
网络·网络协议·udp
ftpeak3 天前
从零开始使用 axum-server 构建 HTTP/HTTPS 服务
网络·http·https·rust·web·web app
hsjkdhs3 天前
网络编程之UDP广播与粘包问题
网络·网络协议·udp
yzx9910133 天前
接口协议全解析:从HTTP到gRPC,如何选择适合你的通信方案?
网络·人工智能·网络协议·flask·pygame
智_永无止境3 天前
Apache Commons Math3 使用指南:强大的Java数学库
apache·math
板鸭〈小号〉3 天前
UDP-Server(3)chat聊天室
网络·网络协议·udp