我想使用IP地址测试在主机操作系统中的VM vagrant中运行的api:

时间:2019-07-18 14:59:45

标签: python python-3.x vagrant virtual-machine bottle

  • 服务器正在虚拟机中运行:

vagrant @ ubuntu-xenial:/ vagrant / email_api $ python3 emailapi.py Bottle v0.12.17服务器正在启动(使用WSGIRefServer())... 收听http://127.0.0.1:8080/ 按Ctrl-C退出。

但是当我使用IP访问api时,我得到了:

无法得到任何回应 连接到时发生错误。 为什么会发生这种情况: -服务器无法发送响应: 确保后端正常运行 -自签名SSL证书被阻止: 通过在“设置”>“常规”中关闭“ SSL证书验证”来解决此问题 -代理配置不正确 确保在“设置”>“代理”中正确配置了代理 -请求超时:  在“设置”>“常规”中更改请求超时

*无效文件:

config.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: 
true

 config.vm.network "private_network", ip: "192.168.33.10"
 config.vm.network "public_network"

2 个答案:

答案 0 :(得分:0)

您应该在0.0.0.0上运行Bottle应用,以将其导出到“其他”计算机上

app.run(host="0.0.0.0", port=80, reloader=True, debug=True)  # ...

答案 1 :(得分:0)

对我来说,我通过nginx代理将internall服务器传递得很好,只需像这样在nginx上进行配置

server{
   listen 85;
   listen [::]:85;
   server_name rsshistory.com;
   location / {
      proxy_pass http://127.0.0.1:8000/;
   }
}

在流浪汉文件中,请勿打开所有文件,只需执行此操作

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.$

# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.33.11"

现在您可以访问瓶服务器真正的192.168.33.11:85

相关问题