Ubuntu Apache2 CGI配置

  • CGI定义如下

CGI(Common Gateway Interface),通用网关接口,它是一段程序,运行在服务器上如:HTTP服务器,提供同客户端HTML页面的接口。

  • CGI程序可以是Python脚本,PERL脚本,SHELL脚本,C或者C++程序等。这里以Python脚本为例子。
  • 网上有些CGI配置,可能有些复杂。其实配置起来还是,挺方便的。

配置过程

  • 安装Apache
sudo apt install apache2
  • /etc/apache2/apache2.conf中加入如下内容
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
  • 创建cgi-bin文件夹
cd /var/www
sudo mkdir cgi-bin
# 将cgi-bin文件夹所有权分配给linduo
sudo chown -R linduo cgi-bin
  • 启用CGI
sudo a2enmod cgi
  • 重启apache服务
sudo service apache2 restart
  • 测试
cd /var/www/cgi-bin/
touch helloworld.py
  • 测试:在helloworld.py中输入如下内容
#!/usr/bin/python
# -*- coding: UTF-8 -*-

print "Content-type:text/html"
print
print '<html>'
print '<head>'
print '<meta charset="utf-8">'
print '<title>Hello World!</title>'
print '</head>'
print '<body>'
print '<h2>Hello World!</h2>'
print '</body>'
print '</html>'

相关文章:

  • 2021-07-24
  • 2022-12-23
  • 2021-09-13
  • 2021-07-06
  • 2022-03-04
  • 2021-12-08
  • 2021-07-05
  • 2021-12-07
猜你喜欢
  • 2021-10-10
  • 2022-02-21
  • 2021-08-06
  • 2022-01-26
  • 2021-10-01
相关资源
相似解决方案