[英]Need Help to Configure apache Server to run CGI Script written in Python
[英]Configure apache to run python (cgi)
我已经在安装了Apache 2.4.4的wampserver中
我已经安装了python并且创建了一个测试文件:
#!/Python34/python
print "Content-type: text/html"
print
print "<html><head>"
print ""
print "</head><body>"
print "Hello."
print "</body></html>"
我想知道如何运行此脚本?
我个人不喜欢CGI和所有这些东西的工作方式(缓慢生成进程,需要使用诸如“ fastcgi”之类的技巧来绕开它,等等。)
我认为您可以将Python程序构建为HTTP服务器(例如,使用cherrypy或您想要的任何东西),启动Python程序以监听localhost:无论如何,然后从Apache端,只需将代理配置为localhost:随你。
优点:
配置apache 2将您的请求传递给python守护程序很简单:
<VirtualHost *:80>
ServerName example.com
ProxyPass / http://localhost:8080/
</VirtualHost>
以及来自cherrypy文档的世界:
import cherrypy
class HelloWorld(object):
def index(self):
return "Hello World!"
index.exposed = True
cherrypy.quickstart(HelloWorld())
+1关于Julien Palard关于不使用CGI的说法,这确实很慢而且效率很低。 独立运行服务器并使用Apache代理服务器的另一种方法是使用mod_wsgi,它允许您在Apache进程内部运行Python进程。 大多数Web框架(Django,Bottle,Flask,CherryPy,web2py等)都可以很好地工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.