Django+Uwsgi+Nginx部署

1、第一要保证Django直接启动没有问题
2、firewall、SELinux、iptables要没问题
3、python版本问题

安装Nginx

[root@localhost ~]# yum install nginx

安装、配置uwsgi

[root@localhost ~]# yum install uwsgi
[root@localhost ~]# cat /lib/systemd/system/uwsgi.service
[Unit]
Description=uwsgi
Documentation=uwsgi
After=syslog.target

[Service]
ExecStart=/usr/local/python3/bin/uwsgi  --ini /etc/uwsgi.ini --master --enable-threads --uid nginx --gid nginx   --plugins=/usr/local/python3/bin/python3 --pidfile /run/uwsgi/uwsgi.pid
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
Restart=always
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

编辑uwsgi.service中主要需要修改的重要参数是ExecStart

ExecStart=/usr/local/python3/bin/uwsgi  --ini /etc/uwsgi.ini --master --enable-threads --uid nginx --gid nginx   --plugins=python36 --pidfile /run/uwsgi/uwsgi.pid

/usr/local/python3/bin/uwsgi #uwsgi命令地址
--ini /etc/uwsgi.ini #uwsgi的配置文件
--master --enable-threads --uid nginx --gid nginx #不用更改
--plugins=--plugins=/usr/local/python3/bin/python3 #python版本,这里注意python路径以及所对应的pip
--pidfile /run/uwsgi/uwsgi.pid #不用更改,指定pid的位置
编辑uwsgi.ini文件

[root@localhost ~]# cat /etc/uwsgi.ini
[uwsgi]
chdir=/data/github_gateway    #项目目录
socket=/run/uwsgi/uwsgi.sock  #sock存放位置(此处巨坑,和PID一个位置准没错)
module=github_gateway.wsgi  #模块位置
touch-reload=/data/github_gateway  #文件修改时优雅的重启uwsgi

配置Nginx

server {
    listen 9000 ;
    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        include uwsgi_params;
        uwsgi_pass  unix://run/uwsgi/uwsgi.sock;  
     }
    }

你可能感兴趣的:(Django+Uwsgi+Nginx部署)