如何在AWS Ubuntu的启用端口5000 [英] How to enable port 5000 on AWS ubuntu

查看:225
本文介绍了如何在AWS Ubuntu的启用端口5000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在端口5000 AWS Ubuntu的服务器上运行的应用程序瓶(瓶运行的默认端口5000)。但是,当我试图访问服务器的端口上,它从来没有连接。

I have a flask app running on AWS Ubuntu server on port 5000 (flask runs default on port 5000). But when I try to access the server on that port, it never connects.

我加在AWS控制台安全组为自定义的TCP 端口 5000 任何IP地址 0.0.0.0/0 ,但我仍然不能访问它。

I added a security group on AWS console as Custom TCP on port 5000 for any ip address 0.0.0.0/0, but still I cannot access it.

我一定要重新启动服务器?还是我缺少什么?

Do I have to restart the server? Or am I missing anything?

让我知道,任何额外的信息来提供。

Let me know any additional information to provide.

推荐答案

在除了允许通过安全组访问端口是5000,你还需要确保你的应用程序正在监听它可以接受来自外部TCP连接的IP 。要侦听所有IP地址,你的应用程序,使用方法:

In addition to allowing access to port 5000 via the Security Group, you also need to ensure that your app is listening on an IP which can accept TCP connections from outside. To listen on all IPs, in your app, use:

if __name__ == '__main__':
    app.run(host='0.0.0.0', debug = False)

相反的:

if __name__ == '__main__':
    app.run(host='127.0.0.1', debug = False)

要看看有什么解决您的应用程序正在监听,你可以运行这个命令:

To see what address your application is listening on, you can run this command:

netstat -an | grep :5000

在做了这些改变,你将要重新启动瓶的应用程序。

After making these changes, you will want to restart your Flask application.

我假设你仅仅使用这种用于开发和测试,因为你保持它的端口 5000 ,但是,当你准备部署您的应用程序投入生产,你需要把它背后真正的网络服务器。我会建议使用 nginx的,提供的 uWSGI 。 <一href="https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-14-04"相对=nofollow>这里是一个指南来配置瓶+的nginx + uWSGI,这里是的从主题瓶的官方文档。

I'm assuming you're just using this for development and testing, since you're keeping it on port 5000, but, when you're ready to deploy your application into production, you need to put it behind a real webserver. I would recommend using nginx with uWSGI. Here is a guide to configuring Flask + nginx + uWSGI, and here is the official documentation from Flask on the subject.

这篇关于如何在AWS Ubuntu的启用端口5000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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