要把自己的博客放到服务器上,代码是从github上pull下来的,一切就绪后,最后重启uwsgi,提示fail
(venv) root@iZ11anup6kpZ:/tmp# service nginx restart
* Restarting nginx nginx [ OK ]
(venv) root@iZ11anup6kpZ:/tmp# service uwsgi restart
* Restarting app server(s) uwsgi [fail]
看了下 uwsgi的log,显示如下
Tue Aug 9 23:55:21 2016 - *** Starting uWSGI 1.9.17.1-debian (64bit) on [Tue Aug 9 23:55:21 2016] ***
Tue Aug 9 23:55:21 2016 - compiled with version: 4.8.2 on 23 March 2014 17:15:32
Tue Aug 9 23:55:21 2016 - os: Linux-3.13.0-65-generic #106-Ubuntu SMP Fri Oct 2 22:08:27 UTC 2015
Tue Aug 9 23:55:21 2016 - nodename: iZ11anup6kpZ
Tue Aug 9 23:55:21 2016 - machine: x86_64
Tue Aug 9 23:55:21 2016 - clock source: unix
Tue Aug 9 23:55:21 2016 - pcre jit disabled
Tue Aug 9 23:55:21 2016 - detected number of CPU cores: 1
Tue Aug 9 23:55:21 2016 - current working directory: /
Tue Aug 9 23:55:21 2016 - writing pidfile to /run/uwsgi/app/myblog/pid
Tue Aug 9 23:55:21 2016 - detected binary path: /usr/bin/uwsgi-core
Tue Aug 9 23:55:21 2016 - setgid() to 33
Tue Aug 9 23:55:21 2016 - setuid() to 33
Tue Aug 9 23:55:21 2016 - your processes number limit is 15834
Tue Aug 9 23:55:21 2016 - your memory page size is 4096 bytes
Tue Aug 9 23:55:21 2016 - detected max file descriptor number: 65535
Tue Aug 9 23:55:21 2016 - VirtualHosting mode enabled.
Tue Aug 9 23:55:21 2016 - lock engine: pthread robust mutexes
Tue Aug 9 23:55:21 2016 - thunder lock: disabled (you can enable it with --thunder-lock)
Tue Aug 9 23:55:21 2016 - uwsgi socket 0 bound to UNIX address /run/uwsgi/app/myblog/socket fd 3
Tue Aug 9 23:55:21 2016 - uwsgi socket 1 bound to UNIX address /tmp/myblog.sock fd 5
Tue Aug 9 23:55:21 2016 - Python version: 2.7.6 (default, Jun 22 2015, 18:01:27) [GCC 4.8.2]
Tue Aug 9 23:55:21 2016 - Set PythonHome to /var/www/myblog/venv
ImportError: No module named site
我的程序结构如下
├── app
│ ├── auth
│ │ ├── forms.py
│ │ ├── __init__.py
│ │ └── views.py
│ ├── __init__.py
│ ├── main
│ │ ├── errors.py
│ │ ├── forms.py
│ │ ├── __init__.py
│ │ └── views.py
│ ├── models.py
│ ├── static
│ │ ├── css
│ │ │ ├── github-markdown.css
│ │ │ ├── materialize.css
│ │ │ └── materialize.min.css
│ │ ├── img
│ │ │ ├── favicon.ico
│ │ │ └── zilaiye.jpg
│ │ └── js
│ │ ├── jquery-3.1.0.js
│ │ ├── jquery-3.1.0.min.js
│ │ ├── materialize.js
│ │ └── materialize.min.js
│ └── templates
│ ├── 404.html
│ ├── 500.html
│ ├── auth
│ │ └── login.html
│ ├── base.html
│ ├── edit_post.html
│ ├── index.html
│ ├── post_detail.html
│ └── tweet.html
├── config.py
├── manage.py
├── requirements.txt
├── tests
│ ├── test-basic.py
│ └── test_user_model.py
└── venv
nginx配置文件如下
server {
listen 80;
server_tokens off;
server_name zhaoyongbiao.me www.zhaoyongbiao.me;
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/myblog.sock;
}
location /static {
alias /var/www/myblog/app/static;
}
## Only requests to our Host are allowed
if ($host !~ ^(zhaoyongbiao.me|www.zhaoyongbiao.me)$ ) {
return 444;
}
}
uwsgi配置如下
[uwsgi]
vhost = true
socket = /tmp/myblog.sock
venv = /var/www/myblog/venv
chdir = /var/www/myblog
module = manage.py
callable = app
flask启动文件 manage.py
import os
from app import create_app, db
from app.models import User, Post, Tweet
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand
app = create_app(os.getenv('CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)
def make_shell_context():
return dict(app=app, db=db, User=User, Post=Post, Tweet=Tweet)
@manager.command
def test():
"""Run the unit test"""
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
manager.add_command('shell', Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)
if __name__ == '__main__':
manager.run()
不知道到底是哪里出了问题(程序在本地是没问题的)
virtualenv配uwsgi,要填坑无数;建议改成Gunicorn(Flask官方推荐的!),保你一路顺风,延年益寿。说Gunicorn比uwsgi慢的主,都已经在填坑的过程中,顺便把自己埋了。