scalingexcellence / scrapybook

Scrapy Book Code
http://scrapybook.com/
475 stars 209 forks source link

vagrant port forward not working #21

Closed zhongwang123 closed 7 years ago

zhongwang123 commented 7 years ago

I can't open http://localhost:9312 in the host and dev,but only can do it in the web if I run curl localhost:9312, I will get a error of curl(7):connect refused......

lookfwd commented 7 years ago

Hello, from within the VM, http://web:9312 should work. from outside the VM (i.e. from a browser) http://localhost:9312 should work. Are you querying from within the VM or ouside?

zhongwang123 commented 7 years ago

I am sorry to not express well....I am query outside of VM with http://localhost:9312 and failed,within the Vm I can query http://localhost:9312 without error

zhongwang123 commented 7 years ago

After 'vagrant up',if I run 'vagrant ssh',I will enter the 'dev',and I will meet curl(7) if I run 'curl localhost:9312' however, if I run 'vagrant ssh web' after 'vagrant up', I will enter 'web' and I can query localhost:9312 successfullly

lookfwd commented 7 years ago

After 'vagrant up',if I run 'vagrant ssh',I will enter the 'dev',and I will meet curl(7) if I run 'curl localhost:9312'

Yes, this is correct.

In page 227 you can find a table with how URLs change on "dev". When you login on those virtual machines, you login on a virtual network that looks like the one in page 226. This way, in order to curl from dev to web, you do curl web:9312 because it's another virtual machine. If you are logged in on web with vagrant ssh web, curl localhost:9312 will work because that's the web server. This is a realistic environment... In production you will typically have distinct database, search, scrapyd and web (likely outside your network) servers.

I am query outside of VM with http://localhost:9312 and failed

This is a bit unexpected. We will have to follow-up if this persists after restarting

zhongwang123 commented 7 years ago

I seem to understand a little......but if I want to query the web outside the VM,what should I do? the 'localhost:9312' seems not work in the chrome

zhongwang123 commented 7 years ago

thank you very much, the problem has troubled me much, I have restarting many times, however......

lookfwd commented 7 years ago

if I want to query the web outside the VM,what should I do?

If you go to page 227 of the book, you will find a list of URLs to try. Is it just the localchost:9312 that doesn't work or all of them (in the 2nd column-there)?

If it's just 9312, then it's likely a port conflict i.e. you have something already running in 9312. In page 239 I have a few tips on re-mapping the port. All you basically have to do is to comment out line 25 from Vagrantfile.dockerhost (this line maps port 9312 to 9312 of the host) and add in line 31 (just after end) something like the following line, which will re-map port 9312 to 9316.

config.vm.network "forwarded_port", guest: 9312, host: 9316
zhongwang123 commented 7 years ago

Thank you every much! I have found that I have made a mistake when editing the Vagrantfile.dockerhost. Thanks a lot!

lookfwd commented 7 years ago

You're awesome! Well done for hacking Vagrantfile and for fixing it! :) Cheers!