将子域重定向到端口 [nginx/flask] [英] Redirect subdomain to port [nginx/flask]

查看:34
本文介绍了将子域重定向到端口 [nginx/flask]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个常见问题,并且有相同的答案,但我问这个问题的原因是因为我不知道如何解决这个问题.根据我决定的方式,我可以选择更改的解决方案.总之,

I know that this is a common question, and there are answers for the same, but the reason I ask this question is because I do not know how to approach the solution. Depending on the way I decide to do it, the solution I can pick changes. Anyways,

我有一个 AWS EC2 实例.我的 DNS 由 Route53 处理,我拥有 example.com.目前,在我的实例上,有两个服务正在运行:

I have an AWS EC2 instance. My DNS is handled by Route53 and I own example.com. Currently, on my instance, there are two services running:

example.com:80 [nginx/php/wordpress]
example.com:8142 [flask]

我想做的是,让 app.example.com 指向 example.com:8142.我该怎么做呢?我很确定我必须将 app.example.com 指向与 example.com 相同的 IP,因为它是为它提供服务的同一个框.而且,nginx 将是第一个在端口 80 处理这些请求的.有没有办法让 nginx 将所有请求转发到 localhost:8142?

What I want to do is, make app.example.com point to example.com:8142. How exactly do I go about doing this? I am pretty sure that I will have to point app.example.com to the same IP as example.com, since it is the same box that will be serving it. And, nginx will be the first one to handle these requests at port 80. Is there a way with which I can make nginx forward all requests to localhost:8142?

有没有更好的方法可以解决这个问题?

Is there a better way that I can solve this problem?

推荐答案

你可以为 app.example.com 添加一个虚拟主机,监听 80 端口,然后代理将所有请求传递给flask:

You could add a virtual host for app.example.com that listens on port 80 then proxy pass all requests to flask:

server {
    listen 80;
    server_name app.example.com;

    location / {
        proxy_pass http://localhost:8142;
    }   
}

这篇关于将子域重定向到端口 [nginx/flask]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