flask+uWSGI+Nginx部署web服务器

uWSGI

用ini配置文件来启动

  1. 进入项目文件夹“”
  2. 启动uWSGI
    uwsgi --ini uwsgi_config.ini
  3. 关闭uWSGI
    killall -9 uwsgi

配置案例:

[uwsgi]
# -------------
# Settings:
# key = value
# Comments >> #
# -------------

# socket = [addr:port]
socket = 0.0.0.0:5000

# Base application directory
# chdir = /full/path
chdir  = /media/coolman/DATA/02代码/local/25strong_ai_flask

# WSGI module and callable
# module = [wsgi_module_name]:[application_callable_name]
module = index:app

# master = [master process (true of false)]
master = true

# processes = [number of processes]
processes = 5

# 将uWSGI设置为守护进程,并将信息写入指定的参数(也就是日志文件)。用法:
daemonize = /media/coolman/DATA/02代码/local/25strong_ai_flask/server.log

Nginx

  1. 修改配置文件
    sudo gedit /etc/nginx/nginx.conf
  2. 关闭Nginx
    sudo service nginx stop
  3. 启动Nginx
    sudo service nginx start

Nginx配置案例:

user www-data;
worker_processes 8;

events {

    worker_connections 1024;

}

http {

    sendfile on;

    gzip              on;
    gzip_http_version 1.0;
    gzip_proxied      any;
    gzip_min_length   500;
    gzip_disable      "MSIE [1-6]\.";
    gzip_types        text/plain text/xml text/css
                      text/comma-separated-values
                      text/javascript
                      application/x-javascript
                      application/atom+xml;

    # Configuration containing list of application servers
    upstream uwsgicluster {

        server 0.0.0.0:5000;
        # server 127.0.0.1:8081;
        # ..
        # .

    }

    # Configuration for Nginx
    server {

        # Running port
        listen 80;
	access_log  /media/coolman/DATA/02代码/local/25strong_ai_flask/nginx_access.log;
	error_log  /media/coolman/DATA/02代码/local/25strong_ai_flask/nginx_error.log;

        # Serve a static file (ex. favico) outside static dir.
        location = /favico.ico  {

            root /app/favico.ico;

        }

        # Proxying connections to application servers
        location / {

            include            uwsgi_params;
            uwsgi_pass         uwsgicluster;
            proxy_redirect     off;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;

        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值