Go to: Python wsgi FastCGI

Source: Internet
Author: User

1. What is wsgi.

Before getting to know flup, you must first get to know wsgi.

Wsgi is called Python Web Server Gateway Interface V1.0 (Python Web Server Gateway Interface). It is an excuse between a Python application and a web server, see pep333.

It is similar to fcgi or FastCGI.

The purpose of wsgi is to establish a simple interface between a common server and a Web framework.

Wsgi features simplicity and portability.

2. What is flup.

Wsgi is also a standard, it defines how Python applications can communicate and exchange information between Web servers such as Apache, Lighttpd, and nginx, it is not something that can be used directly. Flup is an implementation of wsgi using the Python language. It is a tool or library that can be used in Python application development.

Flup Official Website: http://trac.saddi.com/flup. Flup is an open source software and adopts BSD-style open source authorization.

In addition to flup, wsgi has no other implementations. Of course, for more implementations, refer:

Http://wiki.python.org/moin/WSGIImplementations

3. wsgi servers/gateways supported by flup

Flup supports three wsgi servers/gateways: AJP 1.3, FastCGI, and scgi.

For the three wsgi servers/gateways supported by flup, flup provides two different versions: thread version and process version.

In this way, flup actually supports six types of wsgi servers/gateways:

Flup. server. AJP
Flup. server. AJPFork
Flup. server. fcgi
Flup. server. fcgi
Fork
Flup. server. scgi
Flup. server. scgi_fork
Flup. server. cgi

Example:

def myapp(environ, start_response): start_response(’200 OK’, [('Content-Type', 'text/plain')]) return ['Hello World!\n'] if __name__ == ‘__main__’: from flup.server.fcgi import WSGIServer WSGIServer(myapp).run() 

Iv. Application of flup in Django

As a well-known and widely used Python web development framework, Django has applied flup. In the Django/CORE/servers/FastCGI. py file, wsgihandler () in Django/CORE/handlers/wsgi. py is called to process wsgi applications.

V. Web processing process

Nginx <--- (FastCGI) ---> flup (wsgi/Django)

Lighttpd <-- (FastCGI) ---> flup (wsgi/Django)

Apache <-- (CGI/FastCGI/scgi/mod_wsgi) ----> flup (wsgi/Django)

Note:

Apache/Lighttpd:

It is equivalent to a request proxy. According to the configuration, different requests are forwarded to different servers for processing. For example, static file requests are handled by themselves. At this time, it is like a web server, forward requests such as FastCGI and python to the server/gateway such as flup for processing.

Flup:

A Web Server written in Python, the so-called server/gateway in CGI, is responsible for receiving requests forwarded by Apache/Lighttpd and calling the application you write ), and return the application processing result to Apache/Lighttpd.

FastCGI:

A module of Apache/Lighttpd. Although flup can be used as an independent web server, the processing of browser requests is generally handled by Apache/Lighttpd, then Apache/Lighttpd forwards it to flup for processing. In this way, you need something to associate Apache/Lighttpd with flup. This is FastCGI, it sends the client request information to flup through environment variables and socket and receives the results returned by flup.

Web. py:

It should be said that with the above, you can start to write your web program, but the problem is that you have to handle the browser input and output by yourself, there are also cookie, session, templates and other issues, Web. the role of Py is to help you do all of this work well. It is called Web framework. Another famous one is Django, but it feels too complicated, Web. py is enough.

Wsgi:

In addition to flup server/gateway, there are many other users writing server/gateway, which may cause problems at this time. If you write a program on flup, now you have to use xdly for various reasons. At this time, your program may have to make a lot of painful modifications to use xdly server. wsgi is a specification, he standardized how to write the flup service, how to use it, and how to call the program (Application) You wrote. Of course, he also standardized how your program should be written, in this case, as long as both flup and xdly comply with wsgi, your program can be used on both of them. flup is a wsgi server.

1. What is wsgi.

Before getting to know flup, you must first get to know wsgi.

Wsgi is called Python Web Server Gateway Interface V1.0 (Python Web Server Gateway Interface). It is an excuse between a Python application and a web server, see pep333.

It is similar to fcgi or FastCGI.

The purpose of wsgi is to establish a simple interface between a common server and a Web framework.

Wsgi features simplicity and portability.

2. What is flup.

Wsgi is also a standard, it defines how Python applications can communicate and exchange information between Web servers such as Apache, Lighttpd, and nginx, it is not something that can be used directly. Flup is an implementation of wsgi using the Python language. It is a tool or library that can be used in Python application development.

Flup Official Website: http://trac.saddi.com/flup. Flup is an open source software and adopts BSD-style open source authorization.

In addition to flup, wsgi has no other implementations. Of course, for more implementations, refer:

Http://wiki.python.org/moin/WSGIImplementations

3. wsgi servers/gateways supported by flup

Flup supports three wsgi servers/gateways: AJP 1.3, FastCGI, and scgi.

For the three wsgi servers/gateways supported by flup, flup provides two different versions: thread version and process version.

In this way, flup actually supports six types of wsgi servers/gateways:

Flup. server. AJP
Flup. server. AJPFork
Flup. server. fcgi
Flup. server. fcgi
Fork
Flup. server. scgi
Flup. server. scgi_fork
Flup. server. cgi

Example:

def myapp(environ, start_response): start_response(’200 OK’, [('Content-Type', 'text/plain')]) return ['Hello World!\n'] if __name__ == ‘__main__’: from flup.server.fcgi import WSGIServer WSGIServer(myapp).run() 

Iv. Application of flup in Django

As a well-known and widely used Python web development framework, Django has applied flup. In the Django/CORE/servers/FastCGI. py file, wsgihandler () in Django/CORE/handlers/wsgi. py is called to process wsgi applications.

V. Web processing process

Nginx <--- (FastCGI) ---> flup (wsgi/Django)

Lighttpd <-- (FastCGI) ---> flup (wsgi/Django)

Apache <-- (CGI/FastCGI/scgi/mod_wsgi) ----> flup (wsgi/Django)

Note:

Apache/Lighttpd:

It is equivalent to a request proxy. According to the configuration, different requests are forwarded to different servers for processing. For example, static file requests are handled by themselves. At this time, it is like a web server, forward requests such as FastCGI and python to the server/gateway such as flup for processing.

Flup:

A Web Server written in Python, the so-called server/gateway in CGI, is responsible for receiving requests forwarded by Apache/Lighttpd and calling the application you write ), and return the application processing result to Apache/Lighttpd.

FastCGI:

A module of Apache/Lighttpd. Although flup can be used as an independent web server, the processing of browser requests is generally handled by Apache/Lighttpd, then Apache/Lighttpd forwards it to flup for processing. In this way, you need something to associate Apache/Lighttpd with flup. This is FastCGI, it sends the client request information to flup through environment variables and socket and receives the results returned by flup.

Web. py:

It should be said that with the above, you can start to write your web program, but the problem is that you have to handle the browser input and output by yourself, there are also cookie, session, templates and other issues, Web. the role of Py is to help you do all of this work well. It is called Web framework. Another famous one is Django, but it feels too complicated, Web. py is enough.

Wsgi:

In addition to flup server/gateway, there are many other users writing server/gateway, which may cause problems at this time. If you write a program on flup, now you have to use xdly for various reasons. At this time, your program may have to make a lot of painful modifications to use xdly server. wsgi is a specification, he standardized how to write the flup service, how to use it, and how to call the program (Application) You wrote. Of course, he also standardized how your program should be written, in this case, as long as both flup and xdly comply with wsgi, your program can be used on both of them. flup is a wsgi server.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.