我正在尝试使用 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 ...

    编辑2

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

    最佳答案

    据我所知,这就是我想出的,如果有人想说这是更清晰的系统管理员语言,我很乐意编辑。

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

    我想绑定(bind)到端口 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

    关于flask - 在没有 sudo 的情况下启动 uWSGI 服务器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28154075/

    10-15 09:45