使用python实现CGI环境搭建过程解析

作者:道法自然﹑ 时间:2022-11-01 11:41:26 

本文web服务器使用的为apache。

1. 安装apache

yum install -y httpd

2. 配置apache

修改apache配置文件/etc/httpd/conf/httpd.conf将下面一行的注释去掉,如果没有则添加:
LoadModule cgid_module modules/mod_cgid.so

cgi脚本文件的默认路径为/var/www/cgi-bin/

修改如下几处内容:

<Directory />
AllowOverride none
Require all denied
</Directory>

为:

<Directory "/var/www/cgi-bin">
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>

去掉注释并添加.py

AddHandler cgi-script .cgi .py

3.重启apache

第一、启动、终止、重启

systemctl start httpd.service #启动

systemctl stop httpd.service #停止

systemctl restart httpd.service #重启

第二、设置开机启动/关闭

systemctl enable httpd.service #开机启动

systemctl disable httpd.service #开机不启动

4.检查httpd状态

systemctl status httpd.service


● httpd.service - The Apache HTTP Server
 Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
 Active: active (running) since 四 2018-12-27 10:05:27 CST; 6min ago
  Docs: man:httpd(8)
     man:apachectl(8)
Main PID: 4943 (httpd)
 Status: "Total requests: 0; Current requests/sec: 0; Current traffic:  0 B/sec"
 CGroup: /system.slice/httpd.service
     ├─4943 /usr/sbin/httpd -DFOREGROUND
     ├─4946 /usr/libexec/nss_pcache 131074 off
     ├─4947 /usr/sbin/httpd -DFOREGROUND
     ├─4948 /usr/sbin/httpd -DFOREGROUND
     ├─4950 /usr/sbin/httpd -DFOREGROUND
     ├─4951 /usr/sbin/httpd -DFOREGROUND
     ├─4952 /usr/sbin/httpd -DFOREGROUND
     └─4955 /usr/sbin/httpd -DFOREGROUND

12月 27 10:05:26 master systemd[1]: Starting The Apache HTTP Server...
12月 27 10:05:26 master httpd[4943]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.1.200. Set the ...is message
12月 27 10:05:27 master systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

5编写代码


#!/usr/bin/python
#coding=utf-8

print "Content-type:text/html"
print              #空行,告诉服务器结束头部
print '<html>'
print '<head>'
print '<meta charset="utf-8">'
print '<title>Hello Word - 我的第一个CGI程序!</title>'
print '</head>'
print '<body>'
print '<h2>嘿! 你最帅了 ~</h2>'
print '</body>'
print '</html>'

6前台测试

使用python实现CGI环境搭建过程解析

OK 可以。

但是有一个问题,这是引用的python2

来源:https://www.cnblogs.com/hello-wei/p/10183424.html

标签:python,CGI,环境
0
投稿

猜你喜欢

  • mysql error 1071: 创建唯一索引时字段长度限制的问题

    2024-01-12 16:32:20
  • Python中输入和输出(打印)数据实例方法

    2021-03-25 22:32:11
  • python实现按键精灵找色点击功能教程,使用pywin32和Pillow库

    2023-11-08 18:30:34
  • 解决vue单页面多个组件嵌套监听浏览器窗口变化问题

    2024-04-27 15:48:29
  • Django自定义分页与bootstrap分页结合

    2022-05-31 23:53:00
  • python正则表达式中匹配次数与贪心问题详解(+ ?*)

    2021-04-24 20:52:04
  • python 读写中文json的实例详解

    2022-12-12 20:27:36
  • Oracle学习笔记(五)

    2012-01-05 18:52:30
  • Python json解析库jsonpath原理及使用示例

    2022-05-18 09:43:00
  • javascript forEach通用循环遍历方法

    2024-04-29 13:19:14
  • ASP 调用带参数输出的COM接口

    2011-03-17 10:59:00
  • 使用Pytorch如何完成多分类问题

    2022-01-06 20:18:46
  • MySql带OR关键字的多条件查询语句

    2024-01-21 22:39:25
  • vue中的 $slot 获取插槽的节点实例

    2024-04-30 10:26:58
  • Python对象与引用的介绍

    2023-04-30 12:51:59
  • webp 格式图片显示异常分析及解决方案

    2023-08-26 22:33:27
  • 实例解析Python的Twisted框架中Deferred对象的用法

    2024-01-01 23:38:23
  • Python进阶-函数默认参数(详解)

    2023-11-16 17:14:44
  • 解析Oracle数据库中的对象集合schema

    2023-07-22 20:42:34
  • Python torch.onnx.export用法详细介绍

    2022-04-28 22:07:33
  • asp之家 网络编程 m.aspxhome.com