将Django项目部署到CentOs服务器中
作者:回忆不说话 时间:2021-07-30 20:11:11
首先,把项目上传到虚拟机中。
scp -r C:\Users\Administrator\Desktop\fresh root@192.168.218.128:/home/fresh/
在虚拟环境中运行,确保uwsgi安装好。
pip install uwsgi
验证:
浏览器正常访问ip+端口,能正常访问,说明安装好了。
settings文件的修改:
将HOST改为本机地址。
python manage.py collectstatic 收集admin静态文件
修改uwsgi.ini
在项目文件下新建django_uwsgi.ini文件:
vim django_uwsgi.ini
[uwsgi]
# 通过uwsgi访问django需要配置成http
# 通过nginx请求uwsgi来访问django 需要配置成socket
# 9000 是django的端口号
socket = 0.0.0.0:9000
# web项目根目录
chdir = /home/fresh/
# module指定项目自带的的wsgi配置文件位置
module = fresh.wsgi
# 允许存在主进程
master = true
# 开启进程数量
processes = 3
# 服务器退出时自动清理环境
vacuum = true
启动服务:
uwsgi --ini django_uwsgi.ini --buffer-size 32768
如图:
配置nginx:
vi /etc/nginx/conf.d/fresh.conf
server {
listen 8008;
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass 127.0.0.1:9000;
}
location /static/{
root /home/fresh/;
}
}
vi /etc/nginx/nginx.conf
重启nginx。
然后重新启动uwsgi。
uwsgi --ini django_uwsgi.ini --buffer-size 32768
接着在浏览器中输入网址即可,ip是虚拟机的ip。可以通过ifconfig查看。
浏览器打开进去之后没有样式,输入如下命令:
getenforce
setenforce 0
刷新之后即可看到样式。
如果端口被占用,输入命令:
lsof -i:9000 #查看端口占用状态
netstat -lnp| grep 9000 #查看端口占用状态
kill -9 +PID号
来源:https://blog.csdn.net/qq_39138295/article/details/83097231
标签:django,centos,部署
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python神经网络Keras构建CNN网络训练
2022-08-16 08:42:37
基于Python制作短信发送程序
2022-06-19 16:47:25
![](https://img.aspxhome.com/file/2023/4/69644_0s.gif)
用Python计算三角函数之atan()方法的使用
2023-06-22 22:26:00
ASP中使用Set ors=oConn.Execute()时获取记录数的方法
2011-02-20 10:48:00
Selenium+Python 自动化操控登录界面实例(有简单验证码图片校验)
2022-05-03 10:35:40
![](https://img.aspxhome.com/file/2023/2/82712_0s.jpg)
像表格一样用DIV+CSS给网页布局
2008-10-18 15:45:00
在Ubuntu系统下安装使用Python的GUI工具wxPython
2022-08-21 10:17:49
Python使用sort和class实现的多级排序功能示例
2021-01-30 23:54:46
Python pandas DataFrame操作的实现代码
2021-07-24 00:49:43
详解Oracle 中实现数据透视表的几种方法
2023-07-24 03:45:04
Python struct.unpack
2023-10-14 21:29:56
Pytorch mask-rcnn 实现细节分享
2021-10-20 01:31:38
![](https://img.aspxhome.com/file/2023/0/79570_0s.jpg)
在Python运行时动态查看进程内部信息的方法
2021-06-09 09:15:40
python使用Flask框架获取用户IP地址的方法
2023-08-09 03:15:23
详解使用PyInstaller将Pygame库编写的小游戏程序打包为exe文件
2023-11-10 13:20:31
![](https://img.aspxhome.com/file/2023/2/109992_0s.png)
Python实现数字图像处理染色体计数示例
2022-06-15 03:32:36
![](https://img.aspxhome.com/file/2023/4/82544_0s.png)
asp 采集程序常用函数分析
2011-03-16 11:03:00
Python关于抽奖系统的思考与设计思路
2022-06-09 12:53:36
python实现简单登陆系统
2023-05-25 06:50:49
网页设计:把导航系统做薄
2007-12-28 12:02:00
![](https://img.aspxhome.com/file/UploadPic/200712/28/200712281250398s.gif)