As a back-end with web-server, speak the uwsgi protocol

<uwsgi id = "uwsgibk">
<stats>127.0.0.1:9090</stats>
<socket>127.0.0.1:3030</socket>
<file>./server.py</file>
<enable-threads/>
<post-buffering/>
<memory-report/>
</uwsgi>

As a back-end with web-server, speak the http protocol

The http and http-socket options are entirely different beasts. The first one spawns an additional process forwarding requests to a series of workers (think about it as a form of shield, at the same level of apache or nginx), while the second one sets workers to natively speak the http protocol. TL/DR: if you plan to expose uWSGI directly to the public, use –http, if you want to proxy it behind a webserver speaking http with backends, use –http-socket. .. seealso:: Native HTTP support

<uwsgi id = "httpbk">
<stats>127.0.0.1:9090</stats>
<http-socket>127.0.0.1:3030</http-socket>
<file>./server.py</file>
<enable-threads/>
<post-buffering/>
<memory-report/>
</uwsgi>

Expose self directly to the public

The http and http-socket options are entirely different beasts. The first one spawns an additional process forwarding requests to a series of workers (think about it as a form of shield, at the same level of apache or nginx), while the second one sets workers to natively speak the http protocol. TL/DR: if you plan to expose uWSGI directly to the public, use –http, if you want to proxy it behind a webserver speaking http with backends, use –http-socket. .. seealso:: Native HTTP support

<uwsgi id = "http">
<stats>127.0.0.1:9090</stats>
<http>:80</http>
<file>./server.py</file>
<enable-threads/>
<post-buffering/>
<memory-report/>
</uwsgi>

Nginx with The uWSGI FastRouter

http://uwsgi-docs.readthedocs.org/en/latest/Nginx.html
http://uwsgi-docs.readthedocs.org/en/latest/Fastrouter.html
http://stackoverflow.com/questions/21518533/putting-a-uwsgi-fast-router-in-front-of-uwsgi-servers-running-in-docker-containe
http://stackoverflow.com/questions/26499644/how-to-use-the-uwsgi-fastrouter-whith-nginx

Configurations of Nginx

location /test {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3030;
}

Configurations of FastRouter

<uwsgi id = "fastrouter">
<fastrouter>127.0.0.1:3030</fastrouter>
<fastrouter-subscription-server>127.0.0.1:3131</fastrouter-subscription-server>
<enable-threads/>
<master/>
<fastrouter-stats>127.0.0.1:9595</fastrouter-stats>
</uwsgi>

Configurations of instance

<uwsgi id = "subserver1">
<stats>127.0.0.1:9393</stats>
<processes>4</processes>
<enable-threads/>
<memory-report/>
<subscribe-to>127.0.0.1:3131:[server_ip] or [domain]</subscribe-to>
<socket>127.0.0.1:3232</socket>
<file>./server.py</file>
<master/>
<weight>8</weight>
</uwsgi>
<uwsgi id = "subserver2">
<stats>127.0.0.1:9494</stats>
<processes>4</processes>
<enable-threads/>
<memory-report/>
<subscribe-to>127.0.0.1:3131:[server_ip] or [domain]</subscribe-to>
<socket>127.0.0.1:3333</socket>
<file>./server.py</file>
<master/>
<weight>2</weight>
</uwsgi>

If we HTTP-GET [server_ip] or [domain]/test, the route of request as follows:
Nginx >> FastRouter(port 3030) >> FastRouter(port 3131) >> subserver1(port 3232) or subserver2(port 3333)
and the protocol of all is uwsgi.

Faster Router also has specific stats.

http router

http://uwsgi-docs.readthedocs.org/en/latest/HTTP.html
Router

<uwsgi id = "httprouter">
<enable-threads/>
<master/>
<http>:8080</http>
<http-stats>127.0.0.1:9090</http-stats>
<http-to>127.0.0.1:8181</http-to>
<http-to>127.0.0.1:8282</http-to>
</uwsgi>

sub-server1

<uwsgi id = "httpserver1">
<stats>127.0.0.1:9191</stats>
<socket>127.0.0.1:8181</socket>
<memory-report/>
<file>./server.py</file>
<enable-threads/>
<post-buffering/>
</uwsgi>

sub-server2

<uwsgi id = "httpserver2">
<stats>127.0.0.1:9292</stats>
<memory-report/>
<file>./server.py</file>
<socket>127.0.0.1:8282</socket>
<enable-threads/>
<post-buffering/>
</uwsgi>

