Ubuntu 烧瓶+;UWSGI&x2B;NGinx=504除根目录外的所有内容的超时

Ubuntu 烧瓶+;UWSGI&x2B;NGinx=504除根目录外的所有内容的超时,ubuntu,nginx,flask,uwsgi,Ubuntu,Nginx,Flask,Uwsgi,我一直在研究和尝试数以百计的配置,什么都没有。我只有两条路线,“/”和“/搜索/”。网站在/位置加载ok,但当我点击img执行搜索时,它会挂起并给出504 如果我像python3 app.py那样直接运行服务器,那么它工作得非常好 如果我运行它uwsgi,uwsgi--socket 0.0.0.0:8080--protocol=http-w run:app,它也能很好地工作,所以我认为问题在于nginx配置,但我不知道有什么可能出错(我是新手) 这是我的档案: run.py from serve

我一直在研究和尝试数以百计的配置,什么都没有。我只有两条路线,“/”和“/搜索/”。网站在/位置加载ok,但当我点击img执行搜索时,它会挂起并给出504

如果我像python3 app.py那样直接运行服务器,那么它工作得非常好

如果我运行它uwsgi,uwsgi--socket 0.0.0.0:8080--protocol=http-w run:app,它也能很好地工作,所以我认为问题在于nginx配置,但我不知道有什么可能出错(我是新手)

这是我的档案:

run.py

from server import app
if __name__ == '__main__':
      app.run()
server.py

app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def index():
    uploaded_imgs = os.listdir('static/quick_demo')
    uploaded_imgs_rdn = set(random.sample(uploaded_imgs, 7))

    if request.method == 'POST':
        file = request.files['query_img']
        ts = int(time.time())
        img = Image.open(file.stream)  # PIL image
        uploaded_img_path = "static/uploaded/{}_{}".format(ts, file.filename)
        img.save(uploaded_img_path)

        //some code here ...
        return render_template('index.html',
                               query_path=uploaded_img_path,
                               query_upload_path=uploaded_imgs_rdn,
                               scores=scores)
    else:
        return render_template('index.html', query_upload_path=uploaded_imgs_rdn)


@app.route('/search/<img_id>', methods=['GET'])
def search_demo(img_id):
    img_name = img_id
    uploaded_imgs = os.listdir('static/quick_demo')
    uploaded_imgs_rdn = set(random.sample(uploaded_imgs, 7))

    if request.method == 'GET':
        # file = request.files['query_img']
        # ts = int(time.time())
        img = Image.open("static/quick_demo/{}".format(img_name))  # PIL image
        uploaded_img_path = "/static/quick_demo/{}".format(img_name)
        # img.save(uploaded_img_path)

        //some code here ...

        return render_template('index.html',
                               query_path=uploaded_img_path,
                               query_upload_path=uploaded_imgs_rdn,
                               scores=scores)
    else:
        return render_template('index.html', query_upload_path=uploaded_imgs_rdn)
/etc/uwsgi/vassals/site.ini

[uwsgi]
chdir = /var/www/site
module = run:app
touch-reload = /var/www/site/run.py
logto = /var/log/uwsgi/site.log

# master with 2 worker process (based on CPU number)
master = true
processes = 2

# use unix socket for integration with nginx
socket = /var/run/uwsgi/site.sock
chmod-socket = 660
# enable socket cleanup when process stop
vacuum = true

# ensure compatibility with init system
die-on-term = true
我正在学习这个教程

请帮忙

再次感谢

[uwsgi]
chdir = /var/www/site
module = run:app
touch-reload = /var/www/site/run.py
logto = /var/log/uwsgi/site.log

# master with 2 worker process (based on CPU number)
master = true
processes = 2

# use unix socket for integration with nginx
socket = /var/run/uwsgi/site.sock
chmod-socket = 660
# enable socket cleanup when process stop
vacuum = true

# ensure compatibility with init system
die-on-term = true