如何正确将Django应用程序使用Dokku、Nginx和Gunicorn进行迁移。

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

How to properly port Django app using Dokku, Nginx, and guinicorn

问题

我试图设置一个提供给我的Django应用的开发版本。这是一个非常庞大的应用程序(并且没有文档),它使用Dockerfile在Dokku上构建。

我不太明白Dokku是如何管理Nginx和容器之间的交互的。我只想在我的EC2公共IP地址上建立一个HTTP连接,以提供我的Django应用程序。

首先,为什么当我从我的Docker文件部署应用到Dokku时,底部会显示“应用部署到 -> 地址:随机端口”。这个随机端口是Nginx端口还是与容器通信的端口?

在尝试过程中,我的DOKKU_PROXY_PORT设置为随机端口,端口映射设置为80:5000。在这些设置下,我会得到Nginx的欢迎页面,或者使用端口映射80:随机端口会超时。

后来我在网上找到了一些指南,说要将DOKKU_PROXY_PORT设置为80,端口映射设置为http:80:5000,并将虚拟主机设置为公共IP。我这样做了,我认为这是正确的,因为现在我得到了一个蓝屏(我认为是因为工作者不断重新启动,因为settings.py中的Redis HOST变量在调用中引发了错误,我仍在研究如何修复这个问题)。

所以我想知道这是否正确,以及Dokku是如何运作的?为什么我不能将domains-global设置为IP而不是虚拟主机,为什么一些网上的人建议不使用虚拟主机?而且Gunicorn是否自动监听5000:5000(在容器内部:向Dokku公开),我的设置显示Gunicorn设置为8080,但日志显示它使用5000。我真的在努力理解这一切。

英文:

Im trying to set up a development version of a Django app that was provided to me. It is a very large application (and undocumented) and uses a dockerfile to build on dokku.

I’m not understanding how dokku manages nginx and container interactions. All I want to do is set up a http connection at my EC2 public ip address that serves my Django application.

Firstly why is it that when I deploy my app from my docker file on dokku, at the bottom it says app deployed to -> address:random_port. Is this random port the nginx port or the container port to communicate with?

Before messing with this my DOKKU_PROXXY_PORT was set to the random port and my port mapping was 80:5000. With these settings I would get the nginx welcome page or with port mapping 80:random_port I would time out.

Now I found instructions online that said to set DOKKU_PROXXY_PORT to 80, port mapping to http:80:5000 and the vhost to the public ip. I did this and I think it’s correct because now I’m getting a blue screen (which I think is caused by the workers constantly restarting because the redis HOST variable is throwing an error from the call in settings.py, I’m still looking into how to fix this as well).

So I guess I’m wondering if this is correct and how exactly this all is working with dokku? Why can I not set the domains-global to the ip instead of vhost, and why do some people online recommend not to use vhost? And does guinicorn automatically listen on 5000:5000(inside container:exposed to dokku) inside dokku (my settings say guinicorn is set to 8080 but logs say it’s using 5000). I’m really trying to make sense of all of this.

答案1

得分: 0

这不是一个完整的答案,但我目前还不能添加评论。

已经有一段时间了,但dokku会安装Nginx并为您设置反向代理。代理端口是容器的端口。但在这个阶段,除非您在该端口上运行其他内容,否则我建议不要担心它。

在域名方面,我们只是每次部署时添加:部署时

Dokku会自动为您设置反向代理,因此您添加到应用程序的任何域名都是最终用户访问的内容,但内容来自容器。

我唯一建议的是使用SSL(Letsencrypt或您自己的SSL):https://dokku.com/docs/deployment/application-deployment/#setting-up-ssl

一旦您掌握了它,可以尝试复制他们的nginx模板并自定义它

英文:

This is not a complete answer, but I can't add comments yet.

It has been a while, but dokku takes care of installing Nginx and setting up the reverse proxy for you. The proxy port is that of the container. But, at this stage, I would say don't worry about it unless you have something else running on that port.

In terms of domain, we only added per add, when deploying it

Dokku sets up the reverse proxy for you automatically, so whatever domain you added to your app would what your end-users access, but the content comes from the container.

The only thing I would suggest is SSL (Letsencrypt or your own): https://dokku.com/docs/deployment/application-deployment/#setting-up-ssl

Once you have got the hung of it, you can try copying their nginx template and customising it.

huangapple
  • 本文由 发表于 2023年4月7日 04:03:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75953348.html
匿名

发表评论

匿名网友

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

确定