www所用的协议:
HTTP超文本传输协议(HyperText Transfer Protocal)
WEB服务器 www web http apache http server tomcat nginx IIS
网页文件位置: /var/www/html
HTTP协议请求的工作流程
(1)终端客户在web浏览器地址栏输入访问地址http://www.ceshi.com:80/index.html
(2)web浏览器请求DNS服务器把域名www.ceshi.com解析成web服务器的IP地址
(3)web浏览器将端口号(默认是80)从访问地址(URL)中解析出来
(4)web浏览器通过解析后的ip地址及端口号与web服务器之间建立一条TCP连接
(5)建立TCP连接后,web浏览器向web服务器发送一条HTTP请求报文
(6)web服务器响应并读取浏览器的请求信息,然后返回一条HTTP响应报文。
(7)web服务器关闭HTTP连接,关闭TCP连接,web浏览器显示访问的网站内容到屏幕上。
www服务器的基本配置
服务器端:在linux上面实现网页服务器需要Apache这套服务器软件,httpd提供Apache主程序 http://
httpd.apache.org/docs/2.4/
安装软件:httpd
配置文件:
1. 主要的配置文件 /etc/httpd/conf/httpd.conf 。
2. 额外的参数文件 /etc/httpd/conf.d/*.conf 。
如果你不想要修改原始配置文件httpd.conf的话,那么你可以将你自己的额外参数文件独立出来,
例如你想要有自己的额外设置值,可以将它写入 /etc/httpd/conf.d/zhuji.conf (注意,扩展
名一定是.conf),而启动Apache时,这个文件就会被读入主要配置文件当中了。
3. 默认的首页所在目录 /var/www/html/ ,当输入网址时所显示的数据,就是放在这个目录当中的首
页文件(默认为index.html)。
4. 默认给一些可执行的CGI(网页程序)程序放置的目录 /var/www/cgi-bin/ ,当输入网址/cgi-bin/
时所显示的数据所在。
5. 默认的Apache日志文件都放在 /var/log/httpd/ ,对于流量比较大的网站来说,一个星期的日志
文件的数据可以达到1GB左右
1.虚拟机开启httpd并写一个简单网页文件,基于http使windows浏览器能够访问
1.编辑网页文件
[root@localhost html]# cd /var/www/html
[root@localhost html]# ll
total 4
-rw-r--r--. 1 root root 18 Oct 18 20:25 index.html
[root@localhost html]# vim index.html
<b>helloworld</b> //网页内容
2.设置防火墙状态和安全子系统
[root@localhost ~]#systemctl stop firewalld //stop单次,disable永久
[root@localhost html]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=permissive //设置为警示关闭状态
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
3.访问虚拟机服务器的网页文件
http://192.168.157.128:80!
2.建立两个基于ip地址访问的网站
[root@localhost conf.d]# vim /etc/httpd/conf.d/vhosts.conf
<VirtualHost 192.168.157.100:80>
ServerName 192.168.157.100
DocumentRoot /var/www/openlab
</VirtualHost>
<Directory /var/www>
AllowOverride none
Require all granted
</Directory>
<VirtualHost 192.168.157.101:80>
ServerName www.haha.com
DocumentRoot /var/www/w1
</VirtualHost>
<VirtualHost 192.168.157.102:80>
ServerName 192.168.157.102
DocumentRoot /var/www/w2
</VirtualHost>
[root@localhost conf.d]# cd /var/www
[root@localhost www]# ll
total 0
drwxr-xr-x. 2 root root 6 Jul 13 2021 cgi-bin
drwxr-xr-x. 2 root root 24 Oct 20 14:35 html
drwxr-xr-x. 2 root root 24 Oct 22 19:33 openlab
drwxr-xr-x. 2 root root 24 Oct 22 19:36 w1
drwxr-xr-x. 2 root root 24 Oct 22 20:30 w2
[root@localhost www]# vim openlab/index.html //w1和w2同理
this is 100
[root@localhost www]# systemctl start httpd
[root@localhost www]# systemctl stop firewalld.service
[root@localhost www]# getenforce
Permissive
[root@localhost www]# curl 192.168.157.100
this is 100
[root@localhost www]# curl 192.168.157.101
this is 101
[root@localhost www]# curl 192.168.157.102
this is 102 by port 8888(yuming)
3.建立两个基于不同端口访问的网站
[root@localhost conf.d]# vim vhosts.conf
<VirtualHost 192.168.157.100:80>
ServerName 192.168.157.100
DocumentRoot /var/www/openlab
</VirtualHost>
<Directory /var/www>
AllowOverride none
Require all granted
</Directory>
<VirtualHost 192.168.157.101:80>
ServerName 192.168.157.101
DocumentRoot /var/www/w1
</VirtualHost>
<VirtualHost 192.168.157.101:8888>
ServerName 192.168.157.101
DocumentRoot /var/www/w2
</VirtualHost>
LISTEN 8888
[root@localhost conf.d]# curl 192.168.157.101:80
this is 101
[root@localhost conf.d]# curl 192.168.157.101:8888
this is 102 by port 8888(yuming)
4.建立一个同时拥有两个域名的网站
[root@localhost conf.d]# vim /etc/hosts //本地dns缓存
192.168.157.101 www.haha.com www.hehe.com
192.168.157.102 www.heihei.com
[root@localhost conf.d]# vim vhosts.conf
<VirtualHost 192.168.157.100:80>
ServerName 192.168.157.100
DocumentRoot /var/www/openlab
</VirtualHost>
<Directory /var/www>
AllowOverride none
Require all granted
</Directory>
<VirtualHost 192.168.157.101:80>
ServerName 192.168.157.101
DocumentRoot /var/www/w1
</VirtualHost>
<VirtualHost 192.168.157.102:80>
ServerName www.heihei.com
DocumentRoot /var/www/w2
</VirtualHost>
验证:
[root@localhost conf.d]# curl www.haha.com
this is 101
[root@localhost conf.d]# curl www.hehe.com
this is 101
[root@localhost conf.d]# curl www.heihei.com
this is 102 by port 8888(yuming)