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
相关推荐
观远数据2 小时前
连锁零售的BI落地清单:从门店日报到智能补货的6步推进路径
apache·零售
德迅云安全-上官3 小时前
源站隐身 + 流量清洗,高防 IP 品牌实力精选
网络·网络协议·tcp/ip
Ai拆代码的曹操9 小时前
TCP RST 包全链路定位:从 Connection Reset 错误到 Nginx keepalive_timeout 不匹配
网络协议·tcp/ip·nginx
瓦学妹12 小时前
代理IP连接失败怎么办?2026代理IP异常排查与解决方法
网络·网络协议·tcp/ip
ITxiaobing202313 小时前
广告归因数据对齐实战:从IP溯源看点击欺诈与AppsFlyer P360的匹配度优化
大数据·网络协议·tcp/ip
似璟如你13 小时前
IoTDB 从零入门:安装、部署与第一个时序数据写入(Windows版本)
apache·时序数据库·iotdb
budaoweng060914 小时前
charles报错HTTP/1.1 200 Connection established
网络·网络协议·http
TlSfoward14 小时前
爬虫指纹漂移监控与回归测试:JA3/JA4 变化为什么会影响线上验证 TLSFOWARD
数据库·爬虫·网络协议·搜索引擎
IPDEEP全球代理14 小时前
住宅IP、移动IP、机房IP有什么区别?
网络·网络协议·tcp/ip
CHANG_THE_WORLD1 天前
TCP 三次握手彻底解析:SYN、ACK、SEQ、确认号与状态迁移
网络·网络协议·tcp/ip