Other route mode

Just like Fast Route and Http Route, the router can forward(http-to) or route requests to other sub-servers, the only difference is protocol.
The protocols as follows:
Fast, HTTP(S), raw, ssl.
Certainly, all of routers have specific stats in the same style.

The uWSGI Emperor

http://uwsgi-docs.readthedocs.org/en/latest/Emperor.html
Emperor

<uwsgi id = "emperor">
<emperor>./vassals</emperor>
<emperor-stats-server>127.0.0.1:9090</emperor-stats-server>
</uwsgi>

Vassal1

<vassal1>
<uwsgi id = "vassal1">
<http>:8080</http>
<stats>127.0.0.1:9191</stats>
<memory-report/>
<enable-threads/>
<post-buffering/>
<file>./server.py</file>
<chdir>..</chdir>
</uwsgi>
</vassal1>

Vassal2

<vassal2>
<uwsgi id = "vassal2">
<http>:8181</http>
<stats>127.0.0.1:9292</stats>
<memory-report/>
<enable-threads/>
<post-buffering/>
<file>./server.py</file>
<chdir>..</chdir>
</uwsgi>
</vassal2>

Emperor also has specific stats.

multi-mountpoint

<uwsgi id = "vassal1">
<socket>127.0.0.1:3030</socket>
<http>:8080</http>
<stats>127.0.0.1:9191</stats>
<memory-report/>
<enable-threads/>
<post-buffering/>
<manage-script-name/>
<chdir>..</chdir>
<mount>/pic=server.py</mount>
<mount>/test=fuck.py</mount>
<workers>2</workers>
</uwsgi>

注意:

http://stackoverflow.com/questions/19475651/how-to-mount-django-app-with-uwsgi

<manage-script-name/>参数很关键,但官方help中并没有提这个,F*CK YOU!

这样配置后,uWSGI会根据不同的request路径调用不同的app。

The End

uWSGI作为backend,和Nginx的配合比Apache要好,建议用Nginx作前端。

如果在CentOS上以INET socket为载体部署Nginx+uWSGI或Apache+uWSGI时,客户端访问遇到50x Bad Gateway错误时,强烈建议你换到Ubuntu上去试试,因为同样的配置在CentOS上有这个问题,换到Ubuntu后就可能没问题。

2014-11-03补充:CentOS下的这个问题的原因是RedHat系列的Linux发行版默认开启SELinux,SELinux的某些策略导致的这个问题,不知道算不算是BUG。关闭了SELinux就可解决,具体如何关闭可以参考:http://www.cnblogs.com/lightnear/archive/2012/10/06/2713090.html。Debian系列的发行版因为默认没有开启SELinux,所以不存在这个问题。上周末看到一篇比较Liunx发行版性能的文章时,偶然发现的有SELinux这个东西,今天一试果然。如果再碰到其他类似的诡异问题,也可以尝试关闭SELinux试试。

如果用Apache+uWSGI部署后,客户端访问时返回一个文件,那有可能是Apache对页面压缩后的结果,把Apache的GZIP压缩模块关掉就好了。Nginx没有这个问题,更好用不是吗?

忍不住吐槽

尼玛uWSGI的文档就是一坨SHIT,SHIT!国内这方面的知识可能少很多,在这里贴出来,方便国内的用户。

像这种小众一点的东西,国内资料很少,跟国外比还是有差距啊,基友们还需努力啊。

