django2.1+uwsgi+nginx部署

1安装uwsgi

pip3 install uwsgi

2安装nginx

sudo apt install nginx -y

3配置uwsgi与nginx连接

在项目根目录下执行命令:  (注意:后面这个空格+点儿别落下)

cp /etc/nginx/uwsgi_params .

4配置uwsgi.ini

vim uwsgi.ini

然后加入以下内容:

[uwsgi]

chdir=/home/admin/community

module=community.wsgi:application

master=true

processes=5

socket=:8001

chmod-socket = 666

vacuum=true

5配置nginx

#cd 到项目目录下

vim community.conf
#粘贴以下内容

upstream django {

    # server unix:/root/xueyiwang/xueyiwang.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      8000;

    # the domain name it will serve for

    server_name 你自己的公网IP; # 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 /你自己的项目根目录/media;  # your Django project‘s media files - amend as required

    }

    location /static {

        alias /你自己的项目根目录/static_common;  # your Django project‘s static files - amend as required

    }

    # Finally, send all non-media requests to the Django server.

    location / {

        uwsgi_pass  django;

        include   /你自己的项目根目录/uwsgi_params; # the uwsgi_params file you installed

    }

}

6建立软链接

sudo ln -s /你自己的项目根目录/community.conf  /etc/nginx/sites-enabled/

7收集静态文件

#cd 到项目目录下执行命令

python manage.py collectstatic

将项目的所以静态文件收集到STATIC_ROOT指定的目录里

8修改setting.py

ALLOWED_HOSTS = [‘公网IP‘] #自己的服务器公网IP

DEBUG = False

#在最底追加

STATIC_ROOT=os.path.join(BASE_DIR,"static_common").replace("\\ ","/")

9在项目根目录下执行命令

创建数据库表

python manage.py migrate 

10在项目根目录下执行命令:

cd ..

sudo service nginx restart      #重启nginx

uwsgi --ini uwsgi.ini           #启动uwsgi

转:https://www.cnblogs.com/xuepangzi/p/9219207.html

原文地址:https://www.cnblogs.com/CodingLife-190505/p/12273707.html

时间: 2024-07-29 16:09:04

django2.1+uwsgi+nginx部署的相关文章

Django+uWSGI+Nginx 部署网站

Django 1.11设置 保证Django在本地调试没有问题: 当然这是前提^_^ 收集静态文件至指定文件夹 Django静态文件设置具体参考:https://docs.djangoproject.com/en/1.11/ref/contrib/staticfiles/ 在myproject/settings.py中设置静态文件STATIC_URL和STATIC_ROOT设置: 如: STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE

django+uwsgi+nginx部署(非常详细)

django+uwsgi+nginx部署 1.介绍: 在网上看了很多教程,但自己部署了很久都没有成功,这篇博文记录自己所踩过得坑. 2.环境: 1 Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-130-generic x86_64) 3.下载uwsgi以及nginx 1 apt-get install uwsgi 2 apt-get install nginx (注:如果下载异常出现权限问题,在命令前添加sudo) 4.创建Django项目 例如:项目名为mysite

vue+uwsgi+nginx部署前后端分离项目

一:vue+uwsgi+nginx部署 1.1:准备代码: # 路飞学城django代码 https://files.cnblogs.com/files/pyyu/luffy_boy.zip # vue代码 https://files.cnblogs.com/files/pyyu/07-luffy_project_01.zip 1.2:部署准备 1. 部署环境准备 ⑴ . 准备python3和虚拟环境解释器,python3,virtualenvwrapper. pip3 install -i h

Django+uWsgi+nginx部署

一.环境 操作系统:Ubuntu 14.04 64位 python:2.7.6 Django:1.8.2 项目源码:https://github.com/youchuancong/django.git 部署方式:Django+uWsgi+nginx 二.部署 1.Django安装 官网:https://www.djangoproject.com/ 安装 wget https://www.djangoproject.com/m/releases/1.8/Django-1.8.2.tar.gz ta

CentOS下实现Flask + Virtualenv + uWSGI + Nginx部署

一.项目简介 在本文中,将一步一步搭建一个简单的Flask + Virtualenv + uWSGI + Nginx 架构的Web服务,可以作为新手的学习也可作为记录备忘. 如果你安装好了环境并有一定基础可以直接从第五节开始部署. 项目中只是演示了浏览器访问地址,获得文本返回的过程,本人尽量把配置解释的清晰.基于搭建好的架构,后续可以将业务层(Python)进行扩展,本文不做研究 ,比如: 1.扩展业务代码:实现json.静态资源等等的请求响应. 2.基于业务的数据库查询和部署. 3.服务器端的

mac+django(1.8.2)+uwsgi+nginx 部署

一. uwsgi 安装 检验 配置uwsgi.ini 1. 安装 pip3 install uwsgi 2. 检验 方法一(uwsgi启动文件): test.py内容如下: def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"] uwsgi --http 0.0.0.0:8000 --wsgi-file t

CentOS + Python3.6+ Django2.0 + uwsgi + nginx + mysql web发布环境搭建

目录: CentOS上升级Python 安装easy_install和pip uwsgi安装及测试 Django安装及测试 连接uwsgi与Django nginx安装及测试 连接uwsgi与nginx 连接uwsgi与Django与nginx uwsgi ini mysql安装设置 python3 Django mysql连接及测试 快速搭建blog测试 Pycharm开发 如果只是想学习django开发直接用django本身自带的开发用服务器即可. 1. CentOS上升级Python 用的

uwsgi+nginx部署django项目

1. 概念解析(wsgi协议,uwsgi协议,uWSGI) 参考:https://www.cnblogs.com/wspblog/p/8575101.html 1.1 现实世界的web请求: 1.2  wsgi协议,uwsgi协议和uWSGI a. WSGI(wsgi): 全称 Web Server Gateway Interface,或者 Python Web Server Gateway Interface ,是为 Python 语言定义的 Web 服务器和 Web 应用程序或框架之间的一种

uwsgi + nginx 部署python项目(一)

uWSGI uWSGI是一个Web服务器,它实现了WSGI协议.uwsgi.http等协议.Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换. 要注意 WSGI / uwsgi / uWSGI 这三个概念的区分. WSGI是一种通信协议,Flask,webpy,Django.CherryPy等等都自带WSGI,不过性能都不好. uwsgi同WSGI一样是一种通信协议. 而uWSGI是实现了uwsgi和WSGI两种协议的Web服务器. 为什么有了uWSGI为什么还需要n