web和http协议
协议---规则
web服务----http协议
tcp/udp 传输数据
tcp和udp传输数据的不同
tcp比udp安全
udp比tcp的速度块
服务-----tcp
tcp----三次握手(建立连接)
tcp----四次挥手(断开) 断开连接
http协议:
1.0版本 广泛应用的
现在使用的是1.1版本
0.9--1.0 1.0版本在请求报文中加入了请求头
1.0---1.1 1.1版本能够支持长连接
url 路径 访问 http://www.kgc.com url
门牌号 可以找到对应的资源 单个资源
uri 统一资源标识符 一类资源 图片
网站:
静态页面 不能交互的界面 固定的 开发人员写什么就会显示出什么(前段)不连接后端数据库的页面
html png jpeg
动态页面
伪静态页面
ip
源码httpd
client 192.168.2.10
httpd 192.168.2.20
修改默认页面
httpd
[root@localhost ~]# echo 111111 > /usr/local/httpd/htdocs/index.html
client
[root@localhost ~]# curl 192.168.2.20
111111
[root@localhost ~]# cd /usr/local/httpd/
[root@localhost httpd]# ls
bin cgi-bin error icons logs manual
build conf htdocs include man modules
bin 启动命令 脚本
[root@localhost httpd]# cd conf/ #配置文件的目录
[root@localhost conf]# ls
extra httpd.conf magic mime.types original
httpd.conf #主配置文件 #程序加载只会加载主配置文件
[root@localhost conf]# cd extra/
[root@localhost extra]# ls #功能配置的样例文件
httpd-autoindex.conf httpd-mpm.conf
httpd-dav.conf httpd-multilang-errordoc.conf
httpd-default.conf httpd-ssl.conf
httpd-info.conf httpd-userdir.conf
httpd-languages.conf httpd-vhosts.conf #虚拟主机的配置文件
httpd-manual.conf proxy-html.conf
mime.types #httpd服务支持加载文件的类型
logs #日志目录
access_log #访问日志
error_log #错误日志
httpd.pid
client 192.168.2.10
server 192.168.2.20 源码安装的httpd
#配置文件
[root@localhost ~]# cd /usr/local/httpd/
[root@localhost httpd]# cd conf/
[root@localhost conf]# vim httpd.conf
31 ServerRoot "/usr/local/httpd" #工作目录
52 Listen 80 #监听端口
66 LoadModule authn_file_module modules/mod_authn_file.so #httpd加载的动态模块
LoadModule 命令名 模块的路径
162 User daemon
163 Group daemon
apache 程序用户 管理程序 -M -s /sbin/nologin
ssh 一般公司当中都会禁用root用户远程登录
sudo
184 ServerAdmin you@example.com #管理员的邮箱地址
193 #ServerName www.example.com:80 #域名
217 DocumentRoot "/usr/local/httpd/htdocs" #站点根目录
218 <Directory "/usr/local/httpd/htdocs">
231 Options Indexes FollowSymLinks #如果缺少默认index.html的页面 就会把其他的文件以列表的形式显示
238 AllowOverride None #允许开启分布式权限
243 Require all granted #允许访问目录中的内容
244 </Directory>
index.html aa.html bb.html
aa.html
bb.html
<Directory />
AllowOverride none
Require all granted
</Directory>
/one /two
yum
250 <IfModule dir_module>
251 DirectoryIndex index.html #默认索引页
252 </IfModule>
269 ErrorLog "logs/error_log" #错误诶只的目录
276 LogLevel warn #warning之上的日志
info--debug--waring--error 日志等级
283 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Refe rer}i\" \"%{User-Agent}i\"" combined #日志格式
298 CustomLog "logs/access_log" common 访问日志
488 <IfModule proxy_html_module>
489 Include conf/extra/proxy-html.conf #主配置文件当中可以包含其他配置文件 这样在加载主配置文件时,也会加载其他的配置文件
490 </IfModule>
httpd----httpd.conf(proxy-html.conf)
httpd配置虚拟主机
httpd---1个站点
2个站点
相同的ip 相同的端口 不同域名 www.one.com www.two.com
相同的ip 相同域名 不同端口 192.168.2.20:80 192.168.2.20:8080
相同域名 相同端口 不同ip 192.168.2.20 192.168.2.30
基于域名的虚拟主机
第一步
client 通过域名访问 dns
/etc/hosts
[root@localhost ~]# vim /etc/hosts
192.168.2.20 www.one.com
192.168.2.20 www.two.com
服务端:
第二步
创建出两个站点
[root@localhost ~]# mkdir /one
[root@localhost ~]# mkdir /two
[root@localhost ~]# echo one > /one/index.html
[root@localhost ~]# echo two > /two/index.html
[root@localhost ~]# cat /one/index.html
one
[root@localhost ~]# cat /two/index.html
two
配置
[root@localhost ~]# cd /usr/local/httpd/conf/extra/
[root@localhost extra]# vim httpd-vhosts.conf
23 <VirtualHost *:80>
24 ServerAdmin webmaster@dummy-host.example.com
25 DocumentRoot "/one" #站点目录
26 ServerName www.one.com #域名
27 ServerAlias www.dummy-host.example.com #域名的别名
28 ErrorLog "logs/one-error_log" #错误日志
29 CustomLog "logs/one-access_log" common #访问日志
30 <Directory />
31 AllowOverride none
32 Require all granted
33 </Directory>
34 </VirtualHost>
36 <VirtualHost *:80>
37 ServerAdmin webmaster@dummy-host2.example.com
38 DocumentRoot "/two"
39 ServerName www.two.com
40 ErrorLog "logs/two-error_log"
41 CustomLog "logs/two-access_log" common
42 <Directory />
43 AllowOverride none
44 Require all granted
45 </Directory>
46 </VirtualHost>
[root@localhost extra]# vim /usr/local/httpd/conf/httpd.conf
476 Include conf/extra/httpd-vhosts.conf #让其主配置文件包含虚拟主机的配置文件
[root@localhost extra]# systemctl stop httpd
[root@localhost extra]# systemctl start httpd
[root@localhost extra]# netstat -anput | grep httpd
tcp6 0 0 :::80 :::* LISTEN 15639/httpd
[root@localhost extra]# systemctl stop firewalld
client:
[root@localhost ~]# curl www.one.com
one
[root@localhost ~]# curl www.two.com
two
基于端口的虚拟主机
[root@localhost ~]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
23 <VirtualHost 192.168.2.20:80>
26 ServerName www.one.com
36 <VirtualHost 192.168.2.20:8080>
39 ServerName www.one.com
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf
52 Listen 80
53 Listen 8080
[root@localhost ~]# systemctl stop httpd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# netstat -anput | grep httpd
tcp6 0 0 :::80 :::* LISTEN 16247/httpd
tcp6 0 0 :::8080 :::* LISTEN 16247/httpd
client
[root@localhost ~]# curl 192.168.2.20:80
one
[root@localhost ~]# curl 192.168.2.20:8080
two
基于ip的虚拟主机
服务端
[root@localhost ~]# ifconfig ens33:0 192.168.2.30/24 #临时
[root@localhost ~]# ip a
[root@localhost ~]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
23 <VirtualHost 192.168.2.20:80>
36 <VirtualHost 192.168.2.30:80>
[root@localhost ~]# systemctl stop httpd
[root@localhost ~]# systemctl start httpd
client
[root@localhost ~]# curl 192.168.2.20
one
[root@localhost ~]# curl 192.168.2.30
two