Build a Django + flup + nginx environment in Ubuntu

Source: Internet
Author: User

First, we must understand the role of these three in this environment.

1. nginx :( "engine X") is a high-performance HTTP and reverse proxy server, which works similar to Apache. It can process some static file requests. For dynamic file requests, it can distribute requests to different dynamic languages through FastCGI.

 

2. flup: it is a web server software written in Python. It can accept requests from nginx and execute the corresponding PythonCodeTo return the result to nginx.

3. DJANGO: a python-based Web framework. It can be used for basic things, such as Cookie, session management, template mechanism, and permission management.

Before setting up the environment, you must install the python environment. This article uses python2.6.5. The installation of python is not described here.

1. Install related support files

Setuptools: setuptools is required to install the python class library through setup. py.

 
Wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.eggsh setuptools-0.6c11-py2.6.egg

PCRE, class library related to regular expressions, ow.ssh, required for nginx installation.

Wget http://sourceforge.net/projects/pcre/files/pcre/8.02/pcre-8.02.tar.gz/downloadtar zxvf pcre-8.02.tar.gzcd pcre-8.02./configuremakemake installcd .. apt-Get install OpenSSL libssl-devel

Zlib, compression-related class libraries, which are required by many software.

 
Wget http://downloads.sourceforge.net/project/libpng/zlib/1.2.5/zlib-1.2.5.tar.gz? Use_mirror = nchctar zxvf zlib-1.2.5.tar.gzcd zlib-1.2.5./configuremake make installcd ..
2. Install Django
 
Wget http://www.djangoproject.com/download/1.2.1/tarball/tar zxvf Django-1.2.1.tar.gzcd Django-1.2.1python setup. py installcd ..

To use MySQL DATA, see install django1.2 and MySQL-python in Linux.

3. Install flup
 
Wget http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gztar zxvf flup-1.0.2.tar.gzcd flup-1.0.2python setup. py installcd ..
4. Install nginx
Wget http://nginx.org/download/nginx-0.8.39.tar.gztar zxvf nginx-0.8.39.tar.gzcd nginx-0.8.39./configuremakemake instll

Note: After installation, a piece of configuration summary information is displayed, which can be saved for future use.

5. Configuration

Configure flup and flup to communicate with each other through FastCGI.ProgramIn the server {...} configuration section, add the following configuration in the location {...} configuration section:

 
Fastcgi_pass Unix:/tmp/mysite. sock; Response path_info $ response; Response request_method $ request_method; Response QUERY_STRING $ QUERY_STRING; Response content_type $ content_type; Response content_length $ content_length; authorization; Response off; Response server_protocol $ server_protocol; fastcgi_param server_port $ server_port; fastcgi_param SERVER_NAME $ SERVER_NAME;
6. Run

Create a Django Project

Cd ~ Django-admin.py startproject mysite

Run Django in CGI Mode

 
~ /News/manage. py runfcgi daemonize = true socket =/tmp/mysite. Sock

Start nginx

 
/Usr/local/nginx/sbin/nginx

Enjoy the fun of Django!

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.