我有这个Vagrant文件
# encoding: utf-8
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.ssh.forward_agent = true
config.vm.boot_timeout = 300
config.vm.network "private_network", ip: "192.168.30.20"
config.vm.network :forwarded_port, guest: 8080, host: 8080
config.vm.synced_folder "", "/vagrant", type: "nfs"
config.vm.provision "shell", inline: <<-SHELL
apt-get install python-pip build-essential python-dev -y
pip install bottle
SHELL
config.vm.provider "virtualbox" do |v|
v.name = "M101P"
v.memory = 524
end
config.vm.define :M101P do |t|
config.vm.hostname = "M101P"
end
end
这是一个学习pybottle的流浪汉机器......
我有这个代码:(hello.py)
from bottle import route, run, template
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
run(host='localhost', port=8080, debug=True)
但是,当我托盘访问服务器后,make
python hello.py
python hello_bottle.py
Bottle v0.12.9 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
服务器正在运行,但是如果y托盘要访问...
curl 192.168.30.20:8080/hello/world
curl: (7) Failed to connect to 192.168.30.20 port 8080: Connection refused
我可能做错了什么?
答案 0 :(得分:0)
服务器只绑定到localhost,即127.0.0.1; 如果您想通过服务器ip访问服务器,您必须更改
run(host='localhost', port=8080, debug=True)
到
run(host='0.0.0.0', port=8080, debug=True)