0

I use Vagrant boxes for a number of projects and I've had no problem until this. To help my documentation crew I setup MkDocs with Vagrant and everything works up to the point I want to browser from the host.

I use scotch/box 3.5 free version, Python 2.7.12, I've installed pip 18.1 and I start sudo mkdocs serve. I know it's working because I can curl http://127.0.0.1:8000 but when I browse on the host http://192.168.33.10:8000/ returns

This site can’t be reached 192.168.33.10 refused to connect.
Search Google for 192 168 8000
ERR_CONNECTION_REFUSED

Browsing http://192.168.33.10 will return Scotch IO box's /public/index.php

I also tried shutting down the box's apache server but that didn't help either. Does anyone see what is incorrect in my setup?

Vagrantfile

Vagrant.configure("2") do |config|

    # /*=====================================
    # =            FREE VERSION!            =
    # =====================================*/
    # This is the free (still awesome) version of Scotch Box.
    # Please go Pro to support the project and get more features.
    # Check out https://box.scotch.io to learn more. Thanks

    config.vm.box = "scotch/box"
    config.vm.network "private_network", ip: "192.168.33.10"
    config.vm.network "forwarded_port", guest: 8000, host: 8000
    config.vm.hostname = "scotchbox"
    config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]

    # Optional NFS. Make sure to remove other synced_folder line too
    #config.vm.synced_folder ".", "/var/www", :nfs => { :mount_options => ["dmode=777","fmode=666"] }

    config.vm.provision "shell", path: "deploy.sh"
end

deploy.sh #!/usr/bin/env bash

apt-get update
apt-get install -y python-pip
pip install mkdocs

UPDATE

I can see the MkDocs is running and detects changes to the source files.

enter image description here

Servers running on the box.

enter image description here

chris loughnane
  • 2,648
  • 4
  • 33
  • 54
  • Check the logs for your port 8000 server to see if the request is actually getting there but is being ignored / rejected because the "Host" header will be for 192.168.33.10 which the server doesn't recognise. (If that server is nginx I'd guess this is the issue - you need more ServerName directives.) If not, you need to work out whether the forwarded traffic is really getting through to the Vagrant host or not, e.g. by checking `netstat -ano` or `-anp` on your host (depending on Windows or Linux) to see who owns port 8000 on the host. – Rup Nov 27 '18 at 00:29
  • Thanks for you comment. It's an apache server on the scotch box and `http://192.168.33.10/` will load any page setup under the `/var/www/public` folder. I surmised the apache server is taking over but even if I shut it down I still can't get access to `http://192.168.33.10:8000/` so I think the box doesn't know to allow `MkDocs` to handle requests on port `8000`. Unfortunately I don't know how to tell it to. – chris loughnane Nov 27 '18 at 11:30
  • I meant what HTTP server was serving port 8000, but that looks like a simple Python server so I'd guess that's not too fussy about Host headers. I also meant the netstat on your container host just to make sure that it is set up to listen to port 8000 there. When you say you get "page does not exist" is that a 404 error served by some server you can't identify, or a failure to connect to the port ("This site can’t be reached. 192.168.33.10 refused to connect." or similar). Is there a firewall on your VM that's blocking this? e.g. you might need something like https://askubuntu.com/q/911765 – Rup Nov 27 '18 at 11:55
  • Scotch box comes with an apache server and even if I shut this down I get the same response. MKDocs is built in python, I'll continue searching for an answer. – chris loughnane Nov 27 '18 at 12:05
  • Yes, sure. Your mkdocs server is nothing to do with Apache. What could be going wrong: 1) there's nothing listening on 192.168.33.10 to accept connections on port 8000; 2) there is something listening there to forward connections into vagrant on port 8000 but vagrant is refusing the connection. 3) the connection is getting through to vagrant on port 8000 but the server there (which will be mkdocs) is returning a 'not found' error. I think your first step needs to be working out which one of these this is. If you're getting "ERR_CONNECTION_REFUSED" I think it's 1. – Rup Nov 27 '18 at 12:23

1 Answers1

1

Thank you Rup for your help and comments, they helped guide me to the right answer.

I looked at the iptables again and I spotted that the python server is starting but it is being served to the host on mkdocs default loopback address 127.0.0.1 so if I define its address with

mkdocs serve --dev-addr 0.0.0.0:8000

I can browse from the host :)

I learned a few things from your comments, if you could put the last comment in an answer I'll tick it as accepted answer.

chris loughnane
  • 2,648
  • 4
  • 33
  • 54