【问题标题】:Flask + uWSGI + Nginx + Fedora 20 setup issuesFlask + uWSGI + Nginx + Fedora 20 设置问题
【发布时间】:2014-03-25 22:01:50
【问题描述】:

我正在尝试通过 uWSGI 将烧瓶应用程序部署到 Nginx 上,使用 Fedora 20 作为操作系统,但我遇到了一些问题。

我有以下配置文件:

NGINX - 具有以下编辑的默认配置:

location / { try_files $uri @yourapplication; }
location @yourapplication {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/sjudson_app_uswgi.sock;
}

uWSGI:

[uwsgi]
socket = /tmp/%n.sock
wsgi-file = sjudson_app/sjudson_app.py
callable = sjudson
master = true
chmod-socket = 666
logto = /home/server/logs/uwsgi.log

首先,当我尝试运行时:

uwsgi --ini sjudson_app_uwsgi.ini

我刚刚得到:

[uWSGI] getting INI configuration from sjudson_app_uwsgi.ini

无限期。其次,当我直接从命令行运行它时:

uwsgi --socket /tmp/sjudson_app_uwsgi.sock --wsgi-file sjudson_app/sjudson_app.py --callable sjudson --master --chmod-socket=666

我明白了:

*** Starting uWSGI 2.0.3 (32bit) on [Tue Mar 25 17:58:44 2014] ***
compiled with version: 4.8.2 20131212 (Red Hat 4.8.2-7) on 25 March 2014 16:48:01
os: Linux-3.13.6-200.fc20.i686+PAE #1 SMP Fri Mar 7 17:17:53 UTC 2014
nodename: new-host-6
machine: i686
clock source: unix
detected number of CPU cores: 2
current working directory: /home/server
detected binary path: /usr/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
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 /tmp/sjudson_app_uwsgi.sock fd 3
Python version: 2.7.5 (default, Feb 19 2014, 13:47:40)  [GCC 4.8.2 20131212 (Red Hat 4.8.2-7)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x881cc40
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 127952 bytes (124 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x881cc40 pid: 1131 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1131)
spawned uWSGI worker 1 (pid: 1136, cores: 1)

但是当我尝试连接到服务器时,我收到了 502 错误。我注意到这个 stackoverflow 帖子:Flask, nginx, and uwsgi 有类似的问题,对此,赞成的答案涉及套接字权限不正确。但是,我确实有 chmod-socket=666 参数,并查看 /tmp:

srw-rw-rw-.  1 server server    0 Mar 25 17:53 sjudson_app_uwsgi.sock

所以在我看来这不是问题所在。

编辑:

意识到我忘了包含 Nginx 错误消息:

2014/03/26 07:58:38 [crit] 792#0: *15 connect() to unix:/tmp/sjudson_app_uswgi.sock 
failed (2: No such file or directory) while connecting to upstream, client: 
173.79.242.54, server: localhost, request: "GET / HTTP/1.1", upstream: 
"uwsgi://unix:/tmp/sjudson_app_uswgi.sock:", host: "173.79.242.54"

我不确定在这种情况下“没有这样的文件或目录”是什么意思。我知道 .sock 文件存在,那么它很难找到什么?

【问题讨论】:

  • 查看nginx错误日志,uWSGI是正常启动的,所以你需要知道nginx连接不上的原因。而当你以“logto”开头时,日志在指定的文件中,所以你在命令行中看不到更多内容是正常的
  • 我明白了,但这只能解释为什么我在使用 --ini 标志时看不到更多信息。它没有解释为什么我会收到 502 错误,因为日志与我在上面发布的命令行选项的输出具有相同的信息。
  • 删除 logto 指令并从终端重新运行 uwsgi。之后尝试从 nginx 重新连接(确保始终检查 nginx 错误日志)。 unix 套接字上的“没有这样的文件或目录”意味着没有进程在监听套接字。如果它仍然不起作用,请尝试使用 tcp 套接字。
  • 非常感谢您的帮助。不幸的是,它并没有解决问题。 tcp套接字是什么意思?您的意思是明确表示要运行的套接字,例如 127.0.0.1:3031?
  • 开始禁用selinux,标准系统中的tcp套接字没有权限(端口

标签: python nginx flask uwsgi fedora20


【解决方案1】:

我有几乎完全相同的设置和相同的错误消息。要修复它,我必须这样做:

  • 将我的uwsgi.ini 文件中的套接字语句更改为:

    socket = 127.0.0.1:8081
    
  • 将以下内容添加到我的nginx.conf 文件(在服务器语句之外):

    upstream uwsgi { server 127.0.0.1:8081; }
    
  • 将我的nginx.conf 文件中的位置语句更改为:

    location / { try_files $uri @uwsgi; }
    location @uwsgi {
        include uwsgi_params;
        uwsgi_pass uwsgi;
    }
    

这使得 nginx 和 uwsgi 能够通信。这些说明取自http://blog.djcentric.com/setting-up-uswgi-nginx-what-you-need-to-know/

【讨论】:

    【解决方案2】:

    请更改 nginx 配置中的字符串,来自
    uwsgi_pass unix:/tmp/sjudson_app_uswgi.sock;

    uwsgi_pass unix:///tmp/sjudson_app_uswgi.sock;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-20
      • 2020-03-04
      • 2019-02-26
      • 2019-09-27
      • 2014-04-21
      • 2015-11-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多