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
相关推荐
5xidixi1 小时前
HTTP(1)
网络·网络协议·http
lingllllove3 小时前
使用 HTTP::Server::Simple 实现轻量级 HTTP 服务器
服务器·网络协议·http
Ljw...4 小时前
udp和tcp的区别
网络协议·tcp/ip·udp
一只码代码的章鱼4 小时前
计算机网络 笔记 传输层
网络·网络协议·tcp/ip·计算机网络
别致的影分身5 小时前
Linux网络 HTTP cookie 与 session
网络·网络协议·http
忆源8 小时前
SOME/IP--协议英文原文讲解4
网络·网络协议·tcp/ip
大秦王多鱼10 小时前
Kafka SASL/SCRAM介绍
分布式·安全·kafka·apache
esmember1 天前
电路研究9.2.6——合宙Air780EP中HTTP——HTTP GET 相关命令使用方法研究
网络·网络协议·http·at指令
weisian1511 天前
消息队列篇--通信协议篇--STOMP(STOMP特点、格式及示例,WebSocket上使用STOMP,消息队列上使用STOMP等)
websocket·网络协议
追风赶月、1 天前
【网络】传输层协议UDP
网络·网络协议·udp