【问题标题】:Starting uWSGI server without sudo不使用 sudo 启动 uWSGI 服务器
【发布时间】:2015-03-25 02:23:10
【问题描述】:

我正在尝试使用 uWSGI 部署我的 Flask 应用程序,但如果没有 sudo,我似乎无法做到这一点。

这是我的启动脚本:

#!/bin/bash
set -v
set -e
cd /var/hpit/hpit_services
/var/hpit/hpit_services/env/bin/uwsgi --http [::]:80 --master --module wsgi --callable app --processes 4 --daemonize ../log/uwsgi.log --pidfile ../server_pid_file.pid
echo server started

这是我在日志中得到的:

*** Starting uWSGI 2.0.9 (64bit) on [Mon Jan 26 15:53:26 2015] ***
compiled with version: 4.8.2 on 23 January 2015 20:35:44
os: Linux-3.18.1-x86_64-linode50 #1 SMP Tue Jan 6 12:14:10 EST 2015
nodename: <<blocked out>>
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /var/hpit/hpit_services
writing pidfile to ../server_pid_file.pid
detected binary path: /var/hpit/hpit_services/env/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
your processes number limit is 7962
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)
bind(): Permission denied [core/socket.c line 764]

Core/socket.c 第 764 行有这个:

if (bind(serverfd, (struct sockaddr *) &uws_addr, addr_len) != 0) {
    if (errno == EADDRINUSE) {
        uwsgi_log("probably another instance of uWSGI is running on the same address (%s).\n", socket_name);
    }
    uwsgi_error("bind()");
    uwsgi_nuclear_blast();
    return -1;
}

但我没有运行 uWSGI 的实例。这似乎是一个权限问题。我对 /var/hpit、/var/hpit/hpit_services(应用程序的位置)和 /var/hpit/log 的权限是 bsauer:www-data。我的用户我们是 bsauer。

如果我将sudo -E 附加到我的启动脚本中调用uWSGI 二进制文件的行,它似乎可以正常启动,但我读到服务器不应该以sudo 启动。我在工作中继承了这个系统管理员角色,对这一切有点陌生。

这是我的预感/沉思:

  • 我知道 uWSGI 可以从一个用户开始,然后进入另一个用户角色,但我不太了解这个过程,所以也许这就是问题所在。
  • uWSGI 正在尝试访问我不知道的系统上的某些内容

感谢您的帮助,如有需要,我可以提供更多详细信息。

编辑

奇怪的是,我的 /var/hpit/log/uwsgi.log 文件归 bsauer:bsauer 所有,而不是我预期的 bsauer:www-data 或 www-data:www-data...

EDIT2

好的,从页面底部的http://projects.unbit.it/uwsgi/wiki/Example 看来,问题似乎在端口 80 上运行。我将其更改为 8080,但它仍然以 bsauer 运行,我认为我不想要.

【问题讨论】:

    标签: flask uwsgi


    【解决方案1】:

    据我所知,这是我想出的,如果有人想把它放在更清晰的系统管理员语言中,我会很乐意编辑。

    该解决方案毕竟与日志无关。问题是端口 80,默认 HTTP 端口,受系统保护,只有 root 可以绑定到该端口。没有 sudo,它不会让你绑定。绑定到另一个端口,如端口 8080,工作正常。

    我想绑定到端口 80,但仍将服务器作为 www-data 运行,所以我最终关注了此页面的最底部:http://projects.unbit.it/uwsgi/wiki/Example。基本上80端口的socket是共享的,uWSGI可以先sudo访问,然后下拉到www-data中运行服务器。

    在调用 uWSGI 二进制文件之前,我仍然必须使用sudo -E,因为它需要 root 权限才能更改 uWSGI 的用户和组 ID,但这没关系,因为最终结果是服务器随后以非常受限的 www-data 用户运行.

    最后,我的服务器起始行是: sudo -E /var/hpit/hpit_services/env/bin/uwsgi --shared-socket [::]:80 --http =0 --uid 33 --gid 33 --master --module wsgi --callable app --processes 4 --daemonize ../log/uwsgi.log --pidfile ../server_pid_file.pid

    【讨论】:

      猜你喜欢
      • 2013-05-09
      • 2012-01-02
      • 1970-01-01
      • 2012-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-11
      相关资源
      最近更新 更多