django-nginx与uwsgi项目部署

uwsgi是提供动态服务的

nginx反向代理

在项目中创建一个settings.py的副本。我这里重命名为copy_settings.py,将配置文件中的DEBUG=False

django-nginx与uwsgi项目部署

修改项目下wsgi.py的启动配置文件名称

django-nginx与uwsgi项目部署

环境配置:

第一步:在Linux系统中创建一个运行虚拟环境 执行:mkvirtualenv -p /usr/bin/python3.6 copymysite

django-nginx与uwsgi项目部署

第二步:将开发项目中虚拟环境中的依赖包安装到创建的这个虚拟环境中

2-1:首先进入开发项目的虚拟环境中导出包列表

django-nginx与uwsgi项目部署

查看项目依赖的包

django-nginx与uwsgi项目部署

2-2 在新创建的正式虚拟环境中安装上面的包(如果上面有些包是通过离线包安装的,就需要从列表中删除,然后通过离线包安装)

django-nginx与uwsgi项目部署

查看安装的包就和开发环境中的包是一样的

django-nginx与uwsgi项目部署

第三步:安装uwsgi

django-nginx与uwsgi项目部署

测试uwsgi是否安装成功,在项目中创建一个deploy文件夹,在里面创建一个测试文件test.py文件

django-nginx与uwsgi项目部署

执行测试命令,一定要进入到当前测试文件的路径中

django-nginx与uwsgi项目部署

浏览器测试:

django-nginx与uwsgi项目部署

第四步:配置uwsgi,在deploy文件中创建一个uwsgi_conf.ini文件和logs文件夹,配置内容如下:

django-nginx与uwsgi项目部署

第五步:启动uwsgi,进入虚拟环境切换到项目中的deploy文件目录中

启动uwsgi:uwsgi –ini uwsgi_conf.ini &

停止uwsgi:uwsgi –stop uwsgi.pid

sudo pkill -f uwsgi 全部停止后uwsgi 会自动重启

查看状态

ps aux|grep uwsgi

第六步:Nginx安装与配置

6-1:安装nginx 首先执行 sudo apt update -y

django-nginx与uwsgi项目部署

执行安装:sudo apt install nginx -y

django-nginx与uwsgi项目部署

开启和查看开启状态:

django-nginx与uwsgi项目部署

测试:

django-nginx与uwsgi项目部署

第七步:项目中添加nginx配置文件,在deploy文件夹中创建nginx_conf.conf配置文件,内容如下:

7-1

django-nginx与uwsgi项目部署

Nginx配置文件

