我们在学习Python 时会不时的看到有人介绍cgi服务,那么今天我就以小白的方式记录下本次例练
HTTPD:
1、由于本次验证的是基于Httpd这个WEB服务器的cgi服务配置,故第一步就是安装Httpd,首先使用httpd -v 查看是否已安装
[root@hdfs-node ~]# httpd -v
-bash: httpd: command not found
[root@hdfs-node ~]#
2、通过yum 来安装httpd
[root@hdfs-master ~]# yum install -y httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 3.5 kB 00:00:00
* base: mirrors.aliyun.com
* epel: fedora.cs.nctu.edu.tw
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
ambari-2.7.0.0 | 2.9 kB 00:00:00
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/3): epel/x86_64/updateinfo | 959 kB 00:00:04
(2/3): updates/7/x86_64/primary_db | 2.5 MB 00:00:01
(3/3): epel/x86_64/primary_db | 6.6 MB 00:00:27
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-88.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-88.el7.centos for package: httpd-2.4.6-88.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-88.el7.centos.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-88.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================================================================================================================================================
Package Arch Version Repository Size
=========================================================================================================================================================================================================================================
Installing:
httpd x86_64 2.4.6-88.el7.centos base 2.7 M
Installing for dependencies:
httpd-tools x86_64 2.4.6-88.el7.centos base 90 k
mailcap noarch 2.1.41-2.el7 base 31 k
Transaction Summary
=========================================================================================================================================================================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 2.8 M
Installed size: 9.6 M
Downloading packages:
(1/3): httpd-tools-2.4.6-88.el7.centos.x86_64.rpm | 90 kB 00:00:00
(2/3): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
(3/3): httpd-2.4.6-88.el7.centos.x86_64.rpm | 2.7 MB 00:00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 2.9 MB/s | 2.8 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mailcap-2.1.41-2.el7.noarch 1/3
Installing : httpd-tools-2.4.6-88.el7.centos.x86_64 2/3
Installing : httpd-2.4.6-88.el7.centos.x86_64 3/3
Verifying : httpd-tools-2.4.6-88.el7.centos.x86_64 1/3
Verifying : mailcap-2.1.41-2.el7.noarch 2/3
Verifying : httpd-2.4.6-88.el7.centos.x86_64 3/3
Installed:
httpd.x86_64 0:2.4.6-88.el7.centos
Dependency Installed:
httpd-tools.x86_64 0:2.4.6-88.el7.centos mailcap.noarch 0:2.1.41-2.el7
Complete!
[root@hdfs-master ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 5 2018 01:47:09
根据上面代码片段可以看出已经成功安装httpd (httpd -v 有版本信息)
3、安装好服务后就可以配置了,配置信息在“/etc/httpd/conf/httpd.conf”文件里,下面是步骤:
一、打开“/etc/httpd/conf/httpd.conf”文件—vi /etc/http/conf/httpd.conf。
二、找到“#AddHandler cgi-script .cgi”,把注释符号“#”去掉。
三、找到“#DocumentRoot “/var/www/html””这一行,把注释去掉,后面的“/var/www/html”为默认首页所在的目录,可以改成自己的目录。这里以“/home/myself/www”为例。
四、找到“<Directory "/var/www/html ">”, 后面的“/var/www/html”改成 “/home/myself/www”。
五、找到“ScriptAlias /cgi-bin/ “/var/www/cgi-bin/””这一行,为默认放置cgi的目录,可以把“/var/www/cgi-bin/”自己的目录,前面的“/cgi-bin/”为路径的别名。这里以“/home/myself/cgi”为例。