python安装uwsgi_微服务怎么部署到服务器的

python安装uwsgi_微服务怎么部署到服务器的什么是uWSGIuWSGI旨在为部署分布式集群的网络应用开发一套完整的解决方案。主要面向web及其标准服务。由于其可扩展性,能够被无限制的扩展用来支持更多平台和语言。uWSGI是一个web服务器,实现了WSGI协议,uwsgi协议,http协议等。uWSGI的主要特点是:超快的性能低内存占用多app管理详尽的日志功能高度可定制uWSGI服务器自己实现了基于uwsgi协议的ser…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

什么是uWSGI

uWSGI旨在为部署分布式集群的网络应用开发一套完整的解决方案。主要面向web及其标准服务。由于其可扩展性,能够被无限制的扩展用来支持更多平台和语言。uWSGI是一个web服务器,实现了WSGI协议,uwsgi协议,http协议等。
uWSGI的主要特点是:

  • 超快的性能
  • 低内存占用
  • 多app管理
  • 详尽的日志功能
  • 高度可定制

uWSGI服务器自己实现了基于uwsgi协议的server部分,我们只需要在uwsgi的配置文件中指定application的地址,uWSGI就能直接和应用框架中的WSGI application通信

安装uWSGI

pip install uwsgi

uWSGI配置文件

这里给个样例作为参考

[uwsgi]
# 指向项目目录
chdir = /XXX/XXX/XXXX

# 外部访问地址,主要是指定端口号。可以指定多种协议:http 或 socket
socket = 127.0.0.1:8888
# http = 127.0.0.1:8888

# flask启动程序文件
wsgi-file = XXX.py

# flask在manage.py文件中的app名
callable = app

# 处理器数
processes = 4

# 存储日志信息
logto = /XXX/XXX/XXX.log

# 线程数
threads = 8

# 设置uwsgi的pid文件
pidfile = /XXX/XXX.pid

# 设置uwsgi的status文件
statusfile = /XXX/XXX.status

Nginx反向代理配置文件

这里给个样例作为参考

# the upstream component nginx needs to connect to
upstream XXX {
    server 127.0.0.1:7777;
}

# configuration of the server
server {
    # the port your site will be served on
    listen     1002;
    # the domain name it will serve for
    #server_name .example.com; # substitute your machine's IP address or FQDN
    server_name XXXX;
    charset     utf-8;

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  XXX;
        include     uwsgi_params; 
        # the uwsgi_params file you installed
    }
}

PS. 对于新建的配置文件,需要在nginx.conf里面加入引入路径:include vhosts/*.conf

user  work;
worker_processes  auto;

#error_log  logs/error.log;
error_log  /data/logs/nginx/host/logs/host_error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    use epoll;
    accept_mutex off;
    worker_connections  1024;
}


http {
    include       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"';
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent $request_body "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" "$request_time"';

    access_log  /data/logs/nginx/host/logs/host_access.log  main;

    server_tokens   off;
    sendfile        on;
    #tcp_nopush     on;
    tcp_nodelay    on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    client_header_buffer_size 4k;
    client_max_body_size 20M;

    open_file_cache max=102400 inactive=30s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 0;

    gzip  on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript  application/javascript application/json;

include vhosts/*.conf;
}

常见的命令

  • 启动uwsgi服务
    uwsgi --ini uwsgi.ini
    
  • 查看uwsgi的pid号
    cat uwsgi/uwsgi.pid
    
  • 查看一下uwsgi的进程
    ps aux | grep uwsgi
    
  • 重启uwsgi
    uwsgi --reload uwsgi/uwsgi.pid
    
  • 停止uwsgi
    uwsgi --stop uwsgi/uwsgi.pid
    
  • 查看uwsgi的版本
    uwsgi --version
    
  • 测试配置文件是否有语法错误
    nginx -t 
    
  • 重启Nginx
    nginx -s reload
    
  • 测试配置文件是否有语法错误
    nginx -t 
    
  • 强制停止Nginx服务
    nginx -s stop 
    
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/197195.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号