Nginx教程

部署flask(nginx,gunicron,supervisor)

本文主要是介绍部署flask(nginx,gunicron,supervisor),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

supervisor apt安装

配置文件

nginx(

[program:nginx]
command = /usr/sbin/nginx -g 'daemon off;'
startsecs=0
autostart=true
autorestart=true
stdout_logfile=/home/maj/flask/log/nginx_sup.log
redirect_stderr=true
priority=10
stopasgroup=true
killasgroup=true
stopsignal=INT
startsecs=10
startretries=10

)

gunicron(

[program:gunicorn]
command=/home/maj/flask/venv/bin/gunicorn -w4 -b0.0.0.0:8000 app:app ; supervisor启动命令
directory=/home/maj/flask ; 项目的文件夹路径
startsecs=0 ; 启动时间
stopwaitsecs=0 ; 终止等待时间
autostart=true ; 是否自动启动
autorestart=true
stopasgroup=true ; 是否自动重启
stdout_logfile=/home/maj/flask/log/gunicorn.log ; log 日志
stderr_logfile=/home/maj/flask/log/gunicorn.err
environment=MAIL_USERNAME="xxx",MAIL_PASSWORD="xxx",SECRET_KEY="xxx"

)

nginx配置文件:

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

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /home/maj/flask;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.

# try_files $uri $uri/templates/index.html$is_args$query_string;
proxy_pass http://0.0.0.0:8000/;
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


}


location /static {
# root /static;
alias /home/maj/flask/static;
}

这篇关于部署flask(nginx,gunicron,supervisor)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!