部署踩坑

提前准备

在本地能够 python(3) manage.py runserver

服务器端准备

安装nginx

为了防止python的某些包没有安装

请先 sudo apt-get install python-dev

然后 sudo apt-get install nginx

使用uwsgi部署

求求你了 别用uwsgi 玩了4个小时 试了不下15种配置方法 无功而返

现在还没有solution 跳过

使用gunicorn配置

相比于uwsgi, guncorn不能再好

先进入虚拟环境source /path/to/env/bin/active

再安装gunicornsudo pip(3) install gunicorn

/path/to/env/bin/gunicorn --chdir /path/to/project --pythonpath /path/to/env/ -w4 -b0.0.0.0:8017 project.wsgi:application

这边用的8017端口

配置nginx

新建一个配置文件sudo vim /etc/nginx/sites-available/your_conf.conf

your_conf.conf中写下如下内容:

server {
  listen     80;
  server_name your_domain_name.com;
  charset     utf-8;   client_max_body_size 75M;   location /media {
      alias /path/to/project/media;
  }   location /static {
      alias /path/to/project/static;
  }   location / {
      uwsgi_pass unix:///home/tu/zqxt/zqxt.sock;
      include     /etc/nginx/uwsgi_params;
  }
}

listen默认一般都是80端口, 如果没有media文件就不配置,这个static文件夹是运行python(3) manage.py collectstatic后生成的文件夹,因为没有用到uwsgi,所以uwsgi_pass看心情随缘,include按照这个来.

然后复制到/sites-enabled/中: sudo ln -s /etc/nginx/sites-available/your_conf.conf /etc/nginx/sites-enabled/your_conf.conf

ps: nginx配置一般都在/etc/nginx/中,/sites-available/里面保存你可能要用到的configure文件

/sites-enabled/保存目前生效的configure文件

配置django中的路径url

如果不配置这个会找不到static文件夹

from django.conf.urls.static import static
from your_project import settings

urlpatterns = [
   # your path here
   path('admin/', admin.site.urls, name='admin'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

这是Django 2.0版本之后才有的,详情请见官方文档 https://docs.djangoproject.com/en/2.0/ref/urls/

然后 service nginx restart重启nginx,就可以看到了网页了.

(注意只能在gunicorn中配置的端口访问 eg: your_domain_name.com:8017)

nginx + gunicorn + django 2.0 踩坑的更多相关文章

  1. manjaro xfce 18.0 踩坑记录

    manjaro xfce 18.0 踩坑记录 1 简介1.1 Manjaro Linux1.2 开发桌面环境2 自动打开 NumLock3 系统快照3.1 安装timeshift3.2 使用times ...

  2. Win10 安装配置 MongoDB 4.0 踩坑记

    redis 官方没有 Windows 版的,微软维护的已经好久没更新了,所以就在想着换成 MongoDB. 于是一趟被我复杂化的踩坑之旅就开始了,同时也记录一下,避免有人遇见跟我一样的问题. 首先在  ...

  3. vue2.0 踩坑记录之组件

    - did you register the component correctly? For recursive components, make sure to provide the " ...

  4. 使用Centos7.5+Nginx+Gunicorn+Django+Python3部署blog项目

    项目开发环境是 Python3.5.2+Django1.10.6+Sqlite3+Centos7.5+Nginx1.12.2+Gunicorn 发布出来供需要的同学借鉴参考.文中如有错误请多多指正! ...

  5. Django线上部署实战教程之Nginx+Gunicorn+Django篇

    #############################################   推荐 nginx supervisor gunicorn  配置简单,运维方便. Nginx (engi ...

  6. .NET CORE 2.0 踩坑记录之ConfigurationManager

    在之前.net framework 中使用的ConfigurationManager还是很方便的,不过在.NET CORE 2.0中SDK默认已经不存在ConfigurationManager. 那么 ...

  7. pytorch-1.0 踩坑记录

    参加百度的一个竞赛,官方要求把提交的代码测试环境pyorch1.0,于是将自己计算机pytorch升级到1.0. 在ubuntu下用conda install pytorch 命令安装时,效果很差,解 ...

  8. springMvc改造springboot2.0踩坑

    1. 支持jsp applicaiton.proerties添加配置 #指定视图解析路径前缀 spring.mvc.view.prefix=/WEB-INF/jsp/ #指定视图解析后缀 spring ...

  9. Visual C++ 6.0踩坑记录---在Win10下安装Visual C++ 6.0安装成功后点击“打开”按钮闪退问题

    前言: 为了更好的学习C及C++,前段时间下载了Microsoft Visual C++ 6.0(以下简称VC6),原因是VC6具有查看反汇编代码.监视内存.寄存器等功能,并且因为本人正在学习滴水逆向 ...

随机推荐

  1. Linux下安装git本地库与服务器端远程库

    1.    git是一个分布式版本管理系统,关于该工具的详细介绍,我认为廖雪峰老师介绍的非常全面:https://www.liaoxuefeng.com/wiki/896043488029600. 不 ...

  2. 2018-8-10-win10-uwp-httpClient-登陆CSDN

    title author date CreateTime categories win10 uwp httpClient 登陆CSDN lindexi 2018-08-10 19:16:53 +080 ...

  3. 2018-2-22-在-windows-安装-Jekyll

    title author date CreateTime categories 在 windows 安装 Jekyll lindexi 2018-02-22 17:47:39 +0800 2018-2 ...

  4. 服务器修改静态ip

    ifconfig,看当前网卡名字 设置 ip地址,子网掩码 ,广播地址 ifconfig eth1 172.16.11.25 netmask 255.255.255.0 broadcast 172.1 ...

  5. mysql基于Altas读写分离并实现高可用

    实验环境准备: master:192.168.200.111 slave1:192.168.200.112 slave2:192.168.200.113 Altas:192.168.200.114 c ...

  6. 函数传递是如何让HTTP服务器工作的

    var http = require("http"); http.createServer(function(request, response) { response.write ...

  7. java--substring内存溢出问题

    public class SubStringDemo { //substring() /** * jdk6 当调用 substring() 方法时,创建了一个新的String对象,但是string的v ...

  8. 【leetcode】934. Shortest Bridge

    题目如下: In a given 2D binary array A, there are two islands.  (An island is a 4-directionally connecte ...

  9. django 邮箱发送

    在django中提供了邮件接口 QQ邮箱配置 qq邮箱地扯:https://mail.qq.com settings文件 # 邮箱配置 EMAIL_USE_SSL = True EMAIL_HOST ...

  10. 阿里云HBase推出普惠性高可用服务,独家支持用户的自建、混合云环境集群

    HBase可以支持百TB数据规模.数百万QPS压力下的毫秒响应,适用于大数据背景下的风控和推荐等在线场景.阿里云HBase服务了多家金融.广告.媒体类业务中的风控和推荐,持续的在高可用.低延迟.低成本 ...