uwsgi基礎——參數


 
不需要全部看完,一半看不懂。看下去也沒有意思。

uWSGI Documentation (1.0選項列表)

這里包含很大一部分(是的,不是全部,請幫助提升文檔,而不是抱怨。。。)uwsgi選項,沒有特定順序(即使你會發現很多重要的在上面)。每個選項都支持所有的配置方法(命令行參數,環境變量,xml,ini,yaml和LDAP)。很多選項需要和加載插件,在這種情況插件名字會在文檔里提到。

例子使用了多種風格了配置,為了讓用戶更好的理解uwsgi的工作。

如果你剛使用uwsgi,你要在真正有用的配置嚇到你之前看一下 Quickstart  和 Examples 。

配置風格的簡單介紹

在遷移一種配置文件的時候,依照下面的規則:

命令行參數:  --  為前綴

socket會是:

--socket <path/address>

環境變量: 選項名大寫,前綴UWSGI_。所有的破折號(dashes  -)都替換為下划線(underscore_).

max-vars 選項變為

UWSGI_MAX_VARS="<n>"

xml: root 節點必須是 <uwsgi> ,所有的選項都是文本節點。參數工作標識可以沒有值。

socket and master options became

<uwsgi>
    <socket>127.0.0.1:3031</socket>
    <master/>
</uwsgi>

ini: 配置選擇為 uwsgi, 配置可工作設置成true或1。

socket and master options became

[uwsgi]
socket = 127.0.0.1:3031
master = true

yaml: root 元素必須是 uwsgi, 配置工作可以設置為true或1.

socket and master options became

uwsgi:
  socket: 127.0.0.1
  master: 1

ldap: 非常復雜的話題,你可以查查專用的wiki頁面。see useLDAP

 

無窮的選項…

現在開始,深呼吸。

 

socket or uwsgi-socket

指定路徑,你可以指定8個socket選項,命令行可以使用 '-s'簡寫

--socket /tmp/uwsgi.sock

will bind to the unix socket /tmp/uwsgi.sock

-s 127.0.0.1:1717

will bind to ipv4 address 127.0.0.1 on port 1717

[uwsgi]
socket = 127.0.0.1:1717
socket = 127.0.0.1:2626

will bind to ipv4 address 127.0.0.1 on port 1717 and ipv4 address 127.0.0.1 on port 2626

protocol

設置默認的通訊協議(uwsgi, http, fastcgi)

--protocol <protocol>

processes or workers

在preforking模式下worker進程個數。這是一個安全實現並發。添加多個workers,可以管理多個並行請求。每個worker相當於一個系統進程,所以它消耗內存,小心選擇正確的數目。這個值太高會很容易讓系統down機。

命令行中簡寫成 -p

--processes 8

will spawn 8 workers

--workers 4

will spawn 4 workers

-p 8

will spawn 8 workers

<uwsgi>
    <workers>3</workers>
</uwsgi>

will spawn 3 workers

chown-socket

UNDOCUMENTED

harakiri

設置“harakiri ”的超時(看主頁可以得到更多幫助)。每個請求在超過指定的“harakiri”超時的s數會被移除,對應的worker會被回收。

--harakiri 60

會殺死每個超過60s的請求。

harakiri-verbose

當一個請求是“harakiri”殺死的,會記錄信息到uwsgi日志里。打開這個選項會輸出額外的信息(例如列出當前的系統調用)

--harakiri-verbose

在 aharakiri 的時候打開額外信息。

spooler-harakiri

set the harakiri mode for spooler tasks

--spooler-harakiri <n> option

mule-harakiri

set the harakiri mode for mule processes

--mule-harakiri <n>

xmlconfig or xml

加載xml配置文件,命令行中可簡寫成 -x 。根據屬性得到不同的配置。選擇節點,在文件后指定它的id(使用莫冒號(colon )作為分隔符)

--xml /etc/myapp.xml

will load the /etc/myapp.xml config file

--xml /etc/myapp.xml:django

will use the uwsgi 節點來標記 as 'django' in the /etc/myapp.xml config file

This file can be something like this:

<all_the_apps>

  <uwsgi id="turbogears">
    <socket>/tmp/tg.sock</socket>
  </uwsgi>

  <uwsgi id="django">
    <socket>/tmp/django.sock>
  </uwsgi>

