CentOS7.X系统环境部署Django项目
Python
安装python流程地址:https://www.jianshu.com/p/0dc71548b213
Uwsgi
安装地址:https://www.jianshu.com/p/fe69c49687a5
Nginx
安装nginx流程地址:https://www.jianshu.com/p/5460755dea00
创建Django项目来跑跑Django项目( Nginx + Uwsgi )
第一种 pycharm创建Django项目
安装略过
第二种 django-admin 创建Django项目
mkdir /data
django-admin startproject webfile
cd /data01/webfile/
python3 manage.py startapp web
测试Django 项目是否能正常运行
python3 manage.py runserver IP:端口
在/data/webfile 下创建 webuwsgi.ini 添加以下内容( 参数都是有注释 )
[uwsgi]
# 启动uwsqi的用户名和用户组
uid = root
gid = root
# 项目在服务器中的目录(绝对路径)
chdir = /data/webfile/webfile/
# Django的 wsgi 文件目录下
wsgi-file = /data/webfile/webfile/XXX.py
# module指定项目自带的wsgi配置文件位置
# module = webfile.wsgi:application
# 使用HTTP访问的端口号, 使用这个端口号是直接访问了uWSGI, 绕过了Nginx
http = IP:端口
# 与外界连接的端口号, Nginx通过这个端口转发给uWSGI
socket = IP:端口
# 指定sock的文件路径
# socket = /项目目录/uwsgi.socket
# 状态监听端口
# stats = IP:端口
# 开启进程数量
processes = 2
# 进程个数
# workers = 2
# 设置缓冲
post-buffering = 1024
# 设置自中断时间
harakiri = 30
# 是否使用主线程
master = true
# 服务器退出时自动清理环境
vacuum = true
# 序列化接受的内容,如果可能的话
thunder-locke = true
# 启用线程
enable-threads = true
# uwsgi.pid可以来重启文件pid
pidfile= /data/webfile/uwsgi.pid
# 日志文件
daemonize= /data/webfile/uwsgi.log
# Python文件改动时自动重启
# py-autoreload = 1
# 目录下文件改动时自动重启
# touch-reload = /data
# 添加插件
# plugins = python,http
详细资料可以参考-官网文档地址:
https://www.cnblogs.com/zhouej/archive/2012/03/25/2379646.html
https://uwsgi-docs.readthedocs.io/en/latest/
Nginx.conf ( UP主个人需求配置 )
cat /etc/nginx/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name 域名;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
charset utf-8;
gzip on;
gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location / {
include uwsgi_params;
uwsgi_read_timeout 30;
uwsgi_pass unix:IP:端口;
# uwsgi_pass unix:/Django项目/uswgi.sock; # 可以第二种使用uswgi.sock配IP:端口
}
location /static/ {
alias /Django项目/static/;
index index.html index.htm;
}
}
}
接下来需要执行以下命令即可
cd /data0/webfile
uwsgi --ini webuwsgi.ini
网友评论