django在linux上部署

目录结构

image.png

nginx配置文件 nginx.conf


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

	server {
		listen 80;
		server_name localhost;

		root /home/abel/code/website;

		location /static {
			alias /home/abel/code/website/static;
		}
		location / {
			include /usr/local/nginx/conf/uwsgi_params;
			uwsgi_pass 127.0.0.1:8011;
		}

	}
}

uwsgi配置文件 uwsgi.ini (django)

[uwsgi]
# 使用nginx反向代理时使用
;socket = 127.0.0.1:8011
# 直接作为web服务器使用 记得host一定要是0.0.0.0
http = 0.0.0.0:8010
# 配置工程目录
chdir = /tmp/pycharm_project_368
# 配置项目的wsgi目录 注意是相对于工程目录 wsgi.py 文件时django框架自动生成的
wsgi-file = testdjango/wsgi.py
# 配置虚拟环境
;home = /root/.venvs/py38
# 配置进程线程的信息
processes = 1
threads = 1

uwsgi配置文件 uwsgi.ini (flask)


[uwsgi]
#uwsgi启动时,所使用的地址和端口(这个是http协议的)
http = 0.0.0.0:5001
# 虚拟环境路径
virtualenv = /root/.venvs/py38
#指向网站目录
chdir = /tmp/pycharm_project_697
#python 启动程序文件
wsgi-file = myflask.py
#python 程序内用以启动的application 变量名
callable = app
#处理器数
processes = 4
#线程数
threads = 2

注意:flask程序中 app.run(host=‘0.0.0.0’) host 一定要写 要不然远程访问不了

uwsgi 相关命令

进入虚拟环境 安装uwsgi

pip install uwsgi

测试uwsgi,创建test.py文件:

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World"]
uwsgi --http :8001 --wsgi-file test.py

在这里插入图片描述

  • 停止

uwsgi --stop /home/abel/code/website/uwsgi.pid

  • 开启 (一定要先进入虚拟环境)

uwsgi --ini /home/abel/code/website/uwsgi.ini

nginx 相关命令

  • 关闭

sudo nginx -s quit

  • 重新加载配置文件

sudo nginx -s reload

  • 测试配置文件

sudo nginx -t -c /home/abel/code/website/nginx.conf

  • 启动

sudo nginx -c /home/abel/code/website/nginx.conf

  • 查看服务是否活着

ps -ef | grep nginx

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值