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

查看:96
本文介绍了重定向子域到端口[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天全站免登陆