在centos 7上的nginx代理后面的gunicorn上配置flask应用程序的问题

时间:2018-08-07 10:57:59

标签: nginx flask centos gunicorn

我一直在尝试在使用centos 7的nginx代理后面使用gunicorn部署flask应用程序  当我尝试在浏览器中访问该应用程序时,它不会加载并  最终时间到了。我是烧瓶,gunicorn和nginx的新手,所以我不确定自己做错了什么。  我正在使用vultr云托管环境托管该应用程序。我正在关注本教程:  https://www.vultr.com/docs/how-to-setup-gunicorn-to-serve-python-web-applications

,但将文件夹exampleapp替换为control_search文件夹,并将我的python源文件control_search.py​​放在此处。该文件的结构如下  如下:

import requests

....

from flask import Flask,render_template,request,jsonify

app = Flask(__name__)
@app.route('/')
def open_layer():
  return render_template("index.html")
@app.route('/compute',methods=['POST', 'GET'])
def compute_paths():
  ....
  ....
  ....
if __name__ == '__main__':
   app.run(debug=True)

我在control_search文件夹内有一个包含index.html的模板文件夹。这个想法是将index.html文件加载到浏览器中。 我曾尝试同时使用以下两种方法启动gunicorn:

gunicorn -w 2 control_search:open_layer&

gunicorn -w 2 control_search:app&

无济于事。我的nginx配置如下:

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;
    root         /usr/share/nginx/html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    proxy_set_header HOST $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://localhost:8000/;
    }
}

我真的很感谢能为我的工作提供一些建议。 谢谢

0 个答案:

没有答案
相关问题