uWSGI的各种部署方式的更多相关文章

  1. 五步教你实现使用Nginx+uWSGI+Django方法部署Django程序

    Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式. 在这种方式中,我们的通常做法是,将nginx作为服务器最前端,它将接收WEB的所有请求,统一管理请求.ng ...

  2. 使用Nginx+uWSGI+Django方法部署Django程序

    第一步先解决uwsgi与django的桥接.解决在没有nginx的情况下,如何使用uwsgi+DJANGO来实现一个简单的WEB服务器. 第二步解决uwsgi与Nginx的桥接.通过nginx与uws ...

  3. 使用Nginx+uWSGI+Django方法部署Django程序(上)

    Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式. 在这种方式中,我们的通常做法是,将nginx作为服务器最前端,它将接收WEB的所有请求,统一管理请求.ng ...

  4. [原]Python Web部署方式总结

    不要让服务器裸奔 学过PHP的都了解,php的正式环境部署非常简单,改几个文件就OK,用FastCgi方式也是分分钟的事情.相比起来,Python在web应用上的部署就繁杂的多,主要是工具繁多,主流服 ...

  5. [转]Python Web部署方式总结

    学过PHP的都了解,php的正式环境部署非常简单,改几个文件就OK,用FastCgi方式也是分分钟的事情.相比起来,Python在web应用上的部署就繁杂的多,主要是工具繁多,主流服务器支持不足,在了 ...

  6. Python Web部署方式全汇总

    学过PHP的都了解,php的正式环境部署非常简单,改几个文件就OK,用FastCgi方式也是分分钟的事情.相比起来,Python在web应用上的部署就繁杂的多,主要是工具繁多,主流服务器支持不足. 在 ...

  7. 使用Nginx+uWSGI+Django方法部署Django程序(下)

    在上一篇文章<五步教你实现使用Nginx+uWSGI+Django方法部署Django程序(上)>中,阐述了如何只使用uWSGI来部署Django程序. 当然,单单只有uWSGI是不够的, ...

  8. uWSGI + Nginx + Django 部署

    1. uWSGI 服务器 Django 默认使用 WSGI(Python Web Server Gateway ) 作为 Web 服务器,一般仅用来作为测试使用,实际生产环境而是使用 uWSGI 和 ...

  9. django项目在uwsgi+nginx上部署遇到的坑

    本文来自网易云社区 作者:王超 问题背景 django框架提供了一个开发调试使用的WSGIServer, 使用这个服务器可以很方便的开发web应用.但是 正式环境下却不建议使用这个服务器, 其性能.安 ...

随机推荐

  1. ArchLinux新版本(pacstrap安装)及国内较优源推荐

    下载安装镜像和配置虚拟机都略过. 进入安装模式以后第一件事是要进行分区,分区很重要,怎么分区是由后面的grub的模式来决定的.grub有3种模式,分别对应grub-bios-gpt,grub-bios ...

  2. HDUOJ----4006The kth great number(最小堆...)

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  3. DP较为完整的知识

    数位DP 这类题,才刚刚接触,记得去年网络赛,就有道这样的题,我完全不会, 对于这类题基本方法是,是利用数的位数来构造转移方程. 下面给出两篇论文的链接: <数位计数问题解法研究> < ...

  4. MVC笔记 Controller相关技术

    一.Controller的责任 MVC的核心就是Controller(控制器),它负责处理浏览器传送过来的所有请求,并决定要将什么内容响应给浏览器.但Controller并不负责决定内容应该如何显示, ...

  5. 进程间通信机制(管道、信号、共享内存/信号量/消息队列)、线程间通信机制(互斥锁、条件变量、posix匿名信号量)

    注:本分类下文章大多整理自<深入分析linux内核源代码>一书,另有参考其他一些资料如<linux内核完全剖析>.<linux c 编程一站式学习>等,只是为了更好 ...

  6. Python 字典 items() 方法

    描述 Python 字典 items() 方法以列表形式(并非直接的列表,若要返回列表值还需调用list函数)返回可遍历的(键, 值) 元组数组. 语法 items() 方法语法: D.items() ...

  7. 编码规范:Eclipse Code Templates设置

    现在的项目一般都是一个团队共同开发,而每个人都有自己的编码习惯,为了统一格式,项目组在项目开发之前都会制定一系列的规范.设置Code Templates的目的主要是为了统一各种注释的格式以及代码的模板 ...

  8. Spring事务管理实现方式之编程式事务与声明式事务详解(转)

    原文:https://blog.csdn.net/liaohaojian/article/details/70139151 编程式事务 编码方式实现事务管理(代码演示为JDBC事务管理) Spring ...

  9. 《Effective Java》读书笔记二(通用方法)

    No8 覆盖equals方法时请遵守通用约定 通用约定,下面的约定前提都是x/y/z不为null值. 自反性(reflexive),x.equals(x)必须返回true. 对称性(symmetric ...

  10. TRIZ系列-创新原理-9~11-预先反作用原理、预处理原理、预先防范原理

    一.预先反作用原理表述例如以下: 1)预先给物体施加反作用,以补偿过量的或者不想要的压力. 假设知道系统在执行过程中,会有不利的或者有害的作用(负面作用)产生,则能够预先採取一定的措施来抵消.控制这样 ...