如何在子域上部署Docker化的Flask Web应用

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

How to deploy dockerised Flask web app on a subdomain

问题

我有一个Docker化的Flask应用,并想要部署到自定义域名上。

我想要的是在mydomain.com上创建一个WordPress用于主要网站(展示博客和一切使其更简单),然后在app.mydomain.com上部署我的Flask应用。

首先,这是一个好主意吗?如果是的话,最佳的连接方式是什么?

提前感谢!

英文:

I have a dockerised flask app and want to deploy it on a custom domain.

What I would like would be to create a WordPress for the main website (presentation blog and everything to make it simpler) on mydomain.com and deploy my flask app on app.mydomain.com

First of all is it a good idea ? And if so what is the best way to connect both in a good way ?

Thanks in advance !

答案1

得分: 1

你可以使用反向代理,比如 nginx 来解决这个问题。通过使用 nginx,你可以根据请求的域名将其重定向到正确的应用程序。

伪代码nginx配置:

 server {
        #你的其他配置...

        #将来自your.domain.com的所有请求重定向到你的WordPress应用程序。
        if ($host = your.domain.com) {
            #将流量重定向到WordPress上游
        }

       #将所有不安全的www请求重定向到安全的www
        if ($host = your.sub.domain.com) {
            #将流量重定向到Flask上游
        }
    }
英文:

You can solve the problem using a reverse proxy such as nginx.
By using nginx you will be able to redirect the request to the correct application depending on the domain it comes from.

pseudo nginx configuration:

 server {
        #your other config....

        #redirect all request from your.domain.com to your wordpress app.
        if ($host = your.domain.com) {
            #redirect traffic to wordpress upstream
        }

       #redirect all unsecure www to secure www
        if ($host = your.sub.domain.com) {
            #redirect traffic to flask upstream
        }
    }

huangapple
  • 本文由 发表于 2023年3月31日 18:17:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75897374.html
匿名

发表评论

匿名网友

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

确定