【发布时间】:2016-12-19 01:44:35
【问题描述】:
我试图通过 WSGI 在我的 apache Amazon EC2 服务器上运行一个瓶子应用程序,但我不断收到此错误:
[Fri Aug 12 06:15:13 2016] [error] [client 72.219.147.5] File "/var/www/html/website/app.wsgi", line 5, in <module>
[Fri Aug 12 06:15:13 2016] [error] [client 72.219.147.5] import bottle
[Fri Aug 12 06:15:13 2016] [error] [client 72.219.147.5] ImportError: No module named bottle
当我安装 mod_wsgi 时,使用了这个:
mod_wsgi-python26-3.2-6.11.amzn1.x86_64
这是我的 app.wsgi 文件
import os, sys
sys.path.insert(0, "/var/www/html/website")
import bottle
import app
application = bottle.default_app()
这是我的 httpd.conf:
WSGISocketPrefix /var/run/wsgi
<VirtualHost *>
ServerName website.website.me
DocumentRoot /var/www/html/website
WSGIDaemonProcess website threads=5
WSGIScriptAlias / /var/www/html/website/app.wsgi
<Directory "/var/www/html/website">
WSGIProcessGroup website
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
这是 WSGI 的版本(来自我的错误日志):
[Fri Aug 12 06:15:11 2016] [notice] Apache/2.2.31 (Unix) DAV/2 PHP/5.3.29 mod_wsgi/3.2 Python/2.6.9 configured -- resuming normal operations
但如果我运行python -V,我会得到Python 2.7.10。
我也知道瓶子安装正确,因为当我执行以下操作时,没有错误:
$ python
>>>import bottle #no import error
>>>
更新:
我尝试进行“hello world”测试以查看 wsgi 是否正常工作:
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
它成功了,所以问题不是 WSGI。
这是我的 app.py 文件中的内容:
from bottle import route, run, template, static_file, request
import main
template = """<html>
<head><title>Home</title></head>
<body>
<h1>Upload a file</h1>
<form action="/upload" method="post" enctype="multipart/form-data">
Category: <input type="text" name="category" />
Select a file: <input type="file" name="upload1" />
Select a file: <input type="file" name="upload2" />
<input type="submit" value="Start upload" />
</form>
</body>
</html>"""
@route('/')
def index():
return template
如果我执行python app.py,则没有错误。就是在我刷新 website.website.me 的时候出现 500 错误。
感谢任何帮助。
【问题讨论】:
-
可能你没有文件夹权限
-
哪个文件夹? @Raskayu
-
bottle.py文件在哪里?从 shell 运行python时获得的 Python 环境可能与网络服务器创建的环境不同。
标签: python apache amazon-web-services amazon-ec2 bottle