美文网首页Python🐍
Python CGI 在mac上的配置以及apache AH01

Python CGI 在mac上的配置以及apache AH01

作者: YocnZhao | 来源:发表于2019-05-16 17:47 被阅读0次

    关于在mac上配置CGI,我是看了这个博客https://www.jianshu.com/p/ff50628b0217
    按照这个流程走下来
    其中hello.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 - 我的第一个 CGI 程序!</title>'
    print '</head>'
    print '<body>'
    print '<h2>Hello World! 我是来自菜鸟教程的第一CGI程序</h2>'
    print '</body>'
    print '</html>'
    

    在浏览器写http://localhost/cgi-bin/hello.py发现报错:

    apache AH01630: client denied by server configuration
    

    后来去搜索发现时apache版本的httpd.conf写法不对

    #<Directory "/Library/WebServer/CGI-Executables">
    #    AllowOverride None
    #    Options ExecCGI
    #    Order allow,deny
    #    Allow from all
    #</Directory>
    #原文中是要我们写成这样,我们需要改成下面这样就可以了⤵️
    <Directory "/Library/WebServer/CGI-Executables">
        AllowOverride None
        Options ExecCGI
        Require all granted
        Require host ip
    </Directory>
    

    改完之后重新运行

    sudo apachectl restart
    

    重新在浏览器写http://localhost/cgi-bin/hello.py就OK了。

    相关文章

      网友评论

        本文标题:Python CGI 在mac上的配置以及apache AH01

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