在Heroku上运行Python CGI应用程序 [英] Run Python CGI Application on Heroku

查看:124
本文介绍了在Heroku上运行Python CGI应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个使用Python CGI脚本的简单应用程序。我有一个工作的本地版本(使用lighttpd可以正常工作),但现在我想将它上传到Heroku。该应用程序由2或3个脚本组成,这些脚本可以对文件进行操作并将信息打印回浏览器,所以我不认为我需要CGI以外的其他模块。



但是, Heroku文档只解释了如何上传Python应用程序和花哨的web框架,而我没有使用任何



我想知道是否有可能在Heroku上运行CGI脚本,如果可以,怎么做。


<解决方案Heroku Cedar围绕自托管Web应用程序,因此您需要能够将应用程序捆绑在一起并将其作为单个命令运行。

我认为最简单的方法是将您的应用程序移植到Flask。它不是很复杂,特别是如果它只有2或3个脚本。



另一个选项(取决于您的性能要求)将使用简单的 Python标准库中的CGI服务器 Python buildpack 。我认为你需要将你的脚本捆绑在一个./cgi-bin目录中,并用以下命令启动服务器(在proc文件中):

  web:bin / python -m CGIHTTPServer $ PORT 

最复杂的方法是捆绑lighttpd和你的脚本一起写出一个shell脚本来启动它。你将不得不确保你编译的二进制文件与Heroku兼容。我将以 PHP构建包为出发点。


I made a simple application that makes use of Python CGI scripts. I have a working local version (works fine with lighttpd), but now I'd like to upload it to Heroku. The application consists of 2 or 3 scripts that make operations on a file and print information back to the browser, so I don't think I'll need any module other than CGI.

But the Heroku documentation only explains how to upload Python applications with fancy web frameworks, and I'm not using any of those.

I want to know if it's possible to run CGI scripts on Heroku, and if so, how to do it.

解决方案

Heroku Cedar is centered around self-hosting web applications, so you need to be able to bundle your application together and run it as a single command.

I think the easiest way would be to port your application to Flask. It isn't very complicated, especially if it is only 2 or 3 scripts.

Another option (depending on your performance requirements) would be to use the simple CGI server in the Python standard library and the Python buildpack. I think you would need to bundle up your scripts in a ./cgi-bin directory and start the server (in the procfile) with:

 web: bin/python -m CGIHTTPServer $PORT

The most complex way would be to bundle lighttpd and your scripts together and write a shell script to start it all up. You would have to make sure your compiled binaries are compatible with Heroku. I would look at the PHP buildpack as a starting point.

这篇关于在Heroku上运行Python CGI应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