2014-09-04 41 views
0

我試圖在ubuntu上運行Apache上的燒瓶應用程序。 我得到在瀏覽器這個錯誤:在apache上運行python flask webapp

Internal Server Error 

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application. 

的Apache日誌不表示任何錯誤eventhough的日誌級別爲調試。 我WSGI文件看起來像:

import sys 
sys.path.insert(0, '/var/www/myflask/') 
from run import app as application 

我也試過:

from appimport app as application 

沒有任何的運氣。 如果我改變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] 

然後它工作。 另外,如果我在python控制檯中運行我的wsgi的3行,它不會拋出任何異常。 我可以用它自己的獨立的服務器就好了,如下運行應用程序一個run.py SCRPT:

from flask import Flask 
app = Flask(__name__) 
from app import app 
if __name__ == "__main__": 
    app.run(host='0.0.0.0', port=5000) 

這裏是文件系統:

├── app 
│   ├── db_access.py 
│   ├── db_access.pyc 
│   ├── __init__.py 
│   ├── __init__.pyc 
│   ├── static 
│   ├── templates 
│   │   └── index.html 
│   ├── views.py 
│   └── views.pyc 
├── __init__.py 
├── __init__.pyc 
├── myapp.wsgi 
├── requirements.txt 
├── run.py 
├── run.pyc 

任何想法如何使它運行阿帕奇? 我已經閱讀: http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/

http://fosshelp.blogspot.in/2014/03/how-to-deploy-flask-application-with.html

+1

當需要與「python app.py」不同的東西時,我遇到了幾個運行Python腳本的問題。然後我想出了一個Python軟件應該是什麼樣子,並創建了一個名爲Machete的工具(https://pypi.python.org/pypi/machete/)。你可以嘗試一下,創建一個空的(但可運行的)燒瓶應用程序,然後嘗試與你的Apache配置集成......它可能工作。 Python軟件結構有點棘手。 – Lovato 2014-09-05 13:09:42

回答

0

我設法得到它的工作。 我沒有針對wsgi中的run.py,而是針對具有路由標記的views.py。 另一個問題是,我的sqlite數據庫沒有適當的權限,導致應用程序失敗,但你不會得到任何錯誤。 要查看錯誤,我不得不添加:

WSGIRestrictStdout Off 

到 /etc/apache2/sites-available/mydomain.com 的頂部,並添加

sys.stdout = sys.stderr 

我WSGI並添加例外使用python打印命令處理。

+0

如果你必須這樣做stdout,你使用的是一個古老的mod_wsgi版本。你應該真的升級。請參閱http://blog.dscpl.com.au/2009/04/wsgi-and-printing-to-standard-output.html和http://blog.dscpl.com.au/2014/09/debugging-with -pdb-當-使用-modwsgi.html – 2014-09-05 23:24:20