Django上線部署 1 (nginx+uwsgi上線一個測試項目)

寫在前面

本章常用指令

查看防火牆的88端口是否打開:firewall-cmd --list-port
開啓88端口:firewall-cmd --zone=public --add-port=88/tcp --permanent
重啓防火牆:firewall-cmd --reload

創建虛擬環境:mkvirtualenv testenv
進入虛擬環境:workon testenv
退出虛擬環境:deactivate
刪除虛擬環境:rmvirtualenv testenv

nginx目錄:cd /usr/local/nginx/sbin
查看nginx版本:./nginx -v
查看nginx狀態:ps -ef|grep nginx
關閉:sudo ./nginx -s quit
測試:sudo ./nginx -t -c /root/yh/testdjango/text.conf
啓動:sudo ./nginx -c /root/yh/testdjango/text.conf

uwsgi啓動:uwsgi --ini /root/yh/testdjango/uwsgi.ini
重啓:uwsgi --reload xxx.pid
停止:uwsgi --stop xxx.pid
查看狀態:ps -ef|grep uwsgi

查看端口情況:lsof -i:8001
殺掉被佔用端口:kill -9 進程pid

1、準備

windows端:
找到項目根目錄
在templates下新建index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<body>

<h1>這是標題 1</h1>
<h2>這是標題 2</h2>
<h3>這是標題 3</h3>
<h4>這是標題 4</h4>
<h5>這是標題 5</h5>
<h6>這是標題 6</h6>

</body>
</html>

新建test.conf、uwsgi.ini
test.conf

user  root;
worker_processes  1;

error_log  /root/yh/testdjango/error.log warn;
pid        /root/yh/testdjango/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include    /usr/local/nginx/conf/mime.types;
    default_type  application/octet-stream;
    sendfile        on;

    keepalive_timeout  65;


   server {
        listen  89;
        server_name  localhost;

        root  /root/yh/testdjango;
        location /templates {
                alias /root/yh/testdjango/templates;
        }
        location / {
                include /usr/local/nginx/conf/uwsgi_params;
                uwsgi_pass 127.0.0.1:8889;
        }
    }
}

uwsgi.ini

[uwsgi]
# nginx連接時
socket=0.0.0.0:8889
# 作爲web服務器連接時
#http=0.0.0.0:8889
# 項目目錄
chdir=/root/yh/testdjango
# wsgi目錄(相對路徑)
wsgi-file=testdjango/wsgi.py
# 進程
processes=4
# 每個進程裏的線程
threads=10
# 是否開啓多線程模式
enable-threads=True
# 是否開啓接口
master=True
# 進程id存儲文件
pidfile=uwsgi.pid
# 日誌
daemonize=uwsgi.log

新建文件夾logs,裏面新建error.log、nginx.pid兩個空文件
在這裏插入圖片描述
在pycharm裏面生成項目依賴文件:pip freeze > 1.txt
在這裏插入圖片描述
最終目錄包含文件
在這裏插入圖片描述
壓縮整個項目文件夾,上傳到服務器(這裏我是centos系統):rz

解壓到/root/yh/testdjango:unzip -d /root/yh/testdjango 1.zip

在這裏插入圖片描述

2、服務器

開放防火牆端口:89、8889
在這裏插入圖片描述

新建虛擬環境:virtualenv -p /usr/local/bin/python3 /root/yh/testenv
在這裏插入圖片描述
生成虛擬環境:mkvirtualenv testenv

安裝項目依賴:pip install -r 1.txt
在這裏插入圖片描述
啓動nginx:
在這裏插入圖片描述
啓動uwsgi:
在這裏插入圖片描述
到windows瀏覽器訪問:這裏沒指定編碼格式,但是你可以看到成功訪問了
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章