Python/WSGI应用快速入门

Python/WSGI应用快速入门
centos7安装uWSGI以及Python支持
apt-get install build-essential python-dev
pip3 install uwsgi
yum search python | grep -i devel#找到对应安装依赖包
pip install
yum install python36-devel.x86_64
pip install uWSGI
yum unstall python-devel
yum uninstall python-devel
yum -y install python34-devel.x86_64
pip install uWSGI


from django.core.wsgi import get_wsgi_application#用于与UWSGI服务器通信的py
部署静态文件
在部署服务器之前,需要先将Django的静态文件部署到静态文件夹中,首先,编辑django网站的settings.py文件
     
    STATIC_ROOT = os.path.join(BASE_DIR, "static/")
然后,运行以下命令  
    python manage.py collectstatic


一些参数含义
chdir 项目目录
home virtualenv目录(如没有运行virtualenv虚拟环境,则无需设置)
wsgi-file=xx
socket 套接字文件或TCP套接字,例如:site1.uwsgi.sock 或 127.0.0.1:8000
uid 用户id
gid 用户组id
#主进程
master = true
#多站模式
#vhost = true
#多站模式时不设置入口模块和文件
no-site = true
#子进程数
workers = 2
processes 工作进程数
harakiri 进程超过该时间未响应就重启该进程(默认单位为秒)
module 要启动的wsgi模块入口,如:mysite.wsgi:application
ini 指定ini配置文件
xml 指定xml配置文件(与ini类似)
file 指定要运行的wsgi程序文件,如:test.py
emperor Emperor模式
so-keepalive 开启TCP KEEPALIVE(unix套接字方式下无效)
vacuum 退出时清空环境
reload-mercy = 10
#退出、重启时清理文件
vacuum = true
max-requests = 100
##最大请求数
limit-as = 2048
#设置用于uwsgi包解析的内部缓存区大小为64k。默认是4k。
buffer-size = 32768
# 请求超时时间
harakiri = 30
pidfile =xxx
#脚本启动、停止该进程

[uwsgi]
#  enable master process
master = true
# load apps in each worker instead of the master
lazy-apps = true

# disable request logging
disable-logging = true

# spawn the specified number of workers/processes
#  # 进程数 同workers
processes = 16
# a shortcut enabling gevent loop engine with the specified number of async cores and optimal parameters
# 这个要研究
gevent = 1024
# set the socket listen queue size 并发配置,配合设置 net.core.somaxcon = 1024
listen = 8192
# reload workers after the specified amount of managed requests
# 当worker达到指定数量的链接,就reload
max-requests = 50000
#  set the maximum time (in seconds) a worker can take to reload/shutdown (default is 60)
#  worker关闭或reload的时间,有仲情况是,worker关闭要太长时间了,导致一直关不掉
worker-reload-mercy = 10
#Set the max size of a request (request-body excluded), this generally maps to the size of request headers.  设置requset大小,不包括request body,
#一般指request的header,cookie,请求参数
buffer-size = 8192

# setuid to the specified user/uid
uid = nobody
#setgid to the specified group/gid
gid = nogroup
# set environment variable
env = PYTHON_EGG_CACHE=/tmp
env = PYTHONPATH=/home/project/nemu-server-src/env/local/lib/python2.7/site-packages/appinsight/
env = AGENT_CONFIG_FILE=/home/project/nemu-api/etc/config.ini
# set default WSGI callable name
# wsgi、module:  load a WSGI module 配合一起看
# wsgi-file、file:load .wsgi file
callable = app

socket = /tmp/nemu-api.sock  # 监听的socker
#  set PYTHONHOME/virtualenv
# 同virtualenv、pyhome
venv = /home/project/nemu-server-src/env
# load .wsgi file
wsgi-file = /home/project/nemu-api/app.py
daemonize = /home/project/nemu-api/logs/uwsgi.log
touch-reload = /home/project/nemu-api/app.py  # reload an instance touch 这个文件就会触发reload
# 修改进程名的
auto-procname = true
procname-prefix-spaced = nemu-api


[uwsgi]
chdir = /home/ymserver/vhost/owan-web
module = config.wsgi
workers = 8
max-requests = 5000000
disable-logging = True
virtualenv = /home/ymserver/.virtualenvs/owan-web_env
touch-reload = /home/ymserver/vhost/owan-web/reload
reload-on-rss = 512

master = True
vacuum = True

socket = /tmp/%n.sock
uid = www-data
gid = ymserver
umask=002
logto = /data/log/uwsgi/%n.log
logfile-chown=www-data:ymserver
logfile-chmod=664

扫描二维码关注公众号,回复: 5660093 查看本文章

# 如果你想维持 Python 的线程支持同时应用又不启动多个线程,只需要加上 --enable-threads 选项
enable-threads = True

# http://uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html
# 启用了多线程模式后,但自动开启线程支持,因此上面的  enabled-threads 不用设置
threads = 40
# 惊群效应
#http://uwsgi-docs-zh.readthedocs.io/zh_CN/latest/articles/SerializingAccept.html
thunder-lock = true

猜你喜欢

转载自blog.csdn.net/qq_15551663/article/details/88798806
今日推荐