无法在Ubuntu服务器上使用Gunicorn启动Flask应用。

huangapple go评论76阅读模式
英文:

Cant start flask app using gunicorn on ubuntu server

问题

你好,我明白你遇到了问题。根据你的描述,看起来这是一个权限问题,因为端口443是特权端口,需要特殊权限来运行服务。你可以尝试以下解决方法:

  1. 确保你的Flask应用程序有足够的权限来绑定到443端口。你可以使用root用户或者sudo命令来运行你的应用程序,但请确保以安全的方式进行。

  2. 如果你不想使用root用户来运行应用程序,你可以考虑使用反向代理,比如Nginx或Apache,来代理到Flask应用程序,并允许它监听一个高于1024的端口,然后由反向代理服务器处理443端口。

  3. 确保你的SSL证书文件(cert.pem和key.pem)的路径和权限设置正确,以便应用程序可以访问它们。

请按照这些步骤检查你的配置,看看是否有帮助。如果还有其他问题,请提供更多信息以便我能够提供更具体的建议。

英文:

Hello guys so I am trying to make flask app running on ubuntu server and i get this error every time i try to start it. I got here so far

× flaskapp.service - Flask App
     Loaded: loaded (/etc/systemd/system/flaskapp.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2023-06-27 11:35:53 UTC; 14min ago
    Process: 1689 ExecStart=/home/maxnet/.local/bin/gunicorn -w 4 -b 0.0.0.0:443 --certfile=/var/www/flaskapp/certs/cert.pem --keyfile=/var/www/flaskapp/certs/key.pem app:app (code=exited,>
   Main PID: 1689 (code=exited, status=1/FAILURE)
        CPU: 553ms

Jun 27 11:35:47 ubuntu-dev01 systemd[1]: Started Flask App.
Jun 27 11:35:48 ubuntu-dev01 gunicorn[1689]: [2023-06-27 11:35:48 +0000] [1689] [INFO] Starting gunicorn 20.1.0
Jun 27 11:35:48 ubuntu-dev01 gunicorn[1689]: [2023-06-27 11:35:48 +0000] [1689] [ERROR] Retrying in 1 second.
Jun 27 11:35:49 ubuntu-dev01 gunicorn[1689]: [2023-06-27 11:35:49 +0000] [1689] [ERROR] Retrying in 1 second.
Jun 27 11:35:50 ubuntu-dev01 gunicorn[1689]: [2023-06-27 11:35:50 +0000] [1689] [ERROR] Retrying in 1 second.
Jun 27 11:35:51 ubuntu-dev01 gunicorn[1689]: [2023-06-27 11:35:51 +0000] [1689] [ERROR] Retrying in 1 second.
Jun 27 11:35:52 ubuntu-dev01 gunicorn[1689]: [2023-06-27 11:35:52 +0000] [1689] [ERROR] Retrying in 1 second.
Jun 27 11:35:53 ubuntu-dev01 gunicorn[1689]: [2023-06-27 11:35:53 +0000] [1689] [ERROR] Can't connect to ('0.0.0.0', 443)
Jun 27 11:35:53 ubuntu-dev01 systemd[1]: flaskapp.service: Main process exited, code=exited, status=1/FAILURE
Jun 27 11:35:53 ubuntu-dev01 systemd[1]: flaskapp.service: Failed with result 'exit-code'.
~

I think this is some permision stuff but not sure. I have to be honest that i dont use ubuntu server that often. Also want to mention that i NEED it to run on port 443. I was reading something about ports that are less than 1024 are privileged but actually dont know what to do with that.

(This is my first post, if is something missing just tell me i will try to provide more)

答案1

得分: 1

我做的基本上就是四处搜寻,发现在 Flask 应用中我设置了 port=443,我只是删除了它,然后它就能正常工作。

...一个月后

英文:

Okay so basicly what i did was snooping around and finding out and in flask app i had set port=443 and i just deleted and it works.

...After month

huangapple
  • 本文由 发表于 2023年6月27日 20:01:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76564663.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定