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
相关推荐
Think Spatial 空间思维6 分钟前
【HTTPS基础概念与原理】TLS握手过程详解
数据库·网络协议·https
hnlucky11 分钟前
Windows 上安装下载并配置 Apache Maven
java·hadoop·windows·学习·maven·apache
2501_9159090644 分钟前
开发日常中的抓包工具经验谈:Charles 抓包工具与其它选项对比
websocket·网络协议·tcp/ip·http·网络安全·https·udp
利刃大大4 小时前
【网络编程】十、详解 UDP 协议
网络·网络协议·udp
LaoZhangGong1234 小时前
W5500使用ioLibrary库创建TCP客户端
网络·经验分享·stm32·网络协议·tcp/ip
北极象5 小时前
Go语言处理HTTP下载中EOFFailed
开发语言·http·golang
天天爱吃肉82186 小时前
车载以太网驱动智能化:域控架构设计与开发实践
java·运维·网络协议·微服务
IP管家7 小时前
企业级IP代理解决方案:负载均衡与API接口集成实践
服务器·网络·数据库·网络协议·tcp/ip·容器·负载均衡
{⌐■_■}8 小时前
【gRPC】HTTP/2协议,HTTP/1.x中线头阻塞问题由来,及HTTP/2中的解决方案,RPC、Protobuf、HTTP/2 的关系及核心知识点汇总
网络·网络协议·计算机网络·http·rpc·golang
Clownseven8 小时前
[IP地址科普] 服务器公网IP、私网IP、弹性IP是什么?区别与应用场景详解
服务器·网络协议·tcp/ip