</all_the_apps>

這個例子里你可以隨便添加root節點。

在文件名以.xml結尾時,隱式加上。

/usr/bin/uwsgi /etc/myapp.xml

will automatically load the /etc/myapp.xml config file

set

set a placeholder

--set KEY=VALUE

daemonize(守護進程)

進程后台運行使用的log文件或者udp服務器。

--daemonize /var/log/uwsgi.log

will damonize uWSGI writing log messages to /var/log/uwsgi.log

[uwsgi]
daemonize = 192.168.0.100:4000

will daemonize uWSGI sending logs the the udp server listening on address 192.168.0.100 port 4000 See UdpLogging

stop

sends a SIGINT to the pid written in <pidfile>

--stop <pidfile>

reload

sends a SIGHUP to the pid written in <pidfile>

--reload <pidfile>

listen

socket監聽隊列(默認100)。

每個socket有相應隊列讓請求等待隊列變為就緒狀態。當隊列滿了就會拒絕。

極大值以來系統內核。

max-vars

uwsgi的客戶端接收數量。這僅是一個安全的確保,你可能永遠不需要接觸它

buffer-size

uwsgi內部解析的數據包大小,默認4k。

如果准備接收大請求,你可以增長到64k。

--buffer-size 32768

允許uwsgi接收到32k,更大的會被丟棄。

memory-report

內存使用報告。會輸出請求日志相關的RSS和地址空間使用。

<uwsgi>
    <memory-report/>
</uwsgi>

cgi-mode

開啟cgi模式,響應不是http的有效響應,是cgi的形式(頭信息會被添加)

abstract-socket

chmod-socket or chmod

unix套接字是文件系統,必須遵守unix協議。如果你的webserver沒有能力訪問uwsgi socket,你可以設置sockets權限。

When used as a flag this option will set permissions to 666, otherwise the spcified scheme will be used

當設置的權限是666,否則指定的scheme 會被使用。

<uwsgi>
    <chmod-socket/>
</uwsgi>

will set socket permissions to 666

<uwsgi>
    <chmod-socket>644</chmod-socket>
</uwsgi>

will set socket permissions to 644

freebind (Linux only)

允許綁定不存在的網絡地址

map-socket

你可以一個uwsgi綁定多個sockets,你可以對應不同的請求映射不同的實現。

[uwsgi]
socket = /tmp/uwsgi0.sock
socket = /tmp/uwsgi1.sock
workers = 5
map-socket = 0:1,2,3
map-socket = 1:4,5

1,2,3號worker會轉發到第一個socket,4和5轉發到第二個來處理。

如果你部署多個apps在同一個uwsgi實例,你可以很容易的互相調度資源。

enable-threads

打開線程是內置語言,允許你在app里啟動線程。

single-interpreter

很多語言都有多重解釋器。它們可以讓一個相同進程隔離很多apps。如果不想用這個特性就是用這個屬性。

auto-procname

自動設置uwsgi進程的名字,讓它更有意義。

e.g. "uWSGI master", "uWSGI worker 1", "uWSGI worker 2"

procname-prefix

will prepend <value> to the process name

--procname-prefix <value>

procname-prefix-spaced

will append a space to the prefix, before prepending it to the process name

--procname-prefix-spaced <value>

procname-append

will append <value> to the process name

--procname-append <value>

procname

will set the process name to <value>

--procname <value>

procname-master

will set the master process name to <value>

--procname-master <value>

master

enable the master process

emperor

Start the uWSGI Emperor

emperor-tyrant

enable tyrant mode for the emperor. see tyrant

emperor-stats or emperor-stats-server

enable the uWSGI stats server for emperor mode. see stats server

--emperor-stats <addr>

early-emperor

start the emperor before jailing and privileges drop

emperor-broodlord

enable bloodlord mode for the emperor. see broodlord

emperor-amqp-vhost

set virtualhost name in AMQP emperor mode

emperor-amqp-username

set username name in AMQP emperor mode

emperor-amqp-password

set password name in AMQP emperor mode

emperor-throttle

set the number of milliseconds (default 1000) to wait before each vassal's fork()