bash;gutter:true; 启动该程序的默认程序</p> <h1>user nobody;</h1> <p>一个主进程和多个工作进程。这里定义的是主进程数量 worker_processes 4;</p> <p>全局错误日志的位置及日志格式</p> <h1>error_log logs/error.log;</h1> <h1>error_log logs/error.log notice;</h1> <h1>error_log logs/error.log info;</h1> <h1>pid logs/nginx.pid;</h1> <p>events { # 每个工作进程最大并发数 worker_connections 1024; }</p> <p>http 服务设置 http { include mime.types; default_type application/octet-stream;</p> <pre><code># 日志格式 #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; # access_log logs/access.log main; # 全局日志路径 # $remote_addr与$http_x_forwarded_for用以记录客户端ip地址 # $remote_user:记录客户端名称 # $time_local:记录访问时间与时区 # $request:记录访问状态 200成功 # $body_bytes_sent:记录发送给客户端文件主体内容大小 # $http_referer:记录从哪个页面链接访问过来的 # $http_user_agent:记录客户端浏览器相关信息 # sendfie指令指定nginx是否调用sendfile函数(zero copy 方式)来输出文件 sendfile on; # 允许或禁止使用socke的TCP_CORK的选项仅在使用sendfile的时候使用 #tcp_nopush on; # 长连接超时时间 #keepalive_timeout 0; keepalive_timeout 65; # 开启压缩 #gzip on; # 配置虚拟主机 server { # 虚拟主机使用的端口 listen 80; # 主机域名 server_name localhost; # 支持的字符集 #charset koi8-r; #访问日志路径 #access_log logs/host.access.log main; # 定义web根路径 location / { # 根目录路径 root html; # 索引页面 index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # 根据错误码返回对应的页面 error_page 500 502 503 504 /50x.html; # location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} </code></pre> <p>}

7-2:将上面创建的配置文件复制到 /etc/nginx/conf.d文件夹中去或者加入到配置中

注意:将该配置文件加入到nginx的启动配置文件中 获取覆盖原配置文件

sudo ln -s 你的目录/mysite/deploy/nginx_conf.conf

django-nginx与uwsgi项目部署

7-3:如果是第一次使用nginx 需要添加用户到nginx.conf 配置文件中

django-nginx与uwsgi项目部署

7-4:测试nginx配置文件是否正确

django-nginx与uwsgi项目部署

7-5:重新加载配置

sudo nginx -c /etc/nginx/nginx.conf

sudo nginx -s reload

重启nginx sudo systemctl restart nginx

重启第二中方式:

pkill -f ninx

nginx

完成部署,在浏览器中输入IP地址即可访问网站了……..

设置开机启动

sudo systemctl enable nginx.service

Original: https://www.cnblogs.com/wendj/p/11065285.html
Author: begrateful
Title: django-nginx与uwsgi项目部署

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/576506/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • JavaWeb核心篇(2)——Request和Response

    JavaWeb核心篇(2)——Request和Response 上篇文章中提及到了Servlet,在Servlet中我们主要继承了HTTPServlet类,在HTTPServlet…

    数据库 2023年6月14日
    0119
  • Nginx基础入门篇(1)—优势及安装

    一、Nginx 的优势 1.1发展趋势: 2016年: 1.2、简介 Nginx (engine x) 是一个高性能的HTTP(解决C10k的问题)和反向代理服务器,也是一个IMA…

    数据库 2023年6月14日
    087
  • ReentrantLock 公平锁源码 第0篇

    ReentrantLock 0 关于ReentrantLock的文章其实写过的,但当时写的感觉不是太好,就给删了,那为啥又要再写一遍呢 最近闲着没事想自己写个锁,然后整了几天出来后…

    数据库 2023年6月16日
    092
  • Selenium 4 有哪些不一样?

    转载请注明出处❤️ 作者:测试蔡坨坨 原文链接:caituotuo.top/d59b986c.html 你好,我是测试蔡坨坨。 众所周知,Selenium在2021年10月13号发…

    数据库 2023年6月11日
    0105
  • mybatis缓存

    加上flushCache=”true”后,再次运行结果如下 2.二级缓存 mybatis的二级缓存默认开启,但真正使用需要在mapper文件中添加相应的缓存…

    数据库 2023年6月16日
    097
  • keycloak~资源的远程授权

    17.1远程资源授权准备 17.1.1认证和访问流程图 参考:http://www.zyiz.net/tech/detail-141309.html 17.1.2为用户指定角色 可…

    数据库 2023年6月6日
    0104
  • 多线程

    public class 多线程 { static boolean flag = true; static class t1 implements Runnable{ @Overr…

    数据库 2023年6月16日
    0118
  • 一个属性同时使用Autowired和Resource注解会发生什么?

    首发于公众号:BiggerBoy右侧图片wx扫码关注有惊喜欢迎关注,查看更多技术文章 如题,如果在同一个属性上使用@Autowired注解注入bean1,然后使用@Resource…

    数据库 2023年6月11日
    0100
  • SQL基础一

    一、SQL基本术语 数据库管理系统(DBMS,database management system)。人们通常用数据库这个术语来代表他们使用的数据库软件,这是不正确的。确切地说,数…

    数据库 2023年6月16日
    097
  • Linux 的应用安装,升级和卸载和Linux下更换yum源的方法

    Linux 的应用安装,升级和卸载 yum [-y] install &#x8F6F;&#x4EF6;&#x5305;&#x540D; (1)yum…

    数据库 2023年6月16日
    096
  • windows安装mysql8.0.29(ZIP解压安装版本)

    一. 下载mysql 8.0.29软件包 二. 解压,初始化安装 1,打开下载后文件所在目录,使用解压软件解压,打开文件夹!(如图,文件路径不要出现中文!) 2,创建my.ini文…

    数据库 2023年5月24日
    099
  • Typora 开始收费,改用好玩的MarkText

    收费…… 可以考虑使用: MarkText 简述MarkText MarkText 这个工具侧重于”命令”,导航栏都被收起来了。有些…

    数据库 2023年6月6日
    0141
  • 高并发组件了解

    消息队列 A服务和多个服务耦合,内部维护对多个服务发送数据的接口,那么这些接口如果有的挂了,有的不需要了,那么还得修改A内部的代码,如果使用MQ,A发送消息就好,不必考虑那么多事情…

    数据库 2023年6月16日
    075
  • 常见的攻击方式以及防护策略

    本文主要给大家介绍一下常见的几种网络攻击方式(包括CC,UDP,TCP)和基础防护策略! 1.0 常见的网络攻击方式 第一种CC攻击 CC攻击( ChallengeCoHapsar…

    数据库 2023年6月9日
    0100
  • Linux–>vi和vim编辑器的基本操作

    vim编辑器介绍 vi或者vim就是对linux下的文本进行编辑的一种编辑器比如说a.cpp文件这种 Linux会内置vi文本编辑器 Vim可以简单的认为vi的增强版 Linux是…

    数据库 2023年6月14日
    0100
  • Nginx基础入门篇(2)—编译参数介绍

    查看命令 nginx -V nginx version: nginx/1.22.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (…

    数据库 2023年6月14日
    0101
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球