37创客科创中心

 找回密码
 立即注册
查看: 1769|回复: 0

部署服务器案例

[复制链接]

194

主题

324

帖子

2405

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2405
发表于 2023-8-16 08:27:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
虚拟环境
1.安装virtualenv
        pip3.9 install virtualenv
2.创建虚拟环境(day28)        
        代码:
                /data/www/day28
        环境:
                /envs/nb

                mkdir /envs
                virtualenv /envs/nb --python=python3.9
3.激活虚拟环境
        source /envs/nb/bin/activate
4.假设
        source /envs/nb/bin/activate
        cd /data/www/day28
        python app.py

uwsgi
1.安装
        source /envs/nb/bin/activate
        pip install uwsgi

2.基于uwsgi运行flask项目
        cd 项目目录
        - 命令的方式
                uwsgi --http :8080 --wsgi-file app.py  --callable app
        - 配置文件(推荐)
                nb_uwsgi.ini
                        [uwsgi]
                        socket = 127.0.0.1:8001
                        chdir = /data/www/day28/
                        wsgi-file = app.py
                        callable = app
                        processes = 1
                        virtualenv = /envs/nb/


                source /envs/nb/bin/activate
                uwsgi --ini  nb_uwsgi.ini

        - 停止
                ps -ef|grep nb_uwsgi
                kill -9 15018


Nginx
1.安装
        yum install nginx -y
2.配置
        - 普通请求    ->  8001端口
        - /static/   -> /data/www/day28/static
        nginx的默认配置文件路径  /etc/nginx/nginx.conf

        2.1 删除默认的nginx.conf
                rm nginx.conf
        2.2 新建 nginx.conf  + 内容拷贝 + 保存
                cd /etc/nginx/

                vim nginx.conf    创建并打开文件
                i                 编辑模式
                ESC
                :wq

                cat nginx.conf

3.启动Nginx        
        - 启动
                systemctl start nginx
                systemctl stop nginx
                systemctl restart nginx
        - 开机启动
                systemctl enable nginx
4.访问

shell
1.重启(杀掉)
        reboot.sh
2.停止
        stop.sh

nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;


    upstream flask {
        server 127.0.0.1:8001;
    }

    server {
        listen       80;
        listen       [::]:80;

        # Load configuration files for the default server block.
        # include /etc/nginx/default.d/*.conf;

        location /static {
            alias  /data/www/day28/static;
        }

        location / {
            uwsgi_pass  flask;
            include     uwsgi_params;
        }

    }
}



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|37创客科创中心

GMT+8, 2025-12-13 08:13 , Processed in 0.130824 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表