喜欢git,希望通过github的单个仓库作为Blog来记录新路历程。世上并没有路,走的人多了罢了。
OS: Centos7
Python: 2.7.5(Centos7预装)
yum -y install gcc gcc-c++ ncurses-devel zlib zlib-devel openssl openssl--devel pcre pcre-devel
yum install python-devel ==> uwsgi
django=1.11.1
nginx=1.12.2
uWSGI=2.0.17
官方文档: https://uwsgi-docs.readthedocs.io/en/latest/Management.html
[uwsgi]
chdir=/var/www/project/www.wangda/wangda/
# uid=www-data
# gid=www-data
pythonpath=/usr/bin/python2.7
wsgi-file = wangda/wangda/wsgi.py
socket = 127.0.0.1:9090
protocol=http
master=true
workers=5
pidfile=/var/www/project/www.wangda/wangda/uwsgi.pid
vacuum=true
thunder-lock=true
enable-threads=true
harakiri=30
post-buffering=4096
daemonize=/var/www/project/www.wangda/wangda/uwsgi.log
env = LANG=en_US.UTF-8
如果uwsgi错误中提示:
*** Operational MODE: preforking ***
ImportError: No module named {{wangda}}.wsgi
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
chdir 为project目录
--wsgi-file 对应project下的同名目录,再下面是wsgi.py,否则系统无法import
重新reload uwsgi
server {
listen 80;
server_name api.hixinma.top;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /var/www/project/www.wangda/wangda; # 项目根目录
include uwsgi_params;
proxy_pass http://127.0.0.1:9090/; # 同uwsgi中配置开启的端口
index index.html index.htm;
client_max_body_size 35m;
}
error_log /usr/local/nginx/logs/error.log error;
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
我在调试nginx error.log 之初看不到详细的调试错误信息. 这需要使用源码包安装nginx,要激活 debug 日志,Nginx 在构建时需要配置为支持 debug:
./configure --with-debug ...
然后在 server 层面上重新指定的日志将会禁用这台服务器的 debug 日志:
http {
server {
error_log /path/to/log;
...
为了避免这种现象的发生,要么你就注释掉重新定义的那行日志,要么你就在那行也加上 debug 级别:
error_log /path/to/log debug;
django 直接返回序列化json列表数据,需要借助于第三方插件。
url:https://github.com/bluedazzle/django-simple-serializer
运行需求
Python 2:
Django >= 1.5
Python >= 2.6
Python 3:
Django >= 1.8
Python >= 3
安装:
pip install django-simple-serializer