美文网首页
apache2配置CGI运行脚本文件

apache2配置CGI运行脚本文件

作者: 1234yws | 来源:发表于2019-04-25 10:28 被阅读0次

1、cd安装apache2的位置

cd /etc/apache2

2、找到sites-enabled文件夹


文件内容.png

3、查看内容

ls

4、编辑配置文件


编辑配置文件.png
//cgi文件路径
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
                //添加这行,.py后缀可以访问py脚本
                AddHandler cgi-script .cgi .pl .py .sh
        </Directory>

5、cd到设置的运行路径

cd /usr/lib/cgi-bin

6、创建文件hello.py

#!/usr/bin/python3

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>Hello Word! </h2>')
print ('</body>')
print ('</html>')

7、浏览器访问

http://localhost/cgi-bin/hello.py

相关文章

网友评论

      本文标题:apache2配置CGI运行脚本文件

      本文链接:https://www.haomeiwen.com/subject/sdragqtx.html