博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx + supervisrd + gunicorn + Flask
阅读量:7095 次
发布时间:2019-06-28

本文共 3305 字,大约阅读时间需要 11 分钟。

最近做的外包项目开发接近尾声,进入部署阶段,在选择技术的时候,查阅了不少资料。在此做备记。

几个特点:

1、nginx前后端服务器,upstream了4个端口。代码如下:

upstream huhuchen-site {    server 127.0.0.1:5001;    server 127.0.0.1:5002;    server 127.0.0.1:5003;    server 127.0.0.1:5004;}server_names_hash_bucket_size 64;server {    server_name huhuchen.com www.huhuchen.com;    types_hash_max_size 2048;    location / {
proxy_set_header Host $host:80; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Via "nginx"; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 60s; proxy_send_timeout 90s; proxy_read_timeout 90s; proxy_buffering off; proxy_temp_file_write_size 64k; proxy_pass http://huhuchen-site; proxy_redirect off; } location /static { root /home/huhuchen/huhuchen/; expires 30d; add_header Cache-Control public; access_log off; }}

相关资料:

 

2、使用gunicorn启动flask服务,命令如下

gunicorn huhuchen:app -b localhost:50%(process_num)02d --log-level info --access-logfile /var/log/access-%(program_name)s-%(process_num)01d.log

相关资料:

 

遇到的问题:

a).15.0执行命令gunicorn huhuchen:app -b localhost:5000时,需要cd到应用huhuchen所在目录,不然会出错。

b).gunicorn需要配置日志文件,不然应用的访问日志将无法查看,可以直接在目录中配置日志路径,也可以配置在conf.py中,并在命令中导入。

 

3、使用supervisrd保证服务不死,配置如下:

[unix_http_server]file=/tmp/supervisor.sock   ; (the path to the socket file)[supervisord]logfile=/var/log/supervisord.log ; (main log file;default $CWD/supervisord.log)logfile_maxbytes=500MB        ; (max main logfile bytes b4 rotation;default 50MB)logfile_backups=10           ; (num of main logfile rotation backups;default 10)loglevel=info                ; (log level;default info; others: debug,warn,trace)pidfile=/var/log/supervisord.pid ; (supervisord pidfile;default supervisord.pid)nodaemon=false               ; (start in foreground if true;default false)minfds=1024                  ; (min. avail startup file descriptors;default 1024)minprocs=200                 ; (min. avail process descriptors;default 200)[rpcinterface:supervisor]supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface[supervisorctl]serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket[program:ptour]autostart=true                ; start at supervisord start (default: true)command=/usr/local/bin/gunicorn huhuchen:app -b localhost:50%(process_num)02d --log-level info --access-logfile /var/log/access-%(program_name)s-%(process_num)01d.log             ; the program (relative uses PATH, can take args)process_name=%(program_name)s-%(process_num)01d ; process_name expr (default %(program_name)s)numprocs=5                    ; number of processes copies to start (def 1)numprocs_start=0redirect_stderr=true          ; redirect proc stderr to stdout (default false)stdout_logfile=/var/log/%(program_name)s-%(process_num)01d.log        ; stdout log path, NONE for none; default AUTOdirectory=/home/huhuchen               ; directory to cwd to before exec (def no cwd)autorestart=true       ; whether/when to restart (default: unexpected)

 相关资料:

 

 

转载于:https://www.cnblogs.com/huhuchen/archive/2012/10/31/2748901.html

你可能感兴趣的文章
技术书单整理
查看>>
MyBatis-Spring 使用总结
查看>>
[Angular 2] Understanding OpaqueToken
查看>>
设计模式原则 依赖倒置
查看>>
redgate的mysql架构比较和数据比较工具
查看>>
Bmob移动后端云服务平台--Android从零開始--(二)android高速入门
查看>>
免费的UI素材准备
查看>>
Ubuntu设置显示桌面快捷键
查看>>
TabBarController和其他view无法建立Relationship segue的原因
查看>>
hdu 3342 Legal or Not (拓扑排序)
查看>>
JVM概述
查看>>
C#模拟POST提交表单(一)--WebClient
查看>>
[Spark][python]从 web log 中提取出 UserID 作为key 值,形成新的 RDD
查看>>
Zephyr的Shell
查看>>
Bootstrap系列 -- 36. 向上弹起的下拉菜单
查看>>
TMS320C6455 SRIO 实现方案
查看>>
background-color
查看>>
提升单元测试体验的利器--Mockito使用总结
查看>>
SVN功能详解
查看>>
[转]微信小程序之购物车 —— 微信小程序实战商城系列(5)
查看>>