• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Ubuntu 14.04+Django 1.7.1+Nginx+uwsgi部署教程

Ubuntu 14.04+Django 1.7.1+Nginx+uwsgi部署教程

作者:hebedich 字体:[增加 减小] 来源:互联网

hebedich 通过本文主要向大家介绍了django uwsgi,nginx uwsgi django,uwsgi,nginx uwsgi,python uwsgi等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

具体环境:
Ubuntu 14.04 Python 2.7.6 Django 1.7.1 Virtualenv name:test Nginx uwsgi

假设 项目文件夹位于 /data/www/ts 设置保存在 ./conf

virtualenv name = test
domain name = example.com
</div>

django+uwsgi的部署实在是太蛋疼了..网上已有的教程似乎有新版本的兼容问题。最后跑到uwsgi官网上找的教程终于跑通了..
不过官网的教程似乎有引导教学性质,部署的时候就显得很绕弯路,在这里记录下来精简内容

http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

首先,需要一个uwsgi_params文件,放在项目的conf文件夹里面。之后需要指向它。文件内容如下:

uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
</div>

创建一个叫做ts_nginx.conf 的文件,内容如下

# ts_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen 80;
    # the domain name it will serve for
    server_name .example.com; # substitute your machine's IP address or FQDN
    charset utf-8;

    # max upload size
    client_max_body_size 75M; # adjust to taste

    # Django media
    location /media {
        alias /data/www/ts/media; # your Django project's media files - amend as required
    }

    location /static {
        alias /data/www/ts/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass django;
        include /data/www/ts/conf/uwsgi_params; # the uwsgi_params file you installed
    }
}
</div>

把这个conf文件连接到nginx的搜索目录里面。

sudo ln -s /data/www/ts/conf/ts_nginx.conf /etc/nginx/sites-enabled/
</div>

先决条件:这里要设置好django项目的settings里面static files

STATIC_ROOT = os.path.join(BASE_DIR, "static/")
and then run

python manage.py collectstatic
</div>

之后:

service nginx restart
</div>

应该就可以看到
http://example.cn:8000/media/1.gif
了(事先放进去一个静态文件)

之后的blabla步骤都是废话,跳到这里:

Configuring uWSGI to run with a .ini file
</div>

ts_uwsgi.ini 在项目根目录

[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /data/www/ts
# Django's wsgi file
module = ts.wsgi
# the virtualenv (full path)
home = /root/.envs/test
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = 127.0.0.1:8001
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
# set an environment variable
env = DJANGO_SETTINGS_MODULE=conf.settings
uwsgi --ini mysite_uwsgi.ini # the --ini option is used to specify a file
</div>

这里环境变量设置env需要conf文件夹有init.py,否则conf不会被认为是module

(目前除了80端口,其他端口都可以通过地址:端口访问。已经测试8000,81.80测试不知道为什么不成。明天待续)

</div>

您可能想查找下面的文章:

  • 解决uWSGI的编码问题详解
  • 解决uWSGI的编码问题详解
  • 在Debian下配置Python+Django+Nginx+uWSGI+MySQL的教程
  • 在Debian下配置Python+Django+Nginx+uWSGI+MySQL的教程
  • Ubuntu 14.04+Django 1.7.1+Nginx+uwsgi部署教程

相关文章

  • Django imgareaselect手动剪切头像实现方法
  • python安装PIL模块时Unable to find vcvarsall.bat错误的解决方法
  • Python数据类型详解(四)字典:dict
  • 使用Python绘制图表大全总结
  • Python操作Excel之xlsx文件
  • Python生成验证码实例
  • python语言使用技巧分享
  • Python常用模块介绍
  • python使用xmlrpc实例讲解
  • 深入理解NumPy简明教程---数组2

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • python获取一组数据里最大值max函数用法实例
    • python多进程共享变量
    • Python编程判断这天是这一年第几天的方法示例
    • Python设计模式编程中解释器模式的简单程序示例分享
    • Python中绑定与未绑定的类方法用法分析
    • Python判断直线和矩形是否相交的方法
    • Python常用正则表达式符号浅析
    • Python中__init__和__new__的区别详解
    • python中assert用法实例分析
    • 九步学会Python装饰器

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有