在阿里云服务器使用nginx+uwsgi+venv部署Django项目

1.首先先把项目上传到阿里云服务器
2.需要安装python3.0以上版本(centeros7自带2.75版本)
3.在此不介绍如何安装python高版本和虚拟环境

4.在项目根目录创建虚拟环境,就像你在Pycharm里一样
然后启动虚拟环境

[root@iz2ze86lbramtwlubh6tx8z south_focusing]# cd venv/
[root@iz2ze86lbramtwlubh6tx8z venv]# cd bin
[root@iz2ze86lbramtwlubh6tx8z bin]# source activate
(venv) [root@iz2ze86lbramtwlubh6tx8z bin]#

5.在虚拟环境下安装你项目所需要的依赖
pip3 install requirements.txt
6.编写nginx配置文件和uwsgi配置文件
配置如下
nginx.conf

upstream south {
    server 127.0.0.1:10897;
}
server {

        listen 80;
        server_name  www.xxx.com;
        access_log  /opt/south_focusing/logs/access.www.xxx.com.log;
        error_log   /opt/south_focusing/logs/error.www.xxx.com.log;
        index index.html login.html;
    
        # 限制上传大小
        client_max_body_size 1024M;
        location /south {
            include  uwsgi_params;
            uwsgi_pass 127.0.0.1:10897;
                proxy_set_header X-Real_IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header  Cookie $http_cookie;
                proxy_connect_timeout   90;
                proxy_send_timeout 90;
                proxy_read_timeout 90;
                client_max_body_size 10m;
                client_body_buffer_size 128k;
                proxy_buffer_size 64k;
                proxy_buffers 4 32k;
                proxy_busy_buffers_size 64k;
                proxy_temp_file_write_size 64k;
        }

    # 静态文件
    location /static {
        alias /opt/south_focusing/south_focusing/static;
    }

    # 上传素材
    location /media {
        alias /opt/south_focusing/media;
    }

注意编写完nginx配置文件需要检查语法
nginx -t 注意别忘记加;或者文章尾末多空格都会导致出错
nginx -s reload 重启nginx
uwsgi.ini配置如下

[uwsgi]
master = true
processes = 1
threads = 2
chdir = /opt/south_focusing
wsgi-file= /opt/south_focusing/south_focusing/wsgi.py
socket = :10897
logto = /opt/south_focusing/logs/error.log
chmod-socket = 660
vacuum = true
master = true
max-requests = 1000
pidfile=/opt/south_focusing/logs/uwsgi.pid

7.都配置好之后
启动虚拟环境
在venv里 uwsgi uwsgi.ini 即可启动你的项目

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。