共计 4518 个字符,预计需要花费 12 分钟才能阅读完成。
系统 CentOS 6.5
1,安装配置 nginx 和 Python
yum install nginx
python 默认安装的是 2.6 需要升级到 2.7 见教程
2,django 安装
下载当前最新的版本:Django-1.8.5.tar.gz
$ 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 安装成功了。
3,新建 django 项目
[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
响应正常
4,安装 uwsgi
下载地址 http://uwsgi-docs.readthedocs.org/en/latest/Download.html
[
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 的地址即可
如何使用 Docker 组件开发 Django 项目?http://www.linuxidc.com/Linux/2015-07/119961.htm
Ubuntu Server 12.04 安装 Nginx+uWSGI+Django 环境 http://www.linuxidc.com/Linux/2012-05/60639.htm
Django+Nginx+uWSGI 部署 http://www.linuxidc.com/Linux/2013-02/79862.htm
Django 实战教程 http://www.linuxidc.com/Linux/2013-09/90277.htm
Django Python MySQL Linux 开发环境搭建 http://www.linuxidc.com/Linux/2013-09/90638.htm
Django 的详细介绍 :请点这里
Django 的下载地址 :请点这里
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-10/124183.htm