简体   繁体   English

我如何使用Windows防火墙配置python / flask进行公共访问

[英]how do i configure python/flask for public access with windows firewall

We have developed an app in python and are using flask to expose its api via http requests. 我们在python中开发了一个应用程序,并使用flask通过http请求公开其api。

  • all this on WINDOWS - 这一切都在WINDOWS上 -

Everything works ok and we have tested in-house with no problems and we are now trying to use the app in the real world - we have gotten our IT dept to give us a public facing ip/port address (forwarded through a firewall ??) and now we can't access the server/app at all. 一切正常,我们在内部测试没有问题,我们现在正在尝试在现实世界中使用该应用程序 - 我们已经让我们的IT部门给我们一个面向公众的IP /端口地址(通过防火墙转发? )现在我们根本无法访问服务器/应用程序。

After a bit of digging, we've found the problem has something to do with the Windows Firewall configuration, when its on it won't work, when its off everything is fine. 经过一番挖掘后,我们发现问题与Windows防火墙配置有关,当它在它上面时它不起作用,当它关闭一切都很好。

the flask app code is run like so: app.run(debug=False, host='0.0.0.0', port=8080) the port 8080 is setup in the Firewall Exceptions as is python.exe in the Program Exceptions 烧瓶应用程序代码运行如下:app.run(debug = False,host ='0.0.0.0',port = 8080)端口8080在防火墙例外中设置,因为程序异常中的python.exe

netstat -a shows the app is sitting there awaiting connection. netstat -a显示应用程序正坐在那里等待连接。

If I try to access the site though chrome I get the error: ERR_CONNECTION_TIMED_OUT. 如果我尝试通过chrome访问该网站,我收到错误:ERR_CONNECTION_TIMED_OUT。

With the firewall on i'm never seeing any "hits" come through to the app at all. 随着防火墙的开启,我从来没有看到任何“点击”来到应用程序。

Is there some other configuration I'm missing? 我还缺少其他一些配置吗?

Many thanks. 非常感谢。

When running Flask from a windows machine with a firewall I open a port with the following commands: 从带防火墙的Windows机器运行Flask时,我使用以下命令打开一个端口:

netsh firewall add portopening TCP 8080 "MyAppName"
netsh advfirewall firewall add rule name="MyAppName TCP Port 8080" dir=in action=allow protocol=TCP localport=8080
netsh advfirewall firewall add rule name="MyAppName TCP Port 8080" dir=out action=allow protocol=TCP localport=8080

It work for me. 它对我有用。 Is it too much? 太多了吗? I don't know as I am not a Firewall guru :( 我不知道因为我不是防火墙大师:(

When running as a service the program running the service is not python.exe but rather pythonservice.exe . 作为服务运行时,运行该服务的程序不是python.exe ,而是pythonservice.exe You will have to add that to the allowed programs in the Windows Firewall Setup. 您必须将其添加到Windows防火墙设置中允许的程序。 In my case it is located under C:\\Python33\\Lib\\site-packages\\win32\\pythonservice.exe . 在我的情况下,它位于C:\\Python33\\Lib\\site-packages\\win32\\pythonservice.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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