简体   繁体   English

EC2 python 文件未显示 html

[英]EC2 python file not showing html

I am installing django for my EC2 instance,我正在为我的 EC2 实例安装 django,

but before I wanted to do this simple test: i created a file in the instance with the web command line tool但在我想做这个简单的测试之前:我使用 web 命令行工具在实例中创建了一个文件

hello.py:你好.py:

#!/usr/bin/python2.6
print "Content-Type: text/html" 
print 
print """\ 
<html> 
<body> 
<h2>Hello World!</h2> 
</body> 
</html>
"""

and change permissions to execute,并更改执行权限,

but when I go to my page但是当我 go 到我的页面时

http://ec2-107-20-20-19.compute-1.amazonaws.com/hole.py

I see the same as the code, not the actual HTML,我看到的和代码一样,不是实际的HTML,

but if i do it in other server i actually she the Hello World!但如果我在其他服务器上这样做,我实际上是她的Hello World! message信息

so what im I missing in my EC2 instance to be able to see the python files?那么我在我的 EC2 实例中缺少什么能够看到 python 文件?

where is the cgi folder? cgi文件夹在哪里? how to create it in my root folder?如何在我的根文件夹中创建它?

thanks!谢谢!

You should use mod_wsgi with Apache 2 or Gunicorn or uWSGI with Nginx (or another web server) to serve Python web applications.您应该将mod_wsgiApache 2GunicornuWSGINginx (或另一个 web 服务器)一起使用来服务 Python web 应用程序。 Simply putting a .py file somewhere inside your web server's document root won't do what you want, since the web server won't know that it is a script, nor how to execute it (unless you configure CGI appropriately).简单地将.py文件放在 web 服务器的文档根目录中的某处不会执行您想要的操作,因为 web 服务器不知道它是一个脚本,也不知道如何执行它(除非您适当地配置 CGI)。

WSGI has many advantages over CGI: your application code is loaded once and re-used, rather than re-loaded for each web request; WSGI 相对于 CGI 有很多优势:你的应用程序代码被加载一次并重新使用,而不是为每个 web 请求重新加载; it can be run as a different user than the web server, helping to avoid security issues;它可以作为与 web 服务器不同的用户运行,有助于避免安全问题; it has framework support from lots of Python code and frameworks (including Django);它有许多 Python 代码和框架(包括 Django)的框架支持; etc.等等

For more on configuring your Django application for WSGI deployment, see the Django deployment docs .有关为 WSGI 部署配置 Django 应用程序的更多信息,请参阅Django 部署文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM