无法使用uwsgi绑定Heroku上的烧瓶应用程序的端口80

时间:2020-09-20 14:44:47

标签: python flask heroku uwsgi

我写了一个简单的flask应用程序,我想将其部署到Heroku。完成推送和释放后,我查看日志并看到:

2020-09-20T14:32:06.077331+00:00 app[web.1]: *** Starting uWSGI 2.0.18 (64bit) on [Sun Sep 20 14:32:06 2020] ***
2020-09-20T14:32:06.077331+00:00 app[web.1]: compiled with version: 8.3.0 on 09 May 2020 21:28:24
2020-09-20T14:32:06.077331+00:00 app[web.1]: os: Linux-4.4.0-1076-aws #80-Ubuntu SMP Thu Aug 6 06:48:10 UTC 2020
2020-09-20T14:32:06.077335+00:00 app[web.1]: nodename: 8a7c5567-c468-4b88-aae5-7c8917589599
2020-09-20T14:32:06.077335+00:00 app[web.1]: machine: x86_64
2020-09-20T14:32:06.077336+00:00 app[web.1]: clock source: unix
2020-09-20T14:32:06.077336+00:00 app[web.1]: pcre jit disabled
2020-09-20T14:32:06.077337+00:00 app[web.1]: detected number of CPU cores: 8
2020-09-20T14:32:06.077337+00:00 app[web.1]: current working directory: /app
2020-09-20T14:32:06.077338+00:00 app[web.1]: detected binary path: /usr/local/bin/uwsgi
2020-09-20T14:32:06.077338+00:00 app[web.1]: your processes number limit is 256
2020-09-20T14:32:06.077338+00:00 app[web.1]: your memory page size is 4096 bytes
2020-09-20T14:32:06.077339+00:00 app[web.1]: detected max file descriptor number: 10000
2020-09-20T14:32:06.077339+00:00 app[web.1]: lock engine: pthread robust mutexes
2020-09-20T14:32:06.077455+00:00 app[web.1]: thunder lock: disabled (you can enable it with --thunder-lock)
2020-09-20T14:32:06.078001+00:00 app[web.1]: uwsgi socket 0 bound to TCP address :13940 fd 3
2020-09-20T14:32:06.078116+00:00 app[web.1]: unable to find user nginx
2020-09-20T14:32:06.078731+00:00 app[web.1]: 2020-09-20 14:32:06,078 INFO exited: uwsgi (exit status 1; not expected)
2020-09-20T14:32:07.081401+00:00 app[web.1]: 2020-09-20 14:32:07,081 INFO spawned: 'nginx' with pid 14
2020-09-20T14:32:07.082947+00:00 app[web.1]: 2020-09-20 14:32:07,082 INFO spawned: 'uwsgi' with pid 15
2020-09-20T14:32:07.089800+00:00 app[web.1]: 2020/09/20 14:32:07 [warn] 14#14: the "user" directive makes sense only if the master process runs with super
-user privileges, ignored in /etc/nginx/nginx.conf:1
2020-09-20T14:32:07.089801+00:00 app[web.1]: nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ig
nored in /etc/nginx/nginx.conf:1
2020-09-20T14:32:07.090605+00:00 app[web.1]: 2020/09/20 14:32:07 [emerg] 14#14: bind() to 0.0.0.0:80 failed (13: Permission denied)
2020-09-20T14:32:07.090606+00:00 app[web.1]: nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
2020-09-20T14:32:07.091044+00:00 app[web.1]: 2020-09-20 14:32:07,090 INFO exited: nginx (exit status 1; not expected)
2020-09-20T14:32:07.093198+00:00 app[web.1]: [uWSGI] getting INI configuration from /app/uwsgi.ini
2020-09-20T14:32:07.093264+00:00 app[web.1]: 2020-09-20 14:32:07,093 INFO gave up: nginx entered FATAL state, too many start retries too quickly
2020-09-20T14:32:07.093377+00:00 app[web.1]: [uWSGI] getting INI configuration from /etc/uwsgi/uwsgi.ini

