当前位置: 移动技术网 > IT编程>脚本编程>Python > nginx + gunicorn + flask项目发布

nginx + gunicorn + flask项目发布

2018年09月14日  | 移动技术网IT编程  | 我要评论

夜华家居装饰网,单项奖学金申请书,团代会贺词

程序安装(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.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.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 127.0.0.0:8100 mission-manager:app,-w进程数量,mission-managerflask程序主函数所在py文件
  • 启动nginx服务:service nginx start

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网