在uwsgi / nginx上运行烧瓶应用程序时出现问题

问题描述 投票:1回答:2

我已经创建了一个flask应用,到目前为止,已经使用默认的flask服务器来创建/测试它。现在,我想将其部署到服务器上。我正在使用uwsgi和nginx,尽管我对两者都相当陌生。我知道有很多关于类似事物的指南和问题,但是经过我的理解后,我找不到解决方案

以下是我的uwsgi日志中的内容:

machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ben/flask/MLS-Flask
detected binary path: /home/ben/flask/MLS-Flask/mls-flask-ve/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 1024
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /home/ben/flask/MLS-Flask/mls_uwsgi.sock fd 3
Python version: 3.3.3 (default, Dec 30 2013, 16:29:41)  [GCC 4.4.7 20120313 (Red Hat    4.4.7-4)]
Set PythonHome to /home/ben/flask/MLS-Flask/mls-flask-ve
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x11755d0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72760 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
added /home/ben/flask/MLS-Flask/ to pythonpath.
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x11755d0 pid: 2926 (default app)
 *** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 2926, cores: 1)

我假设uwsgi至少正在运行?我对此很陌生,所以我不太确定问题出在哪里。

我的nginx配置是:

server{

    listen  8080;
    charset utf-8;

    location / {try_files $uri @app; }
    location @app {
        include uwsgi_params;
        uwsgi_pass unix:/home/ben/flask/MLS-Flask/mls_uwsgi.sock;
    }
}

我的uwsgi ini是:

[uwsgi]

uid = nginx
gid = nginx

base = /home/ben/flask/MLS-Flask

home = %(base)/mls-flask-ve
pythonpath = %(base)

chdir = /home/ben/flask/MLS-Flask

module = runp

#socket file's location
socket = /home/ben/flask/MLS-Flask/mls_uwsgi.sock

#permissions for the socket file
chmod-socket = 666

#variable that holds a flask application inside the module imported
callable = app

#location of log file
logto = /var/log/uwsgi/%n.log

并且uwsgi ini正在运行的文件是我的烧瓶应用程序:

from app import app


if __name__ == "__main__":
    app.run(debug = False, port = 8080)

我的uwsgi ini或nginx配置中可能有一些无关紧要的东西,但是我不确定这些是否一定是问题所在。谁能看到任何原因导致它不起作用?我目前在localhost:8080上收到502错误的网关错误,所以我猜想它与我的烧瓶uwsgi ini / socket有关。

我非常感谢您的帮助。

nginx flask uwsgi
2个回答
0
投票

事实证明,我的nginx用户无权访问套接字,因为/和/ home /目录归root组和root用户所有。我最终从/目录到套接字一直对所有者和组具有完全访问权限(这可能不是最安全的解决方案安全性,但是在一切正常之后,我可以进一步完善它。)


0
投票

我有同样的问题:

  1. 总是使用ls -lhtr检查套接字权限
  2. 尝试将套接字放入/run/myapp/mysock.sock文件夹中>
  3. 在此文件夹vi mysock.sock中创建一个空的袜子文件
  4. 设置此空文件的权限,以使您的用户和组具有完全访问权限在服务中。 chown user:group /run/myapp/mysock.sock
© www.soinside.com 2019 - 2024. All rights reserved.