nginx+uwsgi+django架构部署

1.安装pcre,pcre是一个轻量级的正则表达式函数库,nginx的HTTP Rewrite模块会用到。

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz
tar -zxvf pcre-8.34.tar.gz
cd pcre-8.34
./configure
make && make install

2.安装nginx.

wget http://nginx.org/download/nginx-1.5.9.tar.gz
tar -zxvf nginx-1.5.9.tar.gz
cd nginx-1.5.9
./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

3.安装MySQL-python.

yum install MySQL-python -y     #yum安装方式
wget http://nchc.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.2/MySQL-python-1.2.2.tar.gz
tar -zxvf MySQL-python-1.2.2.tar.gz
cd MySQL-python-1.2.2
python setup.py install

4.安装uwsgi.

wget http://projects.unbit.it/downloads/uwsgi-2.0.4.tar.gz
tar -zxvf uwsgi-2.0.4.tar.gz
cd uwsgi-2.0.4
make
cp uwsgi /usr/bin

5.安装Django.

wget htpp://www.djangoproject.com/m/releases/1.4/Django-1.4.9.tar.gz
tar -zxvf Django-1.4.9.tar.gz
cd Django-1.4.9
python setup.py install

6.配置nginx。修改/usr/local/nginx/conf/nginx.conf,添加以下server域配置:

    server {
        listen       80;
        server_name  www.omserver.com;

        location / {
            uwsgi_pass 192.168.202.128:9000;
            include uwsgi_params;
            uwsgi_param UWSGI_CHDIR /data/www/OMserverweb;  #项目主目录
            uwsgi_param UWSGI_SCRIPT django_wsgi;
            access_log off;
        }
        location ^~ /static {
            root /data/www/OMserverweb;
        }
        location ~* ^.+\.(mpg|avi|mp3|swf|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|txt|tar|mid|midi|wav|rtf|mpeg)$ {
            root /data/www/OMserverweb/static;
            access_log off;
        }
    }

7.配置uwsgi。创建uwsgi配置文件/usr/local/nginx/conf/uwsgi.ini

[uwsgi]
socket = 0.0.0.0:9000
master = true
pidfile = /usr/local/nginx/uwsgi.pid
processes = 8
chdir = /data/www/OMserverweb
pythonpath = /data/www
profiler = true
memory-report=true
enable-threads=true
logdate=true
limit-as=6048
daemonize=/data/logs/django.log

8.启动uwsgi和nginx服务。

/usr/bin/uwsgi --ini /usr/local/nginx/conf/uwsgi.ini
/usr/local/nginx/sbin/nginx

9.创建django项目

cd /data/www/
django-admin.py startproject OMserverweb

最后访问出现django欢迎界面表示配置成功。

你可能感兴趣的:(nginx,django,架构部署)