http-----虚拟目录与动态网页搭建

虚拟目录:

每个 Internet服务可以从多个目录中发布。通过以通用命名约定 (UNC) 名、用户名及用于访问权限的密码指定目录,可将每个目录定位在本地驱动器或网络上。虚拟服务器可拥有一个宿主目录和任意数量的其它发布目录。其它发布目录称为虚拟目录。
虚拟目录不出现在目录列表中(也称为http://www.服务的“目录浏览”)。要访问虚拟目录,用户必须知道虚拟目录的别名,并在浏览器中键入 URL,对于http://www.服务,还可在 HTML 页面中创建链接。对于 gopher 服务,可在标志文件中创建明确的链接,以便用户可访问虚拟目录。对于FTP服务,可使用目录注释列出虚拟目录。
关于apache虚拟目录alias
关于apache虚拟目录的问题,apache的config文件中documentRoot 后面的是apache在解析页面时候的根目录,如果在本机上同时存在两个工作目录那么如果不虚拟(alias)目录的话,需要不断修改documentroot的路径,然后重启apache,相当麻烦,解决这个问题的办法之一就是设置虚拟目录
优点:
(1)便于访问
(2)便于移动站点中的目
(3)能灵活加大磁盘空间
(4)安全性好
使用alias 创建虚拟目录
Htpasswd命令是Apache的Web服务器内置工具,用于创建和更新存储用户、域和用户基本认证的密码文件
Htpasswd -c创建一个加密目录
1、建立口令文件
[root@localhost ~]# htpasswd -c /etc/httpd/mysecretpwd abc
New password:
Re-type new password:
Adding password for user abc
[root@localhost conf.d]# htpasswd /etc/httpd/mysecretpwd tom
New password:
Re-type new password:
Adding password for user tom
[root@localhost ~]# mkdir /usr/local/mysecret
[root@localhost ~]# echo ” This is mysecret” > /usr/local/mysecret/index.html
2、配置用户认证和虚拟目录
[root@localhost conf.d]# vim vhost.conf
<Directory “/usr/local/mysecret”>
AuthType Basic
AuthName “This is a private directory,Please Login:”
AuthUserFile /etc/httpd/mysecretpwd
Require user abc tom
</Directory>
<Directory “/www”>
AllowOverride None
Require all granted
</Directory>
<VirtualHost 172.16.50.37:80>
DocumentRoot “/www/haha”
Alias /mysecret “/usr/local/mysecret” 虚拟目录
ServerName www.haha.com
ServerAlias www1.haha.com
Errorlog “/var/log/httpd/www.haha.com-error_log”
CustomLog “/var/log/httpd/www.haha.com-acces_log” common
</VirtualHost>
~[root@localhost conf.d]# systemctl restart httpd
这里写图片描述
CGI通用网关接口
CGI 是Web 服务器运行时外部程序的规范,按CGI 编写的程序可以扩展服务器功能。CGI 应用程序能与浏览器进行交互,还可通过数据库API 与数据库服务器等外部数据源进行通信,从数据库服务器中获取数据。格式化为HTML文档后,发送给浏览器,也可以将从浏览器获得的数据放到数据库中。几乎所有服务器都支持CGI,可用任何语言编写CGI,包括流行的C、C ++、VB 和Delphi 等。CGI 分为标准CGI 和间接CGI两种。标准CGI 使用命令行参数或环境变量表示服务器的详细请求,服务器与浏览器通信采用标准输入输出方式。间接CGI 又称缓冲CGI,在CGI 程序和CGI 接口之间插入一个缓冲程序,缓冲程序与CGI 接口间用标准输入输出进行通信
动态网页 : 在服务器端存储的文档非HTML格式,是由编程语言开发的脚本,脚本在接受客户端的参数之后进行执行,执行后生成HTML格式的文档,然后把生成的网页发给客户端。

安装动态网页模块
[root@localhost conf.d]# yum install mod_wsgi -y
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
base | 4.1 kB 00:00:00
Resolving Dependencies
–> Running transaction check
—> Package mod_wsgi.x86_64 0:3.4-12.el7_0 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================
**Package Arch Version Repository Size
=========================================================================================**
Installing:
mod_wsgi x86_64 3.4-12.el7_0 base 76 k
**Transaction Summary
=========================================================================================**
Install 1 Package
Total download size: 76 k
Installed size: 197 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mod_wsgi-3.4-12.el7_0.x86_64 1/1
Verifying : mod_wsgi-3.4-12.el7_0.x86_64 1/1
Installed:
mod_wsgi.x86_64 0:3.4-12.el7_0
Complete!
主配置文件
[root@localhost conf.d]# vi vhost.conf
<Directory “/var/www/alt”>
AllowOverride None
#Allow open access:
Require all granted
</Directory>
listen 8909
<VirtualHost 172.16.50.37:8909>
WSGIScriptAlias / /var/www/alt/webinfo.wsgi
servername www.haha.com
</VirtualHost>
[root@localhost conf.d]# mkdir /var/www/alt
[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]
[root@localhost alt]# systemctl restart httpd
这里写图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值