Vagrant port not exposed - django

I am using an ubuntu/xenial64 vagrant box and following the instructions indicated here to set up a readthedocs server.
I am also hard coding a static private net IP in Vagrantfile:
config.vm.network "private_network", ip: "192.168.33.10"
However, after starting the Django server:
(rtd) vagrant#ubuntu-xenial:~/rtd/checkouts/readthedocs.org$ python manage.py runserver
[14/Mar/2018 05:22:40] root:120[1581]: INFO Generating grammar tables from /usr/lib/python2.7/lib2to3/Grammar.txt
[14/Mar/2018 05:22:40] root:120[1581]: INFO Generating grammar tables from /usr/lib/python2.7/lib2to3/PatternGrammar.txt
[14/Mar/2018 05:22:41] root:120[1585]: INFO Generating grammar tables from /usr/lib/python2.7/lib2to3/Grammar.txt
[14/Mar/2018 05:22:41] root:120[1585]: INFO Generating grammar tables from /usr/lib/python2.7/lib2to3/PatternGrammar.txt
Performing system checks...
System check identified some issues:
WARNINGS:
?: (1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your default TEMPLATES dict: TEMPLATE_DEBUG.
?: (guardian.W001) Guardian authentication backend is not hooked. You can add this in settings as eg: `AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend', 'guardian.backends.ObjectPermissionBackend')`.
System check identified 2 issues (1 silenced).
March 14, 2018 - 05:22:42
Django version 1.9.12, using settings 'readthedocs.settings.dev'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
I am unable to access http://192.168.33.10:8000/
Within the vagrant machine:
vagrant#ubuntu-xenial:~$ netstat -ta
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 localhost:8000 *:* LISTEN
tcp 0 0 localhost:6379 *:* LISTEN
Using
$ vagrant --version
Vagrant 2.0.2
and Virtualbox 5.2.8 r121009 (Qt5.6.1) on Ubuntu 16.04.03 host.

Everything is detailed at the end of the document
For builds to properly kick off as expected, it is necessary the port
you’re serving on (i.e. runserver 0.0.0.0:8080) match the port defined
in PRODUCTION_DOMAIN. You can utilize local_settings.py to modify
this. (By default, it’s localhost:8000)
You can do one of the two:
start the server with python manage.py runserver 0.0.0.0:8080
update local_settings.py and change localhost:8000 with 0.0.0.0:8080
You can also replace 0.0.0.0 with the IP you've configured for the VM

Related

How to run daphne in localhost with https and mkcert

I am trying to run a django-channels project locally using https (the app has a facebook login that requires https).
I have followed the instructions for generating a key and certificate using mkcert ( https://github.com/FiloSottile/mkcert ) and have attempted to use the key and certificate by running daphne -e ssl:443:privateKey=localhost+1-key.pem:certKey=localhost+1.pem django_project.asgi:application -p 8000 -b 0.0.0.0
The server seems to be starting OK however when I try to visit https://0.0.0.0:8000 nothing happens and eventually I get a 'took too long to respond' message.
No new output is added to the standard daphne output that appears when I start up the server:
2019-07-16 19:23:27,818 INFO HTTP/2 support enabled
2019-07-16 19:23:27,818 INFO Configuring endpoint ssl:8443:privateKey=../sec/localhost+1-key.pem:certKey=../sec/localhost+1.pem
2019-07-16 19:23:27,823 INFO Listening on TCP address 0.0.0.0:8443
2019-07-16 19:23:27,823 INFO Configuring endpoint tcp:port=8000:interface=0.0.0.0
2019-07-16 19:23:27,824 INFO Listening on TCP address 0.0.0.0:8000
Can anyone help with this?
You should map the 8000 host port to port 443 of the container while runnig the server.
docker run ... -p 8000:443 ...
Turns out that setting up the Twisted ssl stuff overrides the port that you're setting up in daphne, so in the example above, the site would be shown on port 443

Issues with accessing Django app on remote server; manually assigning IP address does not work [duplicate]

This is probably a very basic question. I SSH to my virtual Ubuntu server and start a django webserver running on localhost:
Downloading/unpacking django
Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
Installing collected packages: django
Successfully installed django
Cleaning up...
Performing system checks...
System check identified no issues (0 silenced).
You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.
April 13, 2016 - 14:16:19
Django version 1.9.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
The Ubuntu server has a static IP [x.xxx.xxx.xxx] so from another machine on another network I try to access the above website in a browser using that static IP address:
x.xxx.xxx.xxx:8000
But I get:
This site can’t be reached
x.xxx.xxx.xxx refused to connect.
ERR_CONNECTION_REFUSED
So I assume that I cannot access the website like this and that is only available on the host it self even though the host has an external/static IP address?
Edit:
The answer is also in:
https://docs.djangoproject.com/en/1.9/intro/tutorial01/#the-development-server
python manage.py runserver 0.0.0.0:8000
You need to run your web server on 0.0.0.0:8000, then externally you would use either ip or host name to access. Using 0.0.0.0 means the django service would listen to all configured network interfaces.
Check wikipedia on details about 0.0.0.0.
Another answer on serverfault could be helpful.

Vagrant networking forwarded_port does not work

I tried to setup sandbox for django development
I have forwarded the port in provision like this
config.vm.network:forwarded_port, host: 4567, guest: 8000
The server on guest started with
System check identified no issues (0 silenced).
March 19, 2015 - 20:50:37
Django version 1.7.7, using settings 'my_site.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
then I open the web browser on host machine and type in
http://127.0.0.1:4567/
Failed to connect to server.
Start the dev server with
python manage.py runserver 0.0.0.0:8000
so that it listens to every interface of port 8000.
You don't need to forward the port on Vagrant for accessing Django server from the host machine. What I usually do is start the server on the guest using
python manage.py runserver 0.0.0.0:8000
and then access it from the host using
"IP_address_of_guest_machine":8000

Error on host m/c - can't establish a connection to the server at 127.0.0.1:8888

Hi I'm learning django form kenneth love's GSWD video tutorials.
I'm using windows 7(32bit) and have vagrant and virtual box installed in it. The OS in virtual machine is Ubuntu 12.04 LTS
As asked in the tutorial I did the following
**vagrant#precise32:/vagrant/projects$ source ~/blog.venv/bin/activate
Installed Django
then created project with django-admin.py startproject microblog
(blog.venv)vagrant#precise32:/vagrant/projects$ cd microblog
(blog.venv)vagrant#precise32:/vagrant/projects/microblog$ python
manage.py runserver 0.0.
0.0:8000
Validating models... 0 errors found Django version 1.4.4, using
settings 'microblog.settings' Development server is running at
(http removed)//0.0.0.0:8000/ Quit the server with CONTROL-C.**
After this when I go back to windows 7 browser and run 127.0.0.1:8888 as said in tutorial I get "can't establish a connection to the server at 127.0.0.1:8888" error.
What should I do to get the default "It Worked"-django page ???
Did you change the Vagrantfile to do port forwardings?
For example, in your case, host port 8888 <=> guest port 8000
Vagrant.configure("2") do |config|
config.vm.network :forwarded_port, guest: 8000, host: 8080
end
Refer to the docs: http://docs.vagrantup.com/v2/networking/forwarded_ports.html

Local Django website won't load in browser

I'm guessing there's a very simple solution to this, but I searched every forum and setup guide and can't figure it out:
I built a Django/CentOS-6.3 environment on my local server (using VirtualBox and Vagrant). When I startup my server in the vagrant terminal with 'python manage.py runserver [::]:8000' it starts up with no errors.
Validating models...
0 errors found
May 31, 2013 - 13:56:15
Django version 1.5.1, using settings 'mysitename.settings'
Development server is running at http://[::]:8000/
Quit the server with CONTROL-C.
However, when I try to navigate to 'http://127.0.0.1:8001' in my browser (I set up port forwarding from port 8000 to port 8001 in my Vagrantfile), the browser just hangs for 5 minutes until it times out, then it returns the message:
> The connection was reset
> The connection to the server was reset while the page was loading.
> ...
This is the exact same message I get from the browser even after I shut down my local server. My computer obviously recognizes this as a forwarded port, because any other port I try (such as 8000) instantly returns an error saying that it can't establish a connection to the server at 127.0.0.1:8000.
With regard to the server files, I have done many similar setups with Django/Ubuntu in the past and have never had any issues, but there must be something different about Django/CentOS that is causing this to happen (or maybe I made a mistake someone in one of my server files). I have followed guides for setting up Django & PostgreSQL on CentOS, too, but to no avail. I'll comment some of the files I have created/edited below.
If anyone has a solution, or even has advice on where to start looking for errors, I would very much appreciate it.
If your network is configured correctly and your django application with
python manage.py runserver 0.0.0.0:8000
and you still can't access your django app from the VM host there is almost certainly a firewall issue. The solution above is good if you are running iptables.
I deployed CentOS 7 on a virtualbox VM from a Windows 7 host. I didn't know that this distribution uses firewalld, not iptables to control access.
if
ps -ae | grep firewall
returns something like
602 ? 00:00:00 firewalld
your system is running firewalld, not iptables. They do not run together.
To correct you VM so you can access your django site from the host use the commands:
firewall-cmd --zone=public --add-port=8000/tcp --permanent
firewall-cmd --reload
Many thanks to pablo v for pointing this out in the post "Access django server on virtual Machine".
the host's "127.0.0.1" is not the same as the guest's "127.0.0.1". Per default the command
python manage.py runserver
listens only to the guest's localhost. You should be able to test it from within the vm (use "vagrant ssh" to login) and run
curl -I http://127.0.0.1:8000/
The host as a different IP. To access the development server from the host you have to start it without ip restriction:
python manage.py runserver 0.0.0.0:8000
Yes:
python manage.py runserver [::]:8000
should be the same. But that's IPv6 syntax AFAIK. Are you sure that the "manage.py runserver" command supports IPv6 by default? I've never used ipv6 addresses w/ django, but looking at the source (https://github.com/django/django/blob/master/django/core/management/commands/runserver.py) there seams to be a flag that the default to False ("--ipv6"). Perhaps that's the "real" problem?
Regards,
For a similar problem,
This command worked like a charm for me
python manage.py runserver [::]:8001
Check your iptables, and stop it. Ubuntu commonly does not open the iptables when it starts.