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
[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
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)
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
ugreen [ugreen plugin required]
enable uGreen as suspend/resume engine. See uGreen
ugreen-stacksize [ugreen plugin required]
set the stack size for uGreen
posted on 2012-11-27 19:07 DON'T PANIC 阅读(9738) 评论(0) 编辑 收藏 举报