HTTP服务基础

独立Web服务

Web通信基本概念

基于B/S

服务端提供网页

浏览器下载并显示网页

Hyper Text Markup Language (HTML)超文本标记语言

Hyper Text Transfer Protocol(http)超文本传输协议

RHEL7中的Web服务

软件包:httpd

系统服务:httpd

提供的默认配置

Listen:监听地址:端口(80)

ServerName:本站点注册的DNS名称

DcocumentRoot:网页根目录(/var/www/html)

DirectoryIndex:起始页/首页文件名(index.html)

一.搭建Web服务器

1.安装httpd软件

[root@server0 ~]#  yum -y install httpd

2.启动httpd服务,并设置为开机自启

[root@server0 ~]# systemctl restart httpd

[root@server0 ~]# systemctl enable httpd.service

3.书写网页文件

[root@server0 ~]# echo My First Web > /var/www/html/index.html

4.安装elinks软件,并使用elinks浏览Web网站

[root@desktop0 ~]# yum -y install elinks.x86_64

[root@server0 ~]# elinks -dump 172.25.0.11

My First Web

二.配置DNS解析

1.修改主配置文件内容/etc/httpd/conf/httpd.conf

[root@server0 ~]# vim /etc/httpd/conf/httpd.conf

/ServerName

...

ServerName server0.example.com:80  #95行

...

2.重启服务,并验证

[root@server0 ~]# systemctl restart httpd

[root@desktop0 ~]# elinks -dump server0.example.com:80

My First Web

三.网页根目录(/var/www/html)

查看主配置文件内容/etc/httpd/conf/httpd.conf

[root@server0 ~]# vim /etc/httpd/conf/httpd.conf

/Docu

...

DocumentRoot "/var/www/html" #119行

...

例如:

客户端访问路径:#elinks -dump server0.example.com/abc

服务端查找路径:/var/www/html/abc/index.html

虚拟Web主机

由同一台服务器提供多个不同的Web站点

区分方式

基于域名的虚拟主机

基于端口的虚拟主机

基于IP地址的虚拟主机(没有人用 )

配置一个虚拟站点

配置文件路径

/etc/httpd/conf/httpd.conf #主配置文件

/etc/httpd/conf.d/*.conf #从配置文件

[root@server0 ~]# vim /etc/httpd/conf/httpd.conf

...

# Load config files in the "/etc/httpd/conf.d" directory, if any.

IncludeOptional conf.d/*.conf

主配置文件最后调用所有从配置文件

目的:

为了配置方便

为了精简主配额文件

为每个虚拟站点添加配置

<VirtualHost IP地址:端口>

ServerName 此站点的DNS名称

DocumentRoot 此站点的网页根目录

</VirtualHost>

1.在帮助文档中找到虚拟站点配置文件模版

[root@server0 ~]# vi /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf

2.建立配置文件 test01.conf

[root@server0 ~]# vi /etc/httpd/conf.d/test01.conf

<VirtualHost *:80>

DocumentRoot /var/www/test

ServerName www0.example.com

</VirtualHost>

<VirtualHost *:80>

DocumentRoot /var/www/nsd

ServerName webapp0.example.com

</VirtualHost>

2.建立目录及相应的网页内容

[root@server0 ~]# mkdir /var/www/test

[root@server0 ~]# mkdir /var/www/nsd

[root@server0 ~]# echo 'wo shi test' > /var/www/test/index.html

[root@server0 ~]# echo 'wo shi nsd' > /var/www/nsd/index.html

3.重启httpd 服务

[root@server0 ~]# systemctl restart httpd.service

4.用elinks验证

[root@desktop0 ~]# elinks -dump www0.example.com

wo shi test

[root@desktop0 ~]# elinks -dump webapp0.example.com

wo shi nsd

启用虚拟Web主机,所有的站点都必须用虚拟Web主机来实现

保证 server0.example.com可以访问

1.修改从配置文件

[root@server0 ~]# vim /etc/httpd/conf.d/test01.conf

<VirtualHost   *:80>

DocumentRoot   /var/www/test

ServerName   www0.example.com

</VirtualHost>

<VirtualHost   *:80>

DocumentRoot   /var/www/nsd

ServerName   webapp0.example.com

</VirtualHost>

<VirtualHost   *:80>

DocumentRoot   /var/www/abc

ServerName   server0.example.com

</VirtualHost>

2. 重起httpd服务

httpd服务访问控制

客户集地址限制

使用<Directory>配置区段

每个文件夹自动继承其父目录的ACL访问权限

除非针对子目录有明确设置

<Directory 目录的绝对路径>

..  ..

Require all denied|granted

Require ip IP或网段地址

</Directory>

例:

Require all denied #禁止任何客户机访问

Require all granted  #允许任何客户机访问

Require ip 172.0.0.1 ::1 172.25.0.11 #仅允许部分客户机访问

实现客户集地址限制

1.创建目录与网页文件

[root@server0 ~]# mkdir /var/www/abc/private

[root@server0 ~]# echo 'xiao ke duo zhao 妈妈'> /var/www/abc/private/index.html

2.建立新的配置文件

[root@server0 ~]# vim /etc/httpd/conf.d/test02.conf

<Directory "/var/www/abc/private">

Require ip 172.25.0.11 172.0.0.1  #仅允许本机访问

</Directory>

3.重启httpd服务

[root@server0 ~]# systemctl restart httpd

[root@server0 ~]# elinks -dump server0.example.com/private

xiao ke duo zhao 妈妈

[root@desktop0 ~]# elinks -dump server0.example.com/private

Forbidden

You don't have permission to access /private on this server.

思路:客户端是否能够访问服务端资源

1.防火墙是否限制

2.服务本身的访问控制

3.SELinux 是否限制

SELinux策略保护

1.安全上下文(标签)

SELinux 会为文件打上标签

[root@server0 ~]# semanage fcontext -l  #查看SELinux给所有文件打的标签

例:

[root@server0 ~]# ls -Zd /var/www/

drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/

使用自定义Web根目录

题目: 调整Web站点http://server0.example.com的网页 使用/webroot,作为此站点新的网页目录

1.修改配置文件

[root@server0 ~]# vim /etc/httpd/conf.d/test01.conf

...

<VirtualHost *:80>

DocumentRoot /webroot

ServerName server0.example.com

</VirtualHost>

...

2.创建目录与网页文件

[root@server0 ~]# mkdir /webroot

[root@server0 ~]# echo 'wo shi webroot'> /webroot/index.html

3.修改访问控制配置文件

[root@server0 ~]# vim /etc/httpd/conf.d/test02.conf

...

<Directory "/webroot">

Require all granted

</Directory>

...

4.修改SELinux标签值

[root@server0 ~]# chcon -R --reference=/var/www /webroot/

#将/var/www 的文件标签 给 /webroot 文件目录

[root@server0 ~]# ls -Zd /webroot/

drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /webroot/

5.重启httpd服务验证

[root@server0 ~]# systemctl restart httpd.service

[root@desktop0 ~]# elinks -dump server0.example.com

wo shi webroot

安全Web服务

https 安全的超文本协议 端口号:443

数字证书基础

PKI公钥基础设施 Public Key Infrastructure

公钥:主要用来加密数据

私钥:主要用来解密数据(与相应的公钥匹配)

数字证书:证明拥有着的合法性/权威性(单位名称,有效期,公钥,颁发机构及签名)

Certificate Authority (CA)  数字证书授权中心:负责证书的申请/审核/颁发/鉴定/撤销等管理工作

//本文使用的数字证书 ,公钥,私钥 均为网上下载

//如果想要了解如何搭建 CA服务器 可以浏览 http://blog.51cto.com/13558754/2057718

搭建https

可以访问https://server0.example.com

1.安装mod_ssl软件包

[root@server0 ~]# yum -y install mod_ssl.x86_64

2.部署网站的证书

[root@server0 tls]# cd /etc/pki/tls/certs/A

[root@server0 certs]# wget http://172.25.254.254/pub/tls/certs/server0.crt

3.部署网站的根证书

[root@server0 tls]# cd /etc/pki/tls/certs/

[root@server0 certs]# wget http://172.25.254.254/pub/example-ca.crt

4.部署私钥

[root@server0 certs]# cd /etc/pki/tls/private/

[root@server0 private]# wget http://172.25.254.254/pub/tls/private/server0.key

5.修改配置文件

[root@server0 private]# vim /etc/httpd/conf.d/ssl.conf

...

DocumentRoot "/webroot" #59行

ServerName server0.example.com:443

...

SSLCertificateFile /etc/pki/tls/certs/server0.crt #100行

...

SSLCertificateKeyFile /etc/pki/tls/private/server0.key #107行

...

SSLCACertificateFile /etc/pki/tls/certs/example-ca.crt #122行

...

6.重启服务

[root@server0 private]# systemctl restart httpd.service

7.验证

[root@desktop0 ~]# firefox https://server0.example.com

//如果想要了解更多关于 搭建https服务的知识可以浏览 http://blog.51cto.com/13558754/2057837

部署动态网站

部署并测试WSGI站点

题目: 为站点webapp0.example.com配置提供动态Web

要求:

此虚拟主机监听在端口8909

测试网页为webinfo.wsgi

从浏览器访问 http://webapp0.example.com:8909 可以接收到动态生成的Web界面

1.安装mod_wsgi软件

[root@server0 /]# yum -y install mod_wsgi.x86_64

2.切换到相应/var/www/nsd目录下下载动态页面

[root@server0 /]# cd /var/www/nsd/

[root@server0 nsd]# wget http://172.25.254.254/pub/materials/webinfo.wsgi

[root@server0 nsd]# cat webinfo.wsgi

3.在Desktop0上查看,可以看到源代码

[root@desktop0 ~]# firefox webapp0.example.com/webinfo.wsgi

4.server0上修改

[root@server0 nsd]# vim /etc/httpd/conf.d/test01.conf

...

<VirtualHost *:80>

DocumentRoot /var/www/nsd

ServerName webapp0.example.com

wsgiscriptalias / /var/www/nsd/webinfo.wsgi

</VirtualHost>

...

5.重启服务,验证

[root@server0 nsd]# systemctl restart httpd.service

[root@desktop0 ~]# elinks -dump webapp0.example.com

UNIX EPOCH time is now: 1509700659.44

#UINX 时间戳:自1970-1-1 0:0:0 到达当前所经过的秒数

6.修改webapp0.example.com端口号8909

[root@server0 nsd]# vim /etc/httpd/conf.d/test01.conf

Listen 8909

<VirtualHost *:8909>

DocumentRoot /var/www/nsd

ServerName webapp0.example.com

wsgiscriptalias / /var/www/nsd/webinfo.wsgi

</VirtualHost>

7.重启服务,(发现不能启动)

[root@server0 nsd]# systemctl restart httpd.service

Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.

SELinux策略保护

标配Web端口

使用semanage工具可查看

当尝试监听非标配端口时,SELinux会阻止

导致httpd 服务启动失败

查看/var/log/messages文件中会有记录

8.SELinux限制8909端口

[root@server0 nsd]# semanage port -l | grep http #查看http允许的端口

http_cache_port_t              tcp      8080, 8118, 8123, 10001-10010

http_cache_port_t              udp      3130

http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000

pegasus_http_port_t            tcp      5988

pegasus_https_port_t           tcp      5989

[root@server0 nsd]# semanage port -a -t http_port_t  -p tcp 8909 #添加8909端口加入http允许端口中

[root@server0 nsd]# semanage port -l | grep http

http_cache_port_t              tcp      8080, 8118, 8123, 10001-10010

http_cache_port_t              udp      3130

http_port_t                    tcp      8909, 80, 81, 443, 488, 8008, 8009, 8443, 9000

pegasus_http_port_t            tcp      5988

pegasus_https_port_t           tcp      5989

[root@server0 nsd]# systemctl restart httpd.service #重启成功

验证

[root@desktop0 ~]# elinks -dump webapp0.example.com:8909

UNIX EPOCH time is now: 1509767472.39

关于web服务器 在RHCE7的考试中有这么5道题 :

实现一个Web服务器

为 http://server0.example.com 配置 Web 服务器:

从URL地址 http://classroom.example.com/pub/materials/station.html 下载一个主页文件,并将该文件重命名为 index.html

将文件 index.html 拷贝到您的 web 服务器的 DocumentRoot 目录下

不要对文件 index.html 的内容进行任何修改

[root@system1 ~]#yum -y install httpd

[root@system1 ~]#vim /usr/local/share/

[root@system1 ~]#vim /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf  #寻找虚拟主机模版

[root@system1 ~]#vim /etc/httpd/conf.d/test01.conf

<VirtualHost *:80>

DocumentRoot /var/www/html

ServerName server0.example.com

</VirtualHost>

[root@system1 ~]#wget -O /var/www/html/index.html http://classroom/pub/materials/station.html

[root@system1 ~]#systemctl restart httpd

[root@system1 ~]#systemctl enable httpd

[root@system2 ~]# curl  http://server0.example.com

配置安全Web服务

为站点 http://server0.example.com 配置TLS加密:

一个已签名证书从 http://classroom.example.com/pub/tls/certs/server0.crt 获取

此证书的密钥从 http://classroom.example.com/pub/tls/private/server0.key 获取

此证书的签名授权信息从 http://classroom.example.com/pub/example-ca.crt 获取

[root@system1 ~]# yum -y install mod_ssl.x86_64

[root@system1 ~]# cd /etc/pki/tls/certs/

[root@system1 ~]# wget http://classroom/pub/example-ca.crt

[root@system1 ~]# wget http://classroom/pub/tls/certs/server0.crt

[root@system1 ~]# cd ../private/

[root@system1 ~]# wget http://classroom/pub/tls/private/server0.key

[root@system1 ~]# vim /etc/httpd/conf.d/ssl.conf

<VirtualHost _default_:443>

# General setup for the virtual host, inherited from global configuration

DocumentRoot "/var/www/html"

ServerName www.example.com:443

...

SSLCertificateFile /etc/pki/tls/certs/server0.crt

SSLCertificateKeyFile /etc/pki/tls/private/server0.key

SSLCACertificateFile /etc/pki/tls/certs/example-ca.crt

[root@system1 ~]# systemctl restart httpd

[root@system2 ~]# firefox https://server0.example.com

实现一个Web服务器

为 http://server0.example.com 配置 Web 服务器:

从URL地址 http://classroom.example.com/pub/materials/station.html 下载一个主页文件,并将该文件重命名为 index.html

将文件 index.html 拷贝到您的 web 服务器的 DocumentRoot 目录下

不要对文件 index.html 的内容进行任何修改

[root@system1 ~]# mkdir /var/www/virtual

[root@system1 ~]# wget -O /var/www/virtual/index.html http://classroom/pub/materials/www.html

[root@system1 ~]# vim /etc/httpd/conf.d/test01.conf

<VirtualHost *:80>

DocumentRoot /var/www/virtual

ServerName www0.example.com

</VirtualHost>

[root@system1 ~]# useradd fleyd

[root@system1 ~]# setfacl -m u:fleyd:rwx /var/www/virtual/

[root@system1 ~]# systemctl restart httpd

[root@system2 ~]# curl www0.example.com

配置Web内容访问

在您的 server0 web服务器的 DocumentRoot 目录下创建一个名为 private 的目录,要求如下:

从 http://classroom.example.com/pub/materials/private.html 下载一个文件副本到这个目录,并且命名为 index.html

不要对这个文件的内容做任何修改

从 system1 上,任何人都可以浏览 private 的内容,但是从其他系统不能访问这个目录的内容

[root@system1 ~]# wget -O /var/www/html/private/index.html http://classroom/pub/materials/private.html

[root@system1 ~]# vim /etc/httpd/conf/httpd.conf  #寻找模版

[root@system1 ~]# vim /etc/httpd/conf.d/test02.conf

<Directory "/var/www/html/private">

Require ip 127.0.0.1 ::1 172.25.0.11

</Directory>

[root@system1 ~]# systemctl restart httpd.service

[root@system1 ~]# firefox http://server0.example.com/private

[root@system2 ~]# firefox http://server.example.com/private

实现动态Web内容

在system1 上配置提供动态Web内容,要求如下:

动态内容由名为 webapp0.example.com 的虚拟主机提供

虚拟主机侦听在端口 8909

从 http://classroom.example.com/pub/materials/webinfo.wsgi 下载一个脚本,然后放在适当的位置,无论如何不要修改此文件的内容

客户端访问 http://webapp0.example.com:8909 可接收到动态生成的 Web 页

此 http://webapp0.example.com:8909/必须能被 example.com 域内的所有系统访问

[root@system1 ~]#mkdir /var/www/webapp0

[root@system1 ~]#cd /var/www/webapp0

[root@system1 ~]#wget http://classroom/pub/materials/webinfo.wsgi

[root@system1 ~]#vim /etc/httpd/conf.d/test01.conf

listen 8909

<VirtualHost *:8909>

DocumentRoot /var/www/webapp0

wsgiscriptalias / /var/www/webapp0/webinfo.wsgi

ServerName webapp0.example.com

</VirtualHost>

[root@system1 ~]#yum -y install mod_wsgi

[root@system1 ~]#semanage port -l | grep http

[root@system1 ~]#semanage port -a -t http_port_t -p tcp 8909

[root@system1 ~]#vim /etc/httpd/conf.d/test01.conf

[root@system1 ~]#systemctl restart httpd

[root@system2 ~]# firefox http://webapp0.example.com:8909

本文转自 Xuenqlve 51CTO博客,原文链接:http://blog.51cto.com/13558754/2058772,如需转载请自行联系原作者

全面分析RHCE7(红帽认证工程师)考试题目之 ----WEB 服务器 篇相关推荐

  1. 想考红帽认证工程师常见问题解答

    其实一直以来就想考个RHCE,但是没对考试有系统的了解.通过查找资料,得到这编文章可以解答 1. 红帽认证工程师及红帽认证技师认证考试是开卷考试吗? 不是.红帽认证工程师及红帽认证技师认证考试为闭卷考 ...

  2. 红帽认证工程师常见问题解答(转)

    红帽认证工程师常见问题解答(转)[@more@]红帽企业Linux 3的发布对红帽认证工程师课程和红帽公司提供的其它课程有什么影响? 红帽认证工程师操作考试是开卷考试吗? 0.我听说红帽认证工程师考试 ...

  3. 红帽认证工程师和红帽认证技师应试指南

    这是我在红帽官网上看到的关于红帽人证的介绍,有对红帽认证感兴趣的可一参考下: 红帽认证工程师及红帽认证技师应试指南 概述 --> 在本指南中,主要对红帽认证技师(RHCT)或红帽认证工程师(RH ...

  4. 红帽认证工程师及红帽认证技师应试指南

    红帽认证工程师及红帽认证技师应试指南 概述 --> 在本指南中,主要对红帽认证技师(RHCT)或红帽认证工程师(RHCE)应试过程中可能会用到的信息进行了介绍.对于红帽全球培训服务(Red Ha ...

  5. Red Hat 宣布新的红帽认证工程师计划

    开发四年只会写业务代码,分布式高并发都不会还做程序员? >>>   红帽公司近日在博客公布了关于红帽认证工程师(RHCE)的新计划. 红帽方面表示,随着行业本身的发展和变化,新技术应 ...

  6. 红帽认证工程师(RHCE)的发展前景

    Linux位居操作系统产品增长之首,市场同比增长率达到30.9%,市场价值达到357亿美元.继续保持较快增长态势.在三年时间内, Linux可望在1700万PC中使用,使其安装规模达到4260万,达到 ...

  7. 全面分析RHCE7(红帽认证工程师)考试题目之 ----SSH篇

    管理SSH服务(远程连接服务) 一,ssh服务常用配置参数 /etc/ssh/sshd_config 注意:修改端口时要确保SELinux 不是 Enforcing [root@test13 ~]# ...

  8. 全面分析RHCE7(红帽认证工程师)考试题目之 ---Firewall(防火墙)篇

    防火墙策略管理(firewall) 作用:隔离 局域网和外网之间 阻止入站,允许出站 软件防火墙 系统服务:firewalld 管理工具:firewall-cmd(命令工具. Linux7),fire ...

  9. 全面分析RHCE7(红帽认证工程师)考试题目之 ----邮件篇

    基础邮件服务 电子邮件服务器的基本功能 为用户提供电子邮箱存储空间(用户名@邮件域名) 处理用户发出的邮件-------传递给收件服务器 处理用户收到的邮件-------投递到邮箱 配置前提 虚拟机s ...

最新文章

  1. windows系统和linux系统可以使用相同的js代码吗_「React 手册 」在 Windows 下使用 React , 你需要注意这些问题...
  2. 一款vue编写的功能强大的swagger-ui,有点秀(附开源地址)
  3. iOS6.0 xcode4.5 设置横屏
  4. python数据挖掘入门与实战代码
  5. 7用Eclipse进行JSP开发
  6. 打开黑色_垃圾桶里的黑色塑料袋,打开一看,倒吸一口气!
  7. BJRangeSliderWithProgress
  8. C#.NET根据数据库中0,1返回对应代表含义“男”,“女”等问题
  9. JQuery判断元素是否存在
  10. html计算一个数组所有元素的和,函数bsxfun,两个数组间元素逐个计算的二值操作...
  11. mtk android 编译环境,MTK android 快速编译方法.docx
  12. 『ORACLE』Oracle GoldenGate搭建(11g)
  13. 玉溪推行电子政务 建设新型智慧城市
  14. animate inater插件_maya插件管理器(Plug-in Manager),MAYA
  15. 微信小程序傻瓜制作_从15款工具中精选出4款,最靠谱的微信小程序制作软件!...
  16. uchome 数据字典详解
  17. 动名词做主语时的谓语动词问题
  18. 苹果手机微信怎么接龙_【手机】微信接龙
  19. Goolge Colab使用教程
  20. 船长的error笔记

热门文章

  1. PIC单片机RC振荡器的使用及校准方法
  2. 服务器2012系统更新后蓝屏怎么删除更新,win10更新补丁后蓝屏怎么删?win10更新补丁后蓝屏的解决方法...
  3. 学习Linux命令(26)
  4. 2022-1-25 Leetcode 884.两句话中的不常见单词
  5. SpringCloud微服务完整项目实例源码
  6. wps怎么导入xml文件_《WPS表格怎么导入XML数据?》 如何将excel导入wps表格数据
  7. 珠海化学分析实验室建设思路
  8. android百度测试,【腾讯百度测试面试题】面试问题:Android… - 看准网
  9. mysql数据库引擎转换_[转]MySQL数据库引擎
  10. cv2.drawContours()讲解