nginx+uwsgi+django+python 應用架構部署

系統centos6.5html

1,安裝配置nginx 和Pythonpython

yum install nginx

python 默認安裝的是2.6 須要升級到2.7見教程linux

2,django 安裝nginx

下載當前最新的版本:Django-1.8.5.tar.gzdjango

$ wget --no-check-certificate https://www.djangoproject.com/download/Django-1.8.5.tar.gz
(備註:--no-check-certificate 免證書認證,否則下載不了https資源)
$ tar zxf Django-1.8.5.tar.gz
$ cd Django-1.8.5
$ python setup.py install
[root@LinuxOT-Test-02 dj17]# python Python 2.7.3 (default, Jan  5 2013, 10:09:00) [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import django>>> django.VERSION(1, 8, 5, 'final', 0)

說明django安裝成功了。vim

3,新建django項目centos

[root@LinuxOT-Test-02 nginx]# mkdir www
[root@LinuxOT-Test-02 nginx]# cd www
[root@LinuxOT-Test-02 www]# django-admin startproject mysite
[root@LinuxOT-Test-02 www]# tree mysite
/mysite/
├── manage.py
└── mysite    
├── __init__.py    
├── settings.py    
├── urls.py    
└── wsgi.py1 
directory, 5 files
[root@LinuxOT-Test-02 www]# cd mysite/
[root@LinuxOT-Test-02 mysite]# python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have unapplied migrations; your app may not work properly until they are applied.Run 'python manage.py migrate' to apply them.
October 13, 2015 - 09:50:28
Django version 1.8.5, using settings 'mysite.settings'Starting development server at 
 Quit the server with CONTROL-C.
[root@LinuxOT-Test-02 mysite]# python manage.py migrate
Operations to perform:  Synchronize unmigrated apps: staticfiles, messages  
Apply all migrations: admin, contenttypes, auth, sessionsSynchronizing apps without migrations:  Creating tables...    
Running deferred SQL...  
Installing custom SQL...
Running migrations:  Rendering model states... DONE  
Applying contenttypes.0001_initial... OK  
Applying auth.0001_initial... OK  
Applying admin.0001_initial... OK  
Applying contenttypes.0002_remove_content_type_name... OK  
Applying auth.0002_alter_permission_name_max_length... OK  
Applying auth.0003_alter_user_email_max_length... OK  
Applying auth.0004_alter_user_username_opts... OK  
Applying auth.0005_alter_user_last_login_null... OK  
Applying auth.0006_require_contenttypes_0002... OK  
Applying sessions.0001_initial... OK
[root@LinuxOT-Test-02 mysite]# python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
October 13, 2015 - 09:51:25Django version 1.8.5, using settings 'mysite.settings'Starting development server at 
 Quit the server with CONTROL-C.
[root@LinuxOT-Test-02 dj17]# curl http://127.0.0.1:8000


響應正常bash

4,安裝uwsgisession

下載地址http://uwsgi-docs.readthedocs.org/en/latest/Download.htmlapp

[
root@LinuxOT-Test-02
 dj17]# wget 
http://projects.unbit.it/downloads/uwsgi-2.0.11.2.tar.gz


對於Python/wsgi的支持。

安裝uwsgi模塊

[root@LinuxOT-Test-02 mysite]# pip install uwsgi
Collecting uwsgi/usr/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see insecureplatformwarning.  
InsecurePlatformWarning  
Downloading uwsgi-2.0.11.2.tar.gz (782kB)    
100% |████████████████████████████████| 782kB 413kB/s Installing collected packages: uwsgi  
Running setup.py install for uwsgi
Successfully installed uwsgi-2.0.11.2
[root@LinuxOT-Test-02 mysite]# pip install 
 Collecting http://projects.unbit.it/downloads/uwsgi-lts.tar.gz  
 Downloading http://projects.unbit.it/downloads/uwsgi-lts.tar.gz (782kB)    
 100% |████████████████████████████████| 782kB 22kB/s   
 Requirement already satisfied (use --upgrade to upgrade): uWSGI==2.0.11.2 from http://projects.unbit.it/downloads/uwsgi-lts.tar.gz in /usr/lib/python2.7/site-packages

 yum install python-devel2.7
[root@LinuxOT-Test-02 .test]# tar zxf uwsgi-2.0.11.2.tar.gz 
[root@LinuxOT-Test-02 .test]# cd uwsgi-2.0.11.2
[root@LinuxOT-Test-02 uwsgi-2.0.11.2]# python uwsgiconfig.py --build
[root@LinuxOT-Test-02 uwsgi-2.0.11.2]# uwsgi --version2.0.11.2
[root@LinuxOT-Test-02 uwsgi-2.0.11.2]# cp uwsgi /usr/sbin/uwsgi

5,關聯django到nginx

vim /etc/nginx/conf.d/default.conf
server {
    listen       80 default_server;
    server_name  _;
    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:9090;
    }
}
[root@LinuxOT-Test-02 uwsgi-2.0.11.2]# service nginx restart
中止 nginx:                      [肯定]
正在啓動 nginx:                    [肯定]
[root@LinuxOT-Test-02 mysite]# uwsgi -s 127.0.0.1:9090 -w demo

         啓動項目

訪問nginx的地址便可

相關文章
相關標籤/搜索