2

这是我的设置:

/etc/nginx/conf.d/mysite.conf

server {
    listen       80;
    server_name mysite.com;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/mysite.sock;
        uwsgi_param UWSGI_PYHOME /srv/www/mysite/env;
        uwsgi_param UWSGI_CHDIR /srv/www/mysite;
        uwsgi_param UWSGI_MODULE app;
        uwsgi_param UWSGI_CALLABLE app;
    }
}

/etc/init/uwsgi.conf

description "uWSGI"
start on runlevel [2345]
stop on runlevel [06]

respawn

exec uwsgi --ini /etc/uwsgi/emperor.ini

/etc/uwsgi/emperor.ini

[uwsgi]
emperor = /etc/uwsgi/vassals
uid = uwsgi
gid = nginx
logto = /var/log/uwsgi/emperor.log

/etc/uwsgi/vassals/mysite.ini

[uwsgi]
protocol = uwsgi
max-requests = 5000
chmod-socket = 660
master = True
vacuum = True
venv = /srv/www/mysite/env
socket = /tmp/mysite.sock
logto = /var/log/uwsgi/mysite.log

/srv/www/mysite/app.py

from flask import Flask
from redis import Redis

app = Flask(__name__)

# Test Redis
@app.route('/test')
def test():
    redis = Redis()
    mykey = redis.get('mykey')
    return mykey

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

/var/log/uwsgi/mysite.log

Traceback (most recent call last):
  File "/srv/www/mysite/app.py", line 2, in <module>
    from redis import Redis
ImportError: No module named redis
unable to load app 0 (mountpoint='') (callable not found or import error)
--- no python application found, check your startup logs for errors ---
[pid: 2517|app: -1|req: -1/5] 71.202.185.125 () {48 vars in 813 bytes} [Wed Jul  3 18:17:08 2013] GET /demo/check => generated 21 bytes in 14 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0)
Traceback (most recent call last):
  File "/srv/www/mysite/app.py", line 2, in <module>
    from redis import Redis
ImportError: No module named redis
unable to load app 0 (mountpoint='') (callable not found or import error)
--- no python application found, check your startup logs for errors ---
[pid: 2517|app: -1|req: -1/6] 71.202.185.125 () {46 vars in 724 bytes} [Wed Jul  3 18:17:08 2013] GET /favicon.ico => generated 21 bytes in 14 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0)
4

0 回答 0