Uwsgi Documentation Release 2.0
Total Page:16
File Type:pdf, Size:1020Kb
uWSGI Documentation Release 2.0 uWSGI March 14, 2014 Contents 1 Included components (updated to latest stable release)3 2 Quickstarts 5 2.1 Quickstart for Python/WSGI applications................................5 2.2 Quickstart for perl/PSGI applications.................................. 10 2.3 Quickstart for ruby/Rack applications.................................. 15 2.4 Snippets................................................. 23 3 Table of Contents 25 3.1 Getting uWSGI.............................................. 25 3.2 Installing uWSGI............................................. 25 3.3 The uWSGI build system........................................ 26 3.4 Managing the uWSGI server....................................... 29 3.5 Supported languages and platforms................................... 32 3.6 Supported Platforms/Systems...................................... 32 3.7 Web server integration.......................................... 33 3.8 Frequently Asked Questions (FAQ)................................... 34 3.9 Things to know (best practices and “issues”).............................. 38 3.10 Configuring uWSGI........................................... 39 3.11 Fallback configuration.......................................... 45 3.12 Configuration logic............................................ 47 3.13 Configuration Options.......................................... 50 3.14 Defining new options for your instances................................. 139 3.15 How uWSGI parses config files..................................... 141 3.16 uwsgi protocol magic variables..................................... 143 3.17 The uwsgi Protocol............................................ 145 3.18 Managing external daemons/services.................................. 147 3.19 The Master FIFO............................................. 149 3.20 Socket activation with inetd/xinetd................................... 151 3.21 Running uWSGI via Upstart....................................... 151 3.22 SystemD................................................. 153 3.23 Running uWSGI instances with Circus................................. 155 3.24 Embedding an application in uWSGI.................................. 156 3.25 Logging.................................................. 158 3.26 Formatting uWSGI requests logs.................................... 163 3.27 Log encoders............................................... 165 3.28 Hooks................................................... 168 3.29 Glossary................................................. 172 i 3.30 uWSGI third party plugins........................................ 172 4 Tutorials 175 4.1 The uWSGI Caching Cookbook..................................... 175 4.2 Setting up Django and your web server with uWSGI and nginx.................... 183 4.3 Running uWSGI on Dreamhost shared hosting............................. 191 4.4 Running python webapps on Heroku with uWSGI........................... 195 4.5 Running Ruby/Rack webapps on Heroku with uWSGI......................... 199 4.6 Reliably use FUSE filesystems for uWSGI vassals (with Linux).................... 203 4.7 Build a dynamic proxy using RPC and internal routing......................... 206 4.8 Setting up Graphite on Ubuntu using the Metrics subsystem...................... 207 5 Articles 211 5.1 Serializing accept(), AKA Thundering Herd, AKA the Zeeg Problem................. 211 5.2 The Art of Graceful Reloading...................................... 218 5.3 Fun with Perl, Eyetoy and RaspberryPi................................. 227 6 uWSGI Subsystems 233 6.1 The uWSGI alarm subsystem (from 1.3)................................ 233 6.2 The uWSGI caching framework..................................... 237 6.3 WebCaching framework......................................... 240 6.4 The uWSGI cron-like interface..................................... 242 6.5 The uWSGI FastRouter......................................... 245 6.6 uWSGI internal routing......................................... 248 6.7 The uWSGI Legion subsystem...................................... 261 6.8 Locks................................................... 265 6.9 uWSGI Mules.............................................. 266 6.10 The uWSGI offloading subsystem.................................... 267 6.11 The uWSGI queue framework...................................... 268 6.12 uWSGI RPC Stack............................................ 270 6.13 SharedArea – share memory pages between uWSGI components................... 272 6.14 The uWSGI Signal Framework..................................... 274 6.15 The uWSGI Spooler........................................... 277 6.16 uWSGI Subscription Server....................................... 281 6.17 Serving static files with uWSGI (updated to 1.9)............................ 284 6.18 SNI - Server Name Identification (virtual hosting for SSL nodes)................... 288 6.19 The GeoIP plugin............................................ 290 6.20 uWSGI Transformations......................................... 291 6.21 WebSocket supports........................................... 294 6.22 The Metrics subsystem.......................................... 296 6.23 The Chunked input API......................................... 304 7 Scaling with uWSGI 307 7.1 The uWSGI cheaper subsystem – adaptive process spawning...................... 307 7.2 The uWSGI Emperor – multi-app deployment............................. 311 7.3 Auto-scaling with Broodlord mode................................... 321 7.4 Zerg mode................................................ 321 7.5 Adding applications dynamically.................................... 323 7.6 Scaling SSL connections (uWSGI 1.9)................................. 324 8 Securing uWSGI 329 8.1 Setting POSIX Capabilities....................................... 329 8.2 Running uWSGI in a Linux CGroup................................... 330 8.3 Using Linux KSM in uWSGI...................................... 331 8.4 Jailing your apps using Linux Namespaces............................... 332 ii 8.5 The old way: the –namespace option.................................. 334 8.6 FreeBSD Jails.............................................. 336 8.7 The Forkpty Router........................................... 340 8.8 The TunTap Router............................................ 342 9 Keeping an eye on your apps 345 9.1 Monitoring uWSGI with Nagios..................................... 345 9.2 The embedded SNMP server....................................... 345 9.3 Pushing statistics (from 1.4)....................................... 346 9.4 Integration with Graphite/Carbon.................................... 347 9.5 The uWSGI Stats Server......................................... 348 9.6 The Metrics subsystem.......................................... 352 10 Async and loop engines 361 10.1 uWSGI asynchronous/non-blocking modes (updated to uWSGI 1.9).................. 361 10.2 The Gevent loop engine......................................... 364 10.3 The Tornado loop engine......................................... 366 10.4 uGreen – uWSGI Green Threads.................................... 369 11 Web Server support 371 11.1 Apache support.............................................. 371 11.2 Cherokee support............................................. 372 11.3 Native HTTP support........................................... 373 11.4 HTTPS support (from 1.3)........................................ 376 11.5 The SPDY router (uWSGI 1.9)..................................... 377 11.6 Lighttpd support............................................. 378 11.7 Attaching uWSGI to Mongrel2..................................... 379 11.8 Nginx support.............................................. 381 12 Language support 385 12.1 Python support.............................................. 385 12.2 The PyPy plugin............................................. 404 12.3 Running PHP scripts in uWSGI..................................... 413 12.4 uWSGI Perl support (PSGI)....................................... 417 12.5 Ruby support............................................... 420 12.6 Using Lua/WSAPI with uWSGI..................................... 427 12.7 JVM in the uWSGI server (updated to 1.9)............................... 431 12.8 The Mono ASP.NET plugin....................................... 441 12.9 Running CGI scripts on uWSGI..................................... 443 12.10 The gccgo plugin............................................. 447 12.11 The Symcall plugin............................................ 450 12.12 The XSLT plugin............................................. 453 12.13 SSI (Server Side Includes) plugin.................................... 454 12.14 uWSGI V8 support............................................ 456 12.15 The GridFS plugin............................................ 457 12.16 The GlusterFS plugin.......................................... 461 12.17 The RADOS plugin........................................... 464 13 Other plugins 467 13.1 The Pty plugin.............................................. 467 13.2 SPNEGO authentication......................................... 468 13.3 Configuring uWSGI with LDAP..................................... 468 14 Broken/deprecated features 469 14.1 Integrating uWSGI with Erlang..................................... 469 iii 14.2 Management Flags............................................ 472 14.3 uWSGI Go support (1.4 only)...................................... 473 15 Release Notes 479 15.1 Stable