vassals-start-hook

<filename> will be executed when the emperor starts the vassals

--vassals-start-hook <filename>

vassals-stop-hook

<filename> will be executed when the emperor stop the vassals

--vassals-stop-hook <filename>

auto-snapshot

UNKNOWN

--auto-snapshot 1

reload-mercy

設置worker在重載中等待的最大秒數。

--reload-mercy 8

在重載的8s內不終止自己。過了就會被殺。

exit-on-reload

強制uwsgi棧終止,即使是reload。在極個別的情況下使用

help or usage

print the help on the stdout then exit

reaper

打開reaper mode. 每個請求服務器都會調用waitpid(-1),來去掉所有的僵屍程序。

max-requests

每個worker的最大請求數。超過會回收。可以使用這個選項來避免內存泄露()

[uwsgi]

max-requests = 1000

會回收超過1000的請求。

socket-timeout

內部套接字超時時間. (default 4 seconds)

--socket-timeout 10

關閉內部10s不活動的鏈接。

locks

創建鎖來使用. see locks

--locks <n>

sharedarea

This enables the SharedArea. This is a low level shared memory. If you want a more usable/user-friendly system look at the CachingFramework

--sharedarea 10

will create a shared memory area of 10 pages

cache

Enable the shared cache. See CachingFramework

cache-blocksize

set the cache blocksize, default 65536 bytes. Better use a multiply of 4096.

cache-store

enable 持久存儲 for the uWSGI cache

cache-store-sync

set the msync() frequency for caching persistent store.

queue

UNDOCUMENTED

queue-blocksize

UNDOCUMENTED

queue-store

UNDOCUMENTED

queue-store-sync

UNDOCUMENTED

spooler

Enable the Spooler on the specified directory

[uwsgi]
spooler = /home/foo/spooler

will save spooler file in the /home/foo/spooler directory

spooler-chdir

allows you to define a <directory> in wich chdir() before each spooler task

--spooler-chdir <directory>

mule

add a mule process. See Mules

disable-logging

禁止request的日志,只顯示錯誤和uwsgi內部信息。

pidfile

write the pidfile to the specified file before privileges drop

pidfile2

write the pidfile to the specified file after privileges drop

chroot

chroot() 改變到指定目錄。

gid

set the gid under the uWSGI server will run

uid

set the uid under the uWSGI server will run

ini

path of ini config file

--ini <inifile>

yaml or yml

path of yaml config file

--yaml <yamlfile>

json

path of a json config file

the format follows the same rules of the other supported configuration system (plus integer, boolean and array support):

{

"uwsgi":  {
       "http": ":8080",
       "master": true,
       "module": "werkzeug.testapp:test_app",
       "workers": 8,
       "pythonpath":  [ "/foo", "/bar" ]
      }

} 

to use JSON support you need the jansson library by default the library presence will be auto-detected but you can force it editing buildconf/default.ini the Emperor has been extended to support .js files too

--json <jsonfile>

ldap

Load configuration fron an ldap server. See useLDAP

ldap-schema

dump the LDAP schema (old-style format)

ldap-schema-ldif

dump the LDAP schema in LDIF format (new openldap)

no-server

初始化uwsgi服務,但是初始化完成就退出了(用於測試)

no-defer-accept

by default (where available) uWSGI will defer the accept() of requests until some data is sent by the client (this is a security/performance measure). If you want to disable this feature specify this option.

limit-as

limit the 每個進程的地址空間使用,using POSIX/UNIX setrlimit()

--limit-as 256

will avoid uWSGI processes to grow over 256MB of address space. Address space is the virtual memory a process has access to. It does not correspond to physical memory.

避免進程內存使用到256MB,地址空間是虛擬內存。和物理內存不一致。

Read and understand this page before enabling it:  http://en.wikipedia.org/wiki/Virtual_memory

reload-on-as

recycle a workers when its address space usage is over the limit specified

--reload-on-as 128

will reload a worker if it consumes more than 128 megs of address space

reload-on-rss

Works as reload-on-as but it control the physical unshared memory. You can enable both

uwsgi:
  reload-on-as: 128
  reload-on-rss: 96

will recycle a workers when its address space usage is hgher than 128 megs or its rss usage is higher than 96 megs

evil-reload-on-as

the master process will reload a worker when its address space usage is higher than <n> megabyte

--evil-reload-on-as <n>

evil-reload-on-rss

same as evil-reload-on-as but it control the physical unshared memory

--evil-reload-on-rss <n>

log-x-forwarded-for

reports the correct client ip when uWSGI is run under multiple proxies

touch-reload

gracefully reload the uWSGI stack when a file/directory changes.

uwsgi:
  touch-reload: /tmp/reload.txt

if you

touch /tmp/reload.txt

the uWSGI server will be gracefully reloaded

limit-post

http請求的body大小。 It reads the CONTENT_LENGTH uwsgi variable to know the size

--limit-post 65536

will disallow request body higher than 64k

no-orphans

自動關閉沒有主進程的workers

prio

設置程序的調度優先級

<uwsgi>
    <prio>20</prio>
</uwsgi>

will set the process priority to 20 (the value is system dependent)

cpu-affinity

Set the CPU affinity (Linux Only) See  http://lists.unbit.it/pipermail/uwsgi/2011-March/001594.html

post-buffering

開啟body緩沖,uwsgi會將超過body限制大小的部分。

[uwsgi]
post-buffering = 8192

will save to disk all the HTTP body bigger than 8K. This option is required for Rack applications as they require a rewindable input stream.

post-buffering-bufsize

set the internal buffer size during post buffering (this is the memory allocated to read chunks of the socket stream)

post-buffering-bufsize 65536

設置64k為socket接收大小。128k的body兩次接收。

高級選項,用不着

upload-progress

Enable the embedded upload progress. You pass the name of a directory where uWSGI has write permissions. For every upload a JSON file will be written to this directory reporting the status of the upload. You can use ajax to read these files. So configure your webserver to allow access to that directory.

--upload-progress /var/www/progress

The user upload a file to the url

http://uwsgi.it/upload?X-Progress-ID=550e8400-e29b-41d4-a716-446655440000

uWSGI find the X-Progress-ID in the query string and create a file called

550e8400-e29b-41d4-a716-446655440000.js

in /var/www/progress with this kind of content

{ "state" : "uploading", "received" : 170000, "size" : 300000 }

Supposing you have mapped /progress to /var/www/progress in your webserver, you can get those json data via ajax pointing to

/progress/550e8400-e29b-41d4-a716-446655440000.js

probably your webserver has a very similar functionality, but if you need to hack it (or simply have more control) delegate this to the uWSGI server

no-default-app

By default, when uWSGI does not find a corresponding app for the specified SCRIPT_NAME variable, will use the default app (most of the time the app mounted under /). Enabling this option will return an error in case of unavailable app.

manage-script-name

If for some reason your webserver cannot manage SCRIPT_NAME you can force uWSGI to rebuild the PATH_INFO automatically.

udp

start a udp server. Mainly useful for snmp or as a shared logger for UdpLogging

multicast

internal option, usable by third party plugins.

cluster

Join the specified cluster. See Clustering

cluster-nodes

You can get the list of nodes in a cluster without joining it

--cluster-nodes 225.1.1.1:1717

will get the list of nodes of the 225.1.1.1:1717 cluster. This list is used internally by the uwsgi load balancing api.

cluster-reload

gracefully reload a whole cluster

--cluster 225.1.1.1:1717 --cluster-reload

will reload all the nodes in the 225.1.1.1:1717 cluster

cluster-log

log a message to all the nodes of a cluster

--cluster 225.1.1.1:1717 --cluster-log "Hello World"

will print "Hello World" to all the nodes logfiles

subscribe-to or st or subscribe

subscribe to a SubscriptionServer, you can subscribe to multiple server using this option multiple times

[uwsgi]
subscribe-to = 192.168.0.1:2626:unbit.it
subscribe-to = 192.168.0.2:2626:uwsgi.it

shared-socket

Advanced option for plugin writers or special needs. Allow to create a socket during server early startup and use it after privileges drop or jailing.

snmp

enable the SNMP server. See UseSnmp

snmp-community

set the snmp community string

check-interval

The master process make a scan every seconds. You can increase this time if you need. DISCOURAGED.

binary-path

If you do not have uWSGI in the system path you can force its path with this option to permit the reloading system and the Emperor to easily find the binary to execute.

async

Enable the async mode. See AsyncSupport

logto

Log to specific file or udp server

logfile-chown

log-syslog

輸出日志到系統日志

Passing a parameter makes uwsgi use the parameter as program-name in the syslog entry header:

--log-syslog mywebapp

log-master

delegate the write of the logs to the master process (this will put all of the logging I/O to a single process). Useful for system with advanced I/O schedulers/elevators

logdate or log-date

report the date in every log line. You can pass an option with strftime() syntax

log-zero

log requests with zero response size

log-slow

log-4xx

log-5xx

log-big

log-sendfile

log-micros

use microseconds resolution for response-time logging (milliseconds resolution is the default)

master-as-root

run the uWSGI master process as root

need-app

exit uwsgi if no app can be loaded

chdir

chdir() to specified directory before privileges drop

chdir2

chdir() to specified directory after privileges drop

lazy

load applications after each worker's fork()

cheap

postpone workers startup until the first request

cheaper

an advanced cheap mode, this will only spawn <n> workers on startup and will use various (pluggable) algorithms to implement adaptive process spawining.

--cheaper <n>

idle

destroy workers (the server will go in cheap mode) after <secs> of inactivity

--idle <secs>

mount

Allow mounting of multiple apps in the same process

--mount /pinax=/var/www/pinax/deploy/pinax.wsgi

grunt

allows grunt processes

threads

enable threaded operational mode. You have to specify the number of threads per worker

--threads 40 --workers 2

will spawn two workers with 40 threads (total 80 threads)

vhost

enable virtual hosting mode. See VirtualHosting

vhost-host

By default the virtualhosting mode use the SERVER_NAME variable as the hostname key. If you want to use the HTTP_HOST one (corresponding to the Host: header) add this option

check-static

Specify a directory that uWSGI will check before passing control to a specific handler.

uWSGI will check if the requested PATH_INFO has a file correspondence in this directory and eventually will serve it

--check-static /var/www/example.com

If the client ask for foo.png and this file exists as /var/www/example.com/foo.png uWSGI will directly serves it using the choosen method (sendfile() by default)

static-map

map a resource as a static file area

[uwsgi]
static-map = /media=/var/www/django/contrib/admin/media
static-map = /images=/var/www/example.com/images

Whenever a PATH_INFO starts with one of the configured resources, uWSGI will serve the file using the choosen method (sendfile() by default)

static-index

Name of static file to use for directory index.

static-index = index.html

If the client asks for /doc/ then uWSGI will check for /doc/index.html and if it exists it will be served to the client.

file-serve-mode

Set the static serving mode:

x-sendfile -> will use the X-Sendfile header (apache, Cherokee, lighttpd)

x-accel-redirect -> will use the X-Accel-Redirect header (nginx)

default -> sendfile()

--file-serve-mode x-sendfile

check-cache

check if an item named as PATH_INFO is available in the uWSGI cache and eventually will serves it

close-on-exec

set close-on-exec flag on the uWSGI socket. This will avoid external processes generated in a request to inherit the socket file descriptor.

mode

generic option, the apps can read this value with uwsgi.mode

env

set an environment variable

[uwsgi]
env = DJANGO_SETTINGS_MODULE=mysite.settings

this will set DJANGO_SETTINGS_MODULE to mysite.settings

vacuum

automatically remove unix socket and pidfiles on server exit

cgroup

run the server in <group> cgroup (Linux only)

--cgroup <group>

cgroup-opt

set cgroup option (Linux only)

--cgroup-opt KEY=VAL

reuse-port (BSD only)

allows multiple instances binding on the same address

loop

set the LoopEngine (advanced option)

worker-exec

funny option to map a new executable to a uWSGI worker. You can run a php fastcgi server pool in this way

/usr/bin/uwsgi --workers 4 --worker-exec /usr/bin/php53-cgi 

attach-daemon

attach an external process to the uWSGI master process, allowing it to control/monitor/respawn this process.

The argument specifies a executable or script to be run. If it is not on the PATH an absolute path can be used. The daemon should must put itself into the background. When the daemon exits uwsgi will restart it.