看起来,它无法绑定端口80。 这是我的__主要__:

if __name__ == '__main__':
    port = int(os.environ.get('PORT', 5000))
    webapp.run(debug=True, host='0.0.0.0', port=port)

这是我的uswgi.init:

[uwsgi]
module = app.ourtale
callable = webapp
master=true
http-socket = :$(PORT)

这是我的procfile:

web: uwsgi --http-socket :$PORT --ini uwsgi.ini

这是我的dockerfile:

FROM tiangolo/uwsgi-nginx-flask:python3.6

COPY requirements.txt /tmp/
RUN pip install -U pip
RUN pip install -r /tmp/requirements.txt

USER nginx //EDIT: Added this line, but it doesn't seem fix the "unable to find user nginx"

COPY . /app

有人知道为什么它无法绑定端口80吗? 预先感谢

更新: 我加了

ENV LISTEN_PORT 8080
EXPOSE 8080

而且似乎解决了无许可问题。 但它似乎仍然崩溃。这些是日志:

2020-09-20T18:14:00.337298+00:00 app[web.1]: *** Starting uWSGI 2.0.18 (64bit) on [Sun Sep 20 18:14:00 2020] ***
2020-09-20T18:14:00.337298+00:00 app[web.1]: compiled with version: 8.3.0 on 09 May 2020 21:28:24
2020-09-20T18:14:00.337299+00:00 app[web.1]: os: Linux-4.4.0-1076-aws #80-Ubuntu SMP Thu Aug 6 06:48:10 UTC 2020
2020-09-20T18:14:00.337300+00:00 app[web.1]: nodename: bb979578-c952-46fc-9710-02e06bbfe136
2020-09-20T18:14:00.337300+00:00 app[web.1]: machine: x86_64
2020-09-20T18:14:00.337301+00:00 app[web.1]: clock source: unix
2020-09-20T18:14:00.337301+00:00 app[web.1]: pcre jit disabled
2020-09-20T18:14:00.337301+00:00 app[web.1]: detected number of CPU cores: 8
2020-09-20T18:14:00.337302+00:00 app[web.1]: current working directory: /app
2020-09-20T18:14:00.337302+00:00 app[web.1]: detected binary path: /usr/local/bin/uwsgi
2020-09-20T18:14:00.337303+00:00 app[web.1]: your processes number limit is 256
2020-09-20T18:14:00.337303+00:00 app[web.1]: your memory page size is 4096 bytes
2020-09-20T18:14:00.337304+00:00 app[web.1]: detected max file descriptor number: 10000
2020-09-20T18:14:00.337304+00:00 app[web.1]: lock engine: pthread robust mutexes
2020-09-20T18:14:00.337398+00:00 app[web.1]: thunder lock: disabled (you can enable it with --thunder-lock)
2020-09-20T18:14:00.337835+00:00 app[web.1]: uwsgi socket 0 bound to TCP address :13532 fd 3
2020-09-20T18:14:00.337932+00:00 app[web.1]: unable to find user nginx
2020-09-20T18:14:00.338440+00:00 app[web.1]: 2020-09-20 18:14:00,338 INFO exited: uwsgi (exit status 1; not expected)
2020-09-20T18:14:01.339776+00:00 app[web.1]: 2020-09-20 18:14:01,339 INFO gave up: uwsgi entered FATAL state, too many start retries too quickly
2020-09-20T18:14:51.678718+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-09-20T18:14:51.698324+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-09-20T18:14:51.807290+00:00 heroku[web.1]: Process exited with status 137
2020-09-20T18:14:51.849446+00:00 heroku[web.1]: State changed from starting to crashed

它似乎未能成功找到名为“ nginx”的用户

1 个答案:

答案 0 :(得分:1)

小于1024的端口是特权端口,需要root用户特权才能绑定。我想您不是以root用户身份运行入口点。

尝试更新默认端口nginx将绑定到HTTP,例如:https://github.com/tiangolo/uwsgi-nginx-flask-docker#custom-listen-port

这无关紧要,只要您在运行docker run时将端口80(外部)映射到此自定义端口即可。