2015-10-22 58 views
0

我在安装Windows流浪,现在我有一个虚拟的Ubuntu,我运行一个python脚本:如何从主机浏览器访问流浪python in vagrant?

[email protected]:/vagrant/FlaskMysql/FlaskApp$ ls 
app.py static storedPro.txt templates 
[email protected]:/vagrant/FlaskMysql/FlaskApp$ python app.py 
* Running on http://127.0.0.1:5002/ (Press CTRL+C to quit) 

我Vagrantefile:

config.vm.box = "hashicorp/precise32" 
    config.vm.provision :shell, path: "bootstrap.sh" 
    config.vm.network :forwarded_port, guest: 80, host: 4567 
    config.vm.network :forwarded_port, guest: 5002, host: 5002 

我试图从浏览器访问上面的地址在我的窗口,index.html页面在几秒钟后出现,然后消失。

UPDATE:

[email protected]:/vagrant/FlaskMysql/FlaskApp$ curl http://127.0.0.1:5000 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 
<title>500 Internal Server Error</title> 
<h1>Internal Server Error</h1> 
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or 
there is an error in the application.</p> 

感谢。

+1

您的主机需要将5002转发到访客机器端口5002? – dm03514

+0

我已经添加了:config.vm.network:forwarded_port,guest:5002,host:5002但仍然得到:此网页不可用 –

回答

1

除了转发,您需要与主机"0.0.0.0"运行瓶应用程序的端口:

app.run(host='0.0.0.0', port=5002) 

这使得开发服务器外部可见;在Vagrant的情况下,我们希望应用程序在外部可见(从客户操作系统到主机操作系统)。

+0

我将它改为app.run(host ='0.0.0.0',port = 5002)正如你所说的,当我去http://0.0.0.0:5002/时,我总是得到:这个网页不可用 –

+0

@BouchaibMounir从主机上的浏览器中,你可以进入http://127.0。 0.1:5002'来访问该网站。 – chucksmash

+0

我在我的问题中添加了一个更新,卷曲。 –

相关问题