Start Your Django Project in Nginx with uWsgi

Step 0:Install A,B,C,blabla needed

This can be seen in my another article in the blog.click here(unavailable now,just in the future)

Step 1:Create A Django Project

chdir /path/to/your/project/base/

django-admin.py startproject mysite

Step 2:Create Your uwsgi congfigure files and Edit them

chdir /path/to/your/project/base/mysite

touch mysite_uwsgi.conf mysite_uwsgi.py mysite_uwsgi.ini mysite_mysite_uwsgi.pid uwsgi.pid

sudo ln -s /path/to/your/project/base/mysite/mysite_uwsgi.conf /etc/nginx/sites-enabled/ # so that this configuration can be included into nginx‘s conf

# sudo ln -s /path/to/your/project/base/mysite/mysite_uwsgi.conf /etc/nginx/sites-enabled/mysite_nginx.conf # another name is also ok!

## ------------------------------------------------------------------------------------------------------------------------

vim mysite_uwsgi.conf

# mysite_uwsgi.conf
server {
    listen         8000;
    server_name    10.10.10.132; # after all of these steps,type http://10.10.10.132:8000/ into your browser to get what you want(ps.10.10.10.132 if my IP)
    charset UTF-8;

    client_max_body_size 75M;

    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:8001; # nginx(not you) wiil get something from 127.0.0.1:8001 then return to you
        uwsgi_read_timeout 2;
    }
    location /static {
        expires 30d;
        autoindex on;
        add_header Cache-Control private;
        alias /path/to/your/project/base/mysite/mysite/static/;
     }
 }

  

# ln this file into the ‘/path/to/nginx/site-enable/‘ (have done in step 2 ‘sudo ln blablablabla‘)

## ------------------------------------------------------------------------------------------------------------------------

vim mysite_uwsgi.py

# mysite_uwsgi.pyimport os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

  

## ------------------------------------------------------------------------------------------------------------------------

vim mysite_uwsgi.ini

[uwsgi]
socket = :8001
master = true
module = mysite_uwsgi
processes = 8
listen = 120
enable-threads = true
daemonize = /path/to/your/project/base/mysite/mysite_uwsgi.log
pidfile = /path/to/your/project/base/mysite/mysite_uwsgi.pid
pythonpath = /path/to/your/project/base/mysite/
pythonpath = /path/to/your/project/base/mysite/mysite_uwsgi
pythonpath = /path/to/your/project/base/mysite/mysite
buffer-size = 32768
reload-mercy = 8
vacuum = true

After all of these above,we can go to Step 3.

Step 3:Restart Your Nginx Service And uWsgi service

Here list the Commonly used commands:
sudo /etc/init.d/nginx stop

sudo /etc/init.d/nginx start

sudo /etc/init.d/nginx restart

And in this step you just need to restart your nginx(if it is started before, or use start instead)

sudo /etc/init.d/nginx restart # restart nginx

chdir /path/to/your/project/base/mysite

uwsgi --socket 127.0.0.1:8001 --wsgi-file mysite_uwsgi.py # start uwsig service,if not,you will get a 502(Bad Gateway) error.

Tips:

  chdir /path/to/your/project/base/mysite

  uwsgi --http 10.10.10.132:8001 --wsgi-file mysite_uwsgi.py

  and then type http://10.10.10.132:8000/ in your browser to see if uwsgi work ok.if ok ,then shose socket

Tips:

  nginx + uwsgi

  apache + mod_wsgi

  nginx + apache + ???

 Step 4:Check If It is OK

Open your browser and type http://10.10.10.132:8000/ (10.10.10.132:8000 also ok)

And you will see the django‘s beautiful welcome page.

for more information:

tutorial from uwsgi.readthedocs.org:Django_and_nginx (follow it but failed,orz...)

tutorial from oschina.net:nginx + uwsgi + django (work)

时间: 2024-10-01 07:43:28

Start Your Django Project in Nginx with uWsgi的相关文章

基于nginx和uWSGI在Ubuntu系统上部署Django项目

1. nginx1.1 安装sudo apt-get install nginx1.2启动.停止和重启sudo /etc/init.d/nginx startsudo /etc/init.d/nginx stopsudo /etc/init.d/nginx restart或者sudo service nginx startsudo service nginx stopsudo service nginx restart2. uWSGI安装用python的pip安装最简单:apt-get inst

安装Django、Nginx和uWSGI

安装Django.Nginx和uWSGI 1.确定已经安装了2.7版本的Python: 2.安装python-devel yum install python-devel 3.安装uwsgi pip install uwsgi 测试uwsgi是否能正常工作 1.新建一个index.py: # index.py def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')])

nginx基于uwsgi部署Django (单机搭建)

nginx基于uwsgi部署Django (单机搭建) 参考链接: https://blog.51cto.com/wangfeng7399 https://blog.51cto.com/wangfeng7399/2341281 https://blog.csdn.net/shylonegirl/article/details/83030024 安装nignx yum -y install nginx (需要epel源) 安装依赖包 yum groupinstall "Development to

Docker手动构建 nginx+py3+uwsgi环境

前述 这里使用的阿里云服务器部署,云服务器ssh登陆成功后,如果几分钟没有操作的话,sshd会自动断开登陆,对于我们来说,在部署软件有时要等很久,经常会发生ssh断开的情况,又或是上个侧所回来ssh就断开了,非常头痛. 这里我们要先解决ssh断开连接的问题 # egrep ^Client /etc/ssh/sshd_configClientAliveInterval 15 --间隔多少秒发送一次心跳ClientAliveCountMax 1800 --多少秒没有数据产生时断开连接 部署py3+u

Apache:To Config The Vhost of Django Project

It is not a good idea to use dev server in Production Environment. Apache or Nginx are good choice.Both of them are of great used as the web server. I'm trying to deploy in apache. The File Structre: If you've read djangoproject's documentation,you w

第一个 Django Project开发

本篇文章是 官网https://docs.djangoproject.com/en/1.7/intro/tutorial01/" 的实践版本.由于原文有较多的解释成分以及用英语书写不便于快速进入Django的开发.所以才有本文. Part 1. 环境搭建测试 如需转载请注明出处:*************************** 谢谢. 1. 环境 Ubuntu 13.10    # cat /etc/issue  进行查看 Python 3.3.2+   # python -V      

[Python] Create a new Django project in Pycharm

From: http://blog.csdn.net/u013088062/article/details/50158239     创建新工程 1.主题 这部分教程主要介绍如何通过Pycharm创建.管理.运行一个Django工程. Django是一个开放源代码的Web应用框架,由Python写成.采用了MVC的软件设计模式,即模型M,视图V和控制器C. 2.准备工作 (1)Pycharm为3.0或者更高版本. (2)电脑上至少安装了一个Python解释器,2.4到3.3版本均可. 这部分教程

如何使用Nginx和uWSGI或Gunicorn在Ubuntu上部署Flask Web应用

我在很多的博客中都看过有关Flask应用的部署,也有很多博主在开博后都记录了部署的教程,因为其中的坑可以说不少.一开始我在网上看到相比较与Ubuntu,CentOS因为更新少作为服务器的操作系统会更加稳定.所以在第一次购买云服务器时,我选择了CentOS,后来由于CentOS不同发行版的Nginx缘故,我又换成了Ubuntu的镜像 首先呢,我们先来了解下关于Web服务器与Web应用还有WSGI之间的联系 一.介绍 WSGI(Web Server Gateway Interface),翻译为Pyt

使用Nginx和uwsgi部署Flask项目

前言 之前用Flask框架开发了一个Python的Web项目,使用Nginx和uWSGI部署起来感觉挺麻烦,过程中还因为对Flask框架的不熟悉,花了好长时间才把应用完全部署起来.下面分享部署成功的相关配置以及部署Flask项目时极可能犯的一个小错误. 一. 配置 1. Flask Web项目源码 Nginx使用的版本是1.6.1,uWSGI是2.0.8,Flask是0.10.1.在Linux环境下安装好Nginx.uWSGI和Flask之后,将使用Flask框架开发的web项目源码放到Linu