【问题标题】:Problems running flask app on uwsgi / nginx在 uwsgi / nginx 上运行烧瓶应用程序的问题
【发布时间】:2014-01-16 21:57:00
【问题描述】:

我已经创建了一个烧瓶应用程序,到目前为止,我一直在使用默认的烧瓶服务器来创建/测试它。现在我想将它部署到服务器。我正在使用 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 bad gateway 错误,所以我猜这与我的烧瓶 uwsgi ini/socket 有关。

感谢您的帮助。

【问题讨论】:

标签: nginx flask uwsgi


【解决方案1】:

原来我的 nginx 用户没有访问套接字的权限,因为 / 和 /home/ 目录归 root 组和 root 用户所有。我最终为所有者和组提供了从 / 目录到套接字的完全访问权限(这可能不是最安全的安全解决方案,但我可以在一切正常后进一步完善它。)

【讨论】:

    【解决方案2】:

    我遇到了同样的问题:

    1. 始终使用ls -lhtr 检查套接字权限
    2. 尝试将套接字放入/run/myapp/mysock.sock 文件夹中
    3. 在此文件夹vi mysock.sock 中创建一个空的 sock 文件
    4. 将此空文件的权限设置为您的用户和组具有完全访问权限 在服务中。 chown user:group /run/myapp/mysock.sock

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-18
      • 2013-09-01
      • 1970-01-01
      • 2012-11-28
      • 1970-01-01
      • 2015-07-18
      • 2017-11-16
      • 2019-04-05
      相关资源
      最近更新 更多