HTTP原理以及搭建(补充)

虚拟目录

1、在搭建虚拟目录服务器之前,必须知道默认的情况下输入http://192.168.79.131访问的目录是/var/www/html
2、所谓的虚拟目录就是在http://192.168.79.131后边跟一个文件目录
例如:http://192.168.79.131/xixi,最后访问的是/haha/hehe/xixi
在这里插入图片描述

3、具体的搭建过程
(1)查看selinux

[root@localhost conf.d]# getenforce 
Permissive

(2)查看防火墙

[root@localhost conf.d]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Mon 2020-08-24 13:32:20 EDT; 2 days ago
 Main PID: 1006 (code=exited, status=0/SUCCESS)

Aug 24 02:59:50 localhost.localdomain systemd[1]: Starting firewalld - dynamic firew....
Aug 24 03:00:05 localhost.localdomain systemd[1]: Started firewalld - dynamic firewa....
Aug 24 13:32:18 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firew....
Aug 24 13:32:20 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewa....
Hint: Some lines were ellipsized, use -l to show in full.

(3)创建网页的根目录,写入内容

[root@localhost conf.d]# mkdir /xunimulu/haha -pv
mkdir: created directory ‘/xunimulu’
mkdir: created directory ‘/xunimulu/haha’
[root@localhost conf.d]# echo zhe shi shouye > /var/www/html/index.html
[root@localhost conf.d]# 
[root@localhost conf.d]# cat /var/www/html/index.html 
zhe shi shouye
[root@localhost conf.d]# 
[root@localhost conf.d]# echo zhe shi xu ni mulu > /xunimulu/haha/index.html
[root@localhost conf.d]# cat /xunimulu/haha/index.html 
zhe shi xu ni mulu
[root@localhost conf.d]# 

(4)编辑httpd的主配置文件

[root@localhost conf.d]# vim virticallist.conf
<virtualhost 192.168.79.131:80>
        documentroot /var/www/html #定义192.168.79.131的目录
        alias /haha /xunimulu/haha #定义haha虚拟目录,实际的网页根目录在/xunimulu/haha下,由于实际的目录是/xunimulu/haha,之所以设定的权限的目录也是/xunimulu/haha
        servername 192.168.79.131
</virtualhost>
<directory /var/www/html>
        allowoverride none
        require all granted
</directory>
<directory /xunimulu/haha>
        allowoverride none
        require all granted
</directory>

(5)重启服务

[root@localhost conf.d]# systemctl restart httpd
Enter SSL pass phrase for bogus_host_without_reverse_dns:443 (RSA) : ******

(6)测试
注意:【在命令行键面测试虚拟目录访问的时候需要加/,否则将会出现301错误,301错误就是要你更进一步完善,当然在浏览器中会自动补充后边的/】
在这里插入图片描述
在这里插入图片描述

用户控制

1、首先搭建用户控制的WEB网站必须创建用户,这里的用户不是存放在/etc/passwd中,而是在新建的文件下边
2、基于用户访问的web服务器搭建的详细过程
(1)创建用户

#这里的-c是指定存放用户名和密码的路径,若是第二次创建就不需要加-c否则将会把之前的给覆盖
[root@localhost etc]# htpasswd -c /etc/httpd/mima hehe
New password: 
Re-type new password: 
Adding password for user hehe
[root@localhost etc]# htpasswd  /etc/httpd/mima hihi
New password: 
Re-type new password: 
Adding password for user hihi


(2)在/etc/httpd/conf.d/*.conf中,在设置目录权限的容器中设定那些用户可以访问,指定用户的认证的用户名和密码文件,认证类型等

[root@localhost conf.d]# cd /etc/httpd/conf.d/
[root@localhost conf.d]# vim virticallist.conf 

<virtualhost 192.168.79.131:80>
        documentroot /var/www/html
        alias /haha /xunimulu/haha
        servername 192.168.79.131
</virtualhost>
<directory /var/www/html>
        allowoverride none
        authtype basic #认证类型
        authname "please login server:" #提示信息
        authuserfile /etc/httpd/mima #指定用户的用户名和密码文件的路径
        require user hehe #设定允许那些用户访问
</directory>
<directory /xunimulu/haha>
        allowoverride none
        authtype basic
        authname "please login server:"
        authuserfile /etc/httpd/mima
        require user hihi
</directory>

注意:【在设定允许用户登录的时候,该用户必须是在存放用户名和密码的路径中存在的用户,若是允许启用路径中的用将无法登录】
(3)重启服务

[root@localhost conf.d]# systemctl restart httpd
Enter SSL pass phrase for bogus_host_without_reverse_dns:443 (RSA) : ******

(4)测试
在没有虚拟目录中看hehe是否可以登录
在这里插入图片描述
在这里插入图片描述

在有虚拟目录中看hihi是否可以登录
在这里插入图片描述
在这里插入图片描述

动态网站

1、动态网站不是指的具有动画功能的网站,而是指根据不同情况的可以变更网站,是可以和后台数据进行一些交互
2、搭建动态网站需要WSGI这个模块,这是一个统一的python接口标准,该标准描述来python应用如何与WEB服务器通信,多个python应用之间如何级联处理请求
3、搭建过程
(1)安装WSGI模块

[root@localhost conf.d]# yum install mod_wsgi.x86_64 -y

(2)创建动态网页的根目录

[root@localhost conf.d]# mkdir /var/www/alt

(3)编辑配置文件

[root@localhost alt]# vim /etc/httpd/conf.d/vhost.conf 
listen 20000
<VirtualHost 192.168.79.131:20000>
        WSGIScriptAlias / /var/www/alt/webinfo.wsgi#WSGIScriptAlias表示动态网页的路径,“/”表示192.168.79.131:20000,而/var/www/alt/webinfo.wsgi是动态网页的路径,整体的意思就是通过192.168.79.131:20000去访问/var/www/alt/webinfo.wsgi文件
</VirtualHost>
<directory "/var/www/alt">
        allowoverride none
        require all granted
</directory>
         

(4)写动态网页的脚本

[root@localhost alt]# vim 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]

(5)启动服务进行测试
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值