美文网首页程序员
CentOS 7 搭建django

CentOS 7 搭建django

作者: 冷煖自知 | 来源:发表于2018-04-12 10:14 被阅读143次

安装所需工具

  • 安装setuptools yum install python-setuptools
  • 安装djangoeasy_install django或者pip install Django
  • 安装C++ yum install gcc-c++
  • 安装nginx yum install nginx -y([nginx启动停止命令]
    (https://www.jianshu.com/p/177065ef9e9b))
  • 安装uwsgi pip install uwsgi

配置

首先开启所需端口(CentOS 开启端口
配置nginx.conf

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  www.ledemon.top;#网站域名
        root            /root/www;#修改根目录(如果修改后重启显示403,则要开启读写权限)
        include /etc/nginx/default.d/*.conf;
        index index.html index.htm;
        location /{
                include uwsgi_params;
                uwsgi_pass 127.0.0.1:8765;#此配置为监听端口号
                uwsgi_read_timeout 2;
                client_max_body_size 35m;
        }

        #此配置为静态资源(img,css,js)
        location /static {
                alias /root/www/static;
        }
}

然后在网站目录下新建wsgi.ini文件做为启动入口

[uwsgi]

#nginx监听的端口号
socket = :8765
# 网站目录
chdir           = /root/www/
#wsgi.py所在目录
wsgi-file       = wsgi.py
# maximum number of worker processes
processes       = 4
vacuum          = true
#log保存位置
daemonize = /root/www/web_uwsgi.log
#更新py文件后重启wsgi
python-autoreload=1

启动nginx,然后通过uwsgi --ini /root/www/uwsgi.ini启动wsgi

  • 如果关闭wsgi的话使用killall -9 uwsgi命令
  • 如果想通过域名访问django,还需要修改setting.py写入所需域名
  • 整合所有静态文件python manage.py collectstatic

其他django问题

听雨阁

相关文章

网友评论

    本文标题:CentOS 7 搭建django

    本文链接:https://www.haomeiwen.com/subject/cpxxkftx.html