django2.2.4项目 部署 centos7.3 环境, tomcat与nginx相互切换

简介: django2.2.4项目 部署 centos7.3 环境, tomcat与nginx相互切换

更新一篇如何将 django2.2.4项目 部署 centos7.3 环境的博客

大致细节参考这篇文章,过程中会遇到以下问题

将django部署到服务器详细过程

uwsgi -x 命令报错, 在没有安装,相关依赖包时会报错,

nginx 配置文件出错会报错

启动项目前进入虚拟环境

[root@iZips92kqeqhgjZ ~]# cd /data/env/pyweb/bin
[root@iZips92kqeqhgjZ bin]# source activate
(pyweb) [root@iZips92kqeqhgjZ bin]# 


出现pyweb 说明加载 python虚拟环境成功。

修改setting

修改ALLOWED_HOSTS,[’*’],可以让任何IP访问

进入django项目目录

编写uwsgi 配置文件,并激活

 cd /data/wwwroot/Logistics
      vi /data/wwwroot/Logistics/Logistics.xml
      uwsgi -x Logistics.xml

编写nginx配置文件

cd /usr/local/nginx/conf/
vi nginx.conf

测试nginx配置文件,并启动nginx,以及停止与重新启动

(pyweb) [root@iZips92kqeqhgjZ conf]# cd /usr/local/nginx/sbin
#退出
(pyweb) [root@iZips92kqeqhgjZ sbin]# ./nginx -s quit
#检测配置文件语法,以及是否成功
(pyweb) [root@iZips92kqeqhgjZ sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
#正常启动不会有任何提示
(pyweb) [root@iZips92kqeqhgjZ sbin]# ./nginx


#重启,当项目文件更新时,需要重新启动nginx 以及 uwsgi

#重新生效 项目的 xml配置文件

(pyweb) [root@iZips92kqeqhgjZ sbin]#   cd /data/wwwroot/Logistics
(pyweb) [root@iZips92kqeqhgjZ Logistics]#      uwsgi -x Logistics.xml
[uWSGI] parsing config file Logistics.xml
(pyweb) [root@iZips92kqeqhgjZ conf]# cd /usr/local/nginx/sbin
(pyweb) [root@iZips92kqeqhgjZ sbin]# ./nginx -s reload


关于数据库迁移

#导出Mysql,django为你的数据库
mysqldump -uroot -ppassword django_1>django_1.sql
#把django.sql上传到服务器,在服务器里用下面命令导入
mysql -uroot -p;
create database django_1;
use dajngo_1;
source your Path\django_1.sql

停止tomcat与启动tomcat

停止与启动nginx

(pyweb) [root@iZips92kqeqhgjZ home]# sh /home/tomcat/apache-tomcat-9.0.21/bin/shutdown.sh
[root@iZips92kqeqhgjZ home]# sh /home/tomcat/apache-tomcat-9.0.21/bin/startup.sh
#启动nginx
(pyweb) [root@iZips92kqeqhgjZ home]# /usr/local/nginx/sbin/nginx
(pyweb) [root@iZips92kqeqhgjZ home]# /usr/local/nginx/sbin/nginx -s quit

#更新项目资源

   #查看Uwsgi进程
(pyweb) [root@iZips92kqeqhgjZ bin]# ps -ef|grep uwsgi 
root      4201     1  0 Sep01 ?        00:00:03 uwsgi -x Logistics.xml
root      4217  4201  0 Sep01 ?        00:00:13 uwsgi -x Logistics.xml
    #用kill方法把uwsgi进程杀死,然后启动uwsgi
(pyweb) [root@iZips92kqeqhgjZ bin]# killall -9 uwsgi
    #启动方法
        (pyweb) [root@iZips92kqeqhgjZ home]# uwsgi -x /data/wwwroot/Logistics/Logistics.xml
        (pyweb) [root@iZips92kqeqhgjZ home]# /usr/local/nginx/sbin/nginx  -s reload
        killall -9 uwsgi
        uwsgi -x /data/wwwroot/Logistics/Logistics.xml
        /usr/local/nginx/sbin/nginx  -s reload


相关文章
|
7天前
|
Ubuntu 前端开发 JavaScript
技术笔记:Ubuntu:一个部署好的tomcat应用(war包)怎么用Nginx实现动静分离?
技术笔记:Ubuntu:一个部署好的tomcat应用(war包)怎么用Nginx实现动静分离?
|
2天前
|
JavaScript 应用服务中间件 nginx
【项目部署系列教程】5. nginx配置反向代理,解决跨域接口的访问
【项目部署系列教程】5. nginx配置反向代理,解决跨域接口的访问
19 10
|
1天前
|
应用服务中间件 网络安全 nginx
|
8天前
|
前端开发 应用服务中间件 nginx
nginx前后端分离、多前端部署配置文件
nginx前后端分离、多前端部署配置文件
15 2
|
8天前
|
应用服务中间件 nginx 数据安全/隐私保护
cloudstack使用nginx部署ui
cloudstack使用nginx部署ui
13 1
|
12天前
|
安全 Ubuntu 应用服务中间件
NGINX环境下实现Web网站访问控制的实战指南
在NGINX中设置基于IP的访问控制可提升网站安全性。步骤包括安装NGINX、备份配置文件、编辑`/etc/nginx/sites-available/default`,添加`allow`和`deny`指令限制特定IP访问,如`allow 192.168.1.100; deny all;`,然后测试配置并重启服务。成功后,仅允许的IP能访问网站,否则会收到403错误。这为Web安全提供基础保障,还可扩展实现更多高级控制策略。【6月更文挑战第20天】
78 3
|
2天前
|
JavaScript 应用服务中间件 nginx
nginx部署多个vue项目
nginx部署多个vue项目
8 0
|
3天前
|
应用服务中间件 Linux nginx
【项目部署系列教程】3. 安装宝塔 vs nginx
【项目部署系列教程】3. 安装宝塔 vs nginx
11 0
|
7天前
|
关系型数据库 应用服务中间件 nginx
Docker + node(koa) + nginx + mysql 线上环境部署
Docker + node(koa) + nginx + mysql 线上环境部署
|
10天前
|
应用服务中间件 nginx
centos7.6安装Nginx解决403
centos7.6安装Nginx解决403
18 0