Daemons are started after apps are initialised, so if initialisation of an app depends on the daemon being up, a deadlock will occur. You can work around this by deferring this initialisation to when the first  request comes in.

A typical usage is attaching a memcached instance

[uwsgi]
master = true
attach-daemon = memcached

plugins

load the specified plugins

--plugins psgi,greenlet

will load the psgi plugin and the greenlet plugin

allowed-modifiers

Limit the client access to only a subset of modifiers

--allowed-modifiers 0,111

will allow access only the WSGI handler and the cache handler

remap-modifier

dump-options

print all the available options then exit

show-config

print the current configuration in ini format (use this output when you ask for help in the mailing-list, THANKS)

print

commodity option, print a string during config file parsing

[uwsgi]
print = foo

will print 'foo' on server startup

version

print the uWSGI version and exit

wsgi-file or file [python plugin required]

load the specified WSGI file (compatible with Graham's mod_wsgi format)

eval [python plugin required]

evaluate a string as a WSGI entry point

<uwsgi>
  <eval>
def application(e, sr):
    pass
  </eval>
</uwsgi>

module [python plugin required]

load the specified python WSGI module (must be in the PYTHONPATH)

callable [python plugin required]

set the callable to use for WSGI modules (default 'application')

test [python plugin required]

test if a module can be imported successfully

home or virtualenv or venv or pyhome [python plugin required]

set the specified virtualenv for python apps

--virtualenv /apps/env001

will use the virtualenv in /apps/env001

pythonpath or python-path or pp [python plugin required]

add a directory (or an egg) to the PYTHONPATH You can specify this option up to 64 times.

[uwsgi]
pp = myapp/lib
pp = trac.egg

pymodule-alias [python plugin required]

magic option allowing python modules remapping. See PymoduleAlias

pyargv [python plugin required]

set the python sys.argv

--pyargv "one two three"

will set sys.argv to ('one','two','three')

optimize

set the python optimizazion level (dangerous)

paste

use paste.deploy to load a WSGI app

uwsgi --paste config:/foo/development.ini

ini-paste

shortcut for --ini + --paste, after file parsing it will use the same file as paste.deploy config file

ini-paste-logged

load a paste.deploy config file containing uwsgi section (load loggers too)

catch-exceptions

print traceback in your browser instead of the logfile (DO NOT USE IT IN PRODUCTION)

ignore-script-name

pep3333-input

reload-os-env

no-site [python plugin required]

Disable the import of python site.py module

ping [ping plugin required]

utility option for scripts. It pings a uwsgi server. If the ping is successfull the process exit with a 0 code, otherwise with a value > 0

/usr/bin/uwsgi --ping 192.168.0.100:1717

will ping the uWSGI server on 192.168.0.100:1717

ping-timeout [ping plugin required]

set the ping-timeout (default to 3 seconds). It is the maximum number of seconds to wait before considering a uWSGI instance dead.

/usr/bin/uwsgi --ping 192.168.0.100:1717 --ping-timeout 10

will set the ping timeout to 10 seconds

nagios

do a Nagios check

fastrouter

Run the fastrouter (it is a uwsgi proxy/load balancer) on specific address

[uwsgi]
fastrouter = 127.0.0.1:3017

run the fastrouter on address 127.0.0.1 port 3017

fastrouter-use-cache

check the uwsgi cache to get hostname:address mapping

fastrouter-use-pattern

use a filesystem pattern to get hostname:address mapping

fastrouter-use-base

fastrouter-events

limit the max number of async events the fastrouter can return in one cycle

fastrouter-subscription-server

add a SubscriptionServer to the fastrouter to build the hostname:address map

fastrouter-timeout

set the internal fastrouter timeout

http

enable the embedded http server/router/gateway/loadbalancer/proxy

http-var

http-to

http-modifier1

http-use-cache

http-use-pattern

http-use-base

http-use-cluster

http-events

http-subscription-server

enable the SubscriptionServer for clustering and massive hosting/load-balancing

http-timeout

設置內部httpsocket超時

ugreen [ugreen plugin required]

enable uGreen as suspend/resume engine. See uGreen

ugreen-stacksize [ugreen plugin required]

set the stack size for uGreen


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM