uWSGI + Django 配置

基本配置:

# mysite_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /path/to/your/project
# Django's wsgi file
module          = project.wsgi
# the virtualenv (full path)
home            = /path/to/virtualenv

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 10
# the socket (use the full path to be safe
socket          = /path/to/your/project/mysite.sock
# ... with appropriate permissions - may be needed
# chmod-socket    = 664
# clear environment on exit
vacuum          = true

擴展配置:

# set an environment variable
env = DJANGO_SETTINGS_MODULE=mysite.settings

# create a pidfile
safe-pidfile = /tmp/project-master.pid

# respawn processes taking more than 20 seconds
harakiri = 20

# limit the project to 128 MB
limit-as = 128

# respawn processes after serving 5000 requests
max-requests = 5000

# background the process & log
daemonize = /var/log/uwsgi/yourproject.log
[uwsgi]

chdir = /path/to/your/project
module = project.wsgi
http-socket = :5000
master = true
harakiri = 20  # respawn processes taking more than 20 seconds
max-requests = 5000  # respawn processes after serving 5000 requests
chmod-socket=664  # django 配置
vacuum = true

# uwsgi默認的頂戴隊列, linux的默認限制是128, 查看 cat /proc/sys/net/core/somaxconn
# listen = 100

# 彈性調整打開的 worker 數目
cheaper-algo = spare2
cheaper = 2           # tries to keep 8 idle workers
cheaper-initial = 4   # starts with minimal workers
cheaper-step = 1      # spawn at most 4 workers at once
cheaper-idle = 60     # cheap one worker per minute while idle
workers = 8           # maximum number of workers
# processes = 4
# threads = 2

stats = :6000
stats-http = true
# log-maxsize = 10000000
logto = http_uwsgi.log
log-slow = 3000  # 記錄滿於 3000 毫秒的請求
log-format = %(addr) - %(user) [%(ltime)] "%(method) %(uri) %(proto)" %(status) %(size) "%(referer)" "%(uagent)"
# disable-logging = true

# https://uwsgi-docs-zh.readthedocs.io/zh_CN/latest/articles/TheArtOfGracefulReloading.html
# reload uWSGI if the specified file is modified/touched
# touch-reload 和 preforking組合,uwsgi 默認的優雅重載(熱啓動)
touch-reload = uwsgi.ini

# lazy-apps and touch-workers-reload,優雅重載的另一個模式
# lazy-apps = true
# 重載 workder
# touch-workers-reload = uwsgi.ini
# 鏈式重載
# touch-chain-reload = uwsgi.ini

py-autoreload = 1  # 自動重載,開發時非常方便

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章