简体   繁体   中英

Custom Raspberry Pi hostname to run Flask app

I want to run a Python Flask app with a Raspberry Pi. The pi is connected through a router. Thus the Flask web app can be viewed from other devices connected to the router. However, my raspberry pi IP address is 192.168.1.145 and the app runs with this URL 192.168.1.145:5000. I would give a meaningful hostname to the raspberry pi like flaskserver:5000 and make it accessible to other devices connected to the same router as pi.

I have tried the following steps-

  1. In flask app my code is app.config['SERVER_NAME'] = 'flaskserver:5000' app.run(host = '192.168.1.145', port = 5000, debug=True, use_reloader=False)
  2. I have added this line to my /etc/hosts 192.168.1.145. flaskserver That did not work. So I tried - 127.0.0.1 flaskserver
  3. I have also tried the following code for my flask server - app.config['SERVER_NAME'] = 'flaskserver:5000' app.run(host = 'flaskserver', port = 5000, debug=True, use_reloader=False)

I am making a lot of trial and error with the configurations. So far nothing has worked. Any advice would be appreciated. Thank you.

我会尝试使用反向代理(例如 nginx)将您的应用程序公开到端口 80。然后将主机文件更改为您想要的任何内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM