nginx + gunicorn + flask项目发布

程序安装(linux mint)

  • gunicorn安装:pip install gunicorn
  • nginx安装:sudo apt-get install nginx

配置

nginx默认配置信息在/etc/nginx/sites-enabled/default

server {
listen 8300 default_server;#默认端口设置位置
listen [::]:8300 default_server ipv6only=on; root /usr/share/nginx/html;
index index.html index.htm; # Make site accessible from http://localhost/
server_name localhost; location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
server {
listen 8200;#nginx对外监听端口设置
server_name my.com;#网站域名绑定
#root html;
#index index.html index.htm; location /auth {#auth为flask程序你的蓝图,如果没有设置蓝图则为/
#try_files $uri $uri/ =404;
proxy_pass http://0.0.0.0:8100;#gunicorn启动flask的网址
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
client_max_body_size 50m;#服务器上传文件大小上限
}
location /static {#静态文件static文件夹所在目录
root /var/www/mission-manager/;
}
}

flask项目部署

  • 复制flask程序至/var/www/
  • 启动gunicorn:gunicorn -w 2 -b 0.0.0.0:8100 mission-manager:app,-w进程数量,mission-managerflask程序主函数所在py文件
  • 启动nginx服务:service nginx start
上一篇:Java企业级电商项目架构演进之路 Tomcat集群与Redis分布式


下一篇:2.Java对象创建