Centos5.4 + Nginx-0.8.50 + UWSGI-0.9.6.2 + Django-1.2.3 build high performance WEB server

Source: Internet
Author: User
I have been using Nginx + Fastcgi to build a pythonweb server. This article introduces how to implement Nginx + UWSGI combination. UWSGI is a fast, self-maintained, and developer-friendly WSGI server developed in pure C language. it aims to provide professional Pythonweb application release and development. It complies with the pythonweb standard protocol.

I have been using Nginx + Fastcgi to build a python web server. This article introduces how to implement Nginx + UWSGI combination. UWSGI is a fast, self-maintained, developer-friendly WSGI server developed in pure C language. it aims to provide professional Python web application release and development. It is more in line with the standard protocol of python web, and the speed is faster and the performance is more stable than Fastcgi.
I. installation platform
1. install pcre

Reference
Cd/home
Mkdir-p/home/install/nginx & cd/home/install/nginx
Wget http://ftp.exim.llorien.org/pcre/pcre-8.00.tar.gz
Tar-zxvf pcre-8.00.tar.gz
Cd pcre-8.00
./Configure
Make & make install
Cd ..

2. install Nginx

Reference
Wget http://nginx.org/download/nginx-0.8.50.tar.gz
Tar-zxvf nginx-0.8.50.tar.gz
Cd nginx-0.8.50/
./Configure? User = nobody? Group = nobody? Prefix =/usr/local/nginx? With-http_stub_status_module? With-cc-opt = '-O3 ′? With-cpu-opt = opteron
Make & make install
Cd ..

3. install python & Mysql-python

Reference
Wget http://www.python.org/ftp/python/2.5.1/Python-2.5.1.tgz
Tar-zxvf Python-2.5.1.tgz
Cd Python-2.5.1
./Configure & make install
Echo "export PATH = $ PATH:/usr/local/bin">/etc/profile
Source/etc/profile

4. install MySql-python

Reference
Cd ../
Wget mysql-python/1.2.2/MySQL-python-1.2.2.tar.gz? R = & ts = 1285248455 & use_mirror = nchc "> http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.2/MySQL-python-1.2.2.tar.gz? R = & ts = 1285248455 & use_mirror = nchc
Cd MySQL-python-1.2.2
Python setup. py install

5. install Django

Reference
Wget http://www.djangoproject.com/download/1.2.3/tarball/
Tar-zxvf Django-1.2.3.tar.gz
Cd Django-1.2.3
Python setup. py install
Cd ..

6. install uWSGI

Reference
Wget http://projects.unbit.it/downloads/uwsgi-0.9.6.2.tar.gz
Tar-zxvf uwsgi-0.9.6.2.tar.gz
Cd uwsgi-0.9.6.2
Make
Cp uwsgi/usr/bin

2. platform configuration
1. platform environment description
1.1 Project location:/opt/www/Purgesys
How to create a project:

Reference
Cd/opt/www
Django-admin.py startproject Purgesys

1.2 view the project (the following file structure indicates that the project has been created successfully)
# Tree Purgesys

Reference
Purgesys
|? _ Init _. py
|? Manage. py
|? Settings. py
'? Urls. py

2. Nginx configuration
# Cd/usr/local/nginx/conf
# Vi django_uwsgi.conf

View plaincopy to clipboardprint?
# Django project
Server {
Listen 80;
Server_name purgesys.domain.com;
Location /{
Uwsgi_pass 127.0.0.1: 9000;
Include uwsgi_params;
Access_log off;
}
Location ^ ~ /Static {
Root/opt/www/Purgesys;
}
Location ^ ~ /Admin /{
Uwsgi_pass 127.0.0.1: 9000;
Include uwsgi_params;
Access_log off;
}
Location ~ * ^. +. (Mpg | avi | mp3 | swf | zip | tgz | gz | rar | bz2 | doc | xls | exe | ppt | txt | tar | mid | midi | wav | rtf | mpeg) $ {
Root/opt/www/Purgesys/static;
Access_log off;
}
}
# Django project server {listen 80; server_name purgesys.domain.com; location/{uwsgi_pass 127.0.0.1: 9000; include uwsgi_params; access_log off;} location ^ ~ /Static {root/opt/www/Purgesys;} location ^ ~ /Admin/{uwsgi_pass 127.0.0.1: 9000; include uwsgi_params; access_log off;} location ~ * ^. +. (Mpg | avi | mp3 | swf | zip | tgz | gz | rar | bz2 | doc | xls | exe | ppt | txt | tar | mid | midi | wav | rtf | mpeg) $ {root/opt/www/Purgesys/static; access_log off ;}}
* Uwsgi output header supported by Nginx-0.8.50 by default
Include uwsgi_params;

# Vi nginx. conf
Append the sub-configuration file django_uwsgi.conf.

Http {
........
Include django_uwsgi.conf;
}
Http {........ Include django_uwsgi.conf ;}
3. UWSGI configuration
# Mkdir-p/home/uwsgi; cd/home/uwsgi
# Mkdir-p/opt/www/logs
# Echo "">/opt/www/logs/django. log
# Vi uwsgi. xml

View plaincopy to clipboardprint?

127.0.0.1: 9000
200
True
/Usr/local/nginx/uwsgi. pid
8
/Opt/www/Purgesys
/Opt/www/
Django_wsgi
True
True
True
True
6048
/Opt/www/logs/django. log

127.0.0.1: 9000 200 True /Usr/local/nginx/uwsgi. pid 8 /Opt/www/Purgesys /Opt/www/ Django_wsgi True True True True 6048 /Opt/www/logs/django. log
4. create an application module
Cd/opt/www/Purgesys
Vi django_wsgi.py

View plaincopy to clipboardprint?
Import OS
OS. environ [DJANGO_SETTINGS_MODULE] = 'purgesys. setts'
Import django. core. handlers. wsgi
Application = django. core. handlers. wsgi. WSGIHandler ()
Import OS. environ [DJANGO_SETTINGS_MODULE] = 'purgesys. setting' import django. core. handlers. wsgi application = django. core. handlers. wsgi. WSGIHandler ()
5. start the service
#/Usr/bin/uwsgi-x/home/uwsgi. xml
#/Usr/local/nginx/sbin/nginx

6. View processes
# [Liuts @ webserver nginx] # ps-ef | grep uwsgi | grep-v grep

Reference
Root 21652 1 0 17:12? 00:00:00/usr/bin/uwsgi-x/home/uwsgi. xml
Root 21653 21652 0? 00:00:00/usr/bin/uwsgi-x/home/uwsgi. xml
Root 21654 21652 0? 00:00:00/usr/bin/uwsgi-x/home/uwsgi. xml
Root 21655 21652 0? 00:00:00/usr/bin/uwsgi-x/home/uwsgi. xml
Root 21656 21652 0? 00:00:00/usr/bin/uwsgi-x/home/uwsgi. xml
Root 21657 216

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.