2014-09-23 54 views
1

我跟着Linode guide設置了Flask應用程序的UWSGI,並且一切似乎都沒有問題,直到我嘗試將我的應用程序而不是示例之一,當我得到「uWSGI Error Python應用程序未找到」。UWSGI燒瓶:沒有找到Python應用程序

我的文件中/srv/www/xxx.com/xxx/結構爲:

app/ 
    __init__.py 
uwsgi.py 

__init__.py文件具有線運行的應用程序:

if __name__ == '__main__': 
    app.run() 

而且uwsgi.py導入應用程序:

#!flask/bin/python 

from app import app 

if __name__ == "__main__": 
    app.run(debug = False) 

當我手動嘗試運行python uwsgi.py該應用程序似乎工作,所以沒有錯誤或錯誤的進口。如果我改變uwsgi.py的內容是這樣的(來自例子):

import os 
import sys 

sys.path.append('/srv/www/example.com/application') 

os.environ['PYTHON_EGG_CACHE'] = '/srv/www/example.com/.python-egg' 

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] 

的應用程序似乎運行,所以UWSGI和nginx的工作正常運行的uwsgi.py文件,而不是當我把它指向我的應用程序

我uwsgi配置:

<uwsgi> 
    <plugin>python</plugin> 
    <socket>/run/uwsgi/app/xxx.com/xxx.com.socket</socket> 
    <pythonpath>/srv/www/xxx.com/application/xxx/</pythonpath> 
    <app mountpoint="/"> 

     <script>uwsgi</script> 

    </app> 
    <master/> 
    <processes>4</processes> 
    <harakiri>60</harakiri> 
    <reload-mercy>8</reload-mercy> 
    <cpu-affinity>1</cpu-affinity> 
    <stats>/tmp/stats.socket</stats> 
    <max-requests>2000</max-requests> 
    <limit-as>512</limit-as> 
    <reload-on-as>256</reload-on-as> 
    <reload-on-rss>192</reload-on-rss> 
    <no-orphans/> 
    <vacuum/> 
</uwsgi> 

我的nginx的配置:

server { 
     listen   80; 
     server_name  $hostname; 
     access_log /srv/www/xxx.com/logs/access.log; 
     error_log /srv/www/xxx.com/logs/error.log; 

     location/{ 
      uwsgi_pass  unix:///run/uwsgi/app/xxx.com/xxx.com.socket; 
      include   uwsgi_params; 
      uwsgi_param  UWSGI_SCHEME $scheme; 
      uwsgi_param  SERVER_SOFTWARE nginx/$nginx_version; 

     } 

     location /static { 
      root /srv/www/xxx.com/public_html/static/; 
      index index.html index.htm; 

     } 

} 

這是uwsgi錯誤日誌:

added /srv/www/xxx.com/application/xxx/ to pythonpath. 
- unable to load app 0 (mountpoint='/') (callable not found or import error) 
- *** no app loaded. going in full dynamic mode *** 
- *** uWSGI is running in multiple interpreter mode *** 
- spawned uWSGI master process (pid: 21982) 
- spawned uWSGI worker 1 (pid: 21990, cores: 1) 
- set cpu affinity for worker 1 toTue Sep 23 16:51:19 2014 - 0Tue Sep 23 16:51:19 2014 - 
- spawned uWSGI worker 2 (pid: 21991, cores: 1) 
- *** Stats server enabled on /tmp/stats.socket fd: 14 *** 
- set cpu affinity for worker 2 toTue Sep 23 16:51:19 2014 - 0Tue Sep 23 16:51:19 2014 - 

任何人都可以指向我我正在哪裏錯誤?我花了幾個小時嘗試各種解決方案,但似乎沒有任何工作,我必須省略一些重要的東西,但找不到它。

回答

1

嘗試加入<callable>application</callable>

+0

仍然一樣。爲了以防萬一,使用'application'和'app'試用。 – 2014-09-23 17:42:05

+1

哇,我設法做到了,我加了'應用程序'以及'應用程序',它的工作原理。有人知道爲什麼這是原因,以及爲什麼這個東西必須用這種方式來定義? – 2014-09-23 18:49:31

+0

uWSGI查找可調用的名爲'application'的應用程序。如果你把它稱爲別的東西,它需要知道名字是什麼。 – dirn 2014-09-23 21:52:25