http与https有何不同及相关实验提升

HTTP:
在这里插入图片描述

WWW:
在这里插入图片描述
基本配置以及常用文件目录
httpd.conf文件的格式
Web服务的基本配置
设置目录权限
虚拟主机的配置
https的配置
先介绍下apache的常用目录
1.1这个是apache的所有配置文件存放的目录
在这里插入图片描述

1.2网页默认放置的路径
Cgi-bin 是一种特殊的目录,在进行交互式的www访问(如填写在线表格)时,需要对服务器上有相应程序对访问这输入的信息进行处理,这写程序就是就是cgi程序。而这些程序只能放在cgi-bin这个目录
在这里插入图片描述

1.3Apache的主配置文件
在这里插入图片描述

httpd.conf配置文件主要由3个部分组成
全局环境
主服务器配置
虚拟主机
每部分都有相应的配置语句,该文件所有配置语句的语法为“配置参数名称 参数值”的形式。
httpd.conf的配置语句除了选项的参数值以外,所有选项指令均不区分大小写,可以在每一行前用“#”号表示注释。
全局配置的相关参数,全局的参数一般不用改动
配置路径: /etc/httpd/*
主配置目录: /etc/httpd/conf
子配置目录: /etc/httpd/conf.d(apache是一个模块化的一个配置服务,所以我们可以根据每个模块进行一些配置,不仅对程序本身进行模块化配置对配置文件也进行了模块化配置)

<>
</>
主配置文件介绍:
ServerRoot “/etc/httpd” 服务配置文件的根设置apache安装的绝对路径
Listen 80 监听端口
Include conf.modules.d/.conf
User apache 进程属主
Group apache
ServerAdmin root@localhost 服务管理员邮箱
ServerName 0.0.0.0:80 服务名
目录标签
AllowOverride none 可以覆盖前面的配置
Require all denied 禁止访问根

DocumentRoot “/var/www/html” 文档根目录
<Directory “/var/www”>
AllowOverride None
Require all granted

<Directory “/var/www/html”>
Options Indexes FollowSymLinks 选项索引跟踪软连接
AllowOverride None
Require all granted
设置文档目录访问权限


DirectoryIndex index.html 索引目录为index.html

<Files ".ht
"> 安全策略控制文件都是以.ht开头
Require all denied

ErrorLog “logs/error_log” 链接到日志的文件
LogLevel warn

LogFormat “%h %l %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i”” combined
%h 客户端IP
%l 使用identd时才会有信息,一般情况下都是-
%u 远程用户(从验证获取到的)
%t 收到请求时的时间
%r 请求的首行
%s 服务器端返回的状态码
%b 除HTTP头以外的返回的字节数
%{Referer}i 从那个页面链接跳转到的此页面
%{User-agent}i 用户的User-Agent
LogFormat “%h %l %u %t “%r” %>s %b” common

LogFormat “%h %l %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i” %I %O” combinedio

CustomLog “logs/access_log” combined


ScriptAlias /cgi-bin/ “/var/www/cgi-bin/”

<Directory “/var/www/cgi-bin”>
AllowOverride None
Options None
Require all granted


TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

AddDefaultCharset UTF-8 字符集

MIMEMagicFile conf/magic

EnableSendfile on 支持发送文件
IncludeOptional conf.d/*.conf 包括选项子配置文件

/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf

MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型。是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器会自动使用指定应用程序来打开。多用于指定一些客户端自定义的文件名,以及一些媒体文件打开方式。
它是一个互联网标准,扩展了电子邮件标准,使其能够支持:

Https
在这里插入图片描述
在这里插入图片描述
1.CA证书

在这里插入图片描述
2.基于虚拟目录和用户控制的web网站

[root@localhost ~]# htpasswd -c /etc/httpd/mymima abc(-c表示创建)
输入密码
[root@localhost ~]# htpasswd /etc/httpd/mymima tom
输入密码
[root@localhost ~]# mkdir /usr/local/mysecret
[root@localhost ~]# echo this is my secret > /usr/local/mysecret/index.html
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf
在这里插入图片描述

AuthType Basic 基本认证类型(账号)
AuthName “Please login:” 提示信息,双引号必须有,可以更换为其它提示信息
AuthUserFile /etc/httpd/mymima 用户认证文件的用户名和密码指定的文件所在位置
Require user xiaoming xiaohong 指定这两个用户可以访问该服务器

[root@localhost ~]#systemctl restart httpd
在浏览器中输入:http://192.168.227.140/mimi
【登录成功后实际上访问的是/usr/local/mysecret/index.html的内容】
会弹出如下需要输入用户名和密码的窗口:

在这里插入图片描述

如果显示类似如下提示:
Unauthorized
This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

来自 http://192.168.227.140/mimi
将下图中的“启用弹出窗口阻止程序”的勾去掉
在这里插入图片描述

3.动态网站搭建
安装包mod_wsgi      //web server Gateway Interface// alt 属性是一个必需的属性,它规定在图像无法显示时的替代文本
动态网页:在服务器端存储的文档非HTML格式,是由编程语言开发的脚本,脚本在接受客户端的参数之后进行执行,执行后生成html格式的文档,然后把生成的网页发给客户端。

Listen 8909
mkdir /var/www/alt
<Directory “/var/www/alt”>
AllowOverride None
# Allow open access:
Require all granted

<VirtualHost 192.168.0.129:8909>
WSGIScriptAlias / /var/www/alt/webinfo.wsgi

在这里插入图片描述
python脚本内容 vim /var/www/alt/webinfo.wsgi
def application(environ, start_response):
status = ‘200 OK’
output = ‘Hello World’
response_headers = [(‘Content-type’, ‘text/plain’),
(‘Content-Length’, str(len(output)))]
start_response(status, response_headers)
return [output]
application 是一个接受接受两个参数environ, start_response的标准 wsgi app:
environ: 一个包含请求信息及环境信息的字典, server 端会详细说明
start_response: 一个接受两个参数status, response_headers的方法:
status: 返回状态码,如 http 200 、 404 等
response_headers: 返回信息头部列表

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/csdn10086110/article/details/88250880
今日推荐