How start server Django in the VM (Vagrant) - python

i want install Django in my VM created with PuPHPpet (Vagrant), then when i start the server with
python manage.py runserver
My project is normally available in 127.0.0.1:8000
But i have unreachable web page, then i try
python manage.py runserver ipvm:8000 and others ports
I have always unreachable web page
So, i have found in this forum
0.0.0.0:8000
And i have again unreachable web page, Why ? How can start my server in my VM ?

You have to forward the port from Vagrant to your local machine. You can add a line like this to your Vagrantfile:
config.vm.network :forwarded_port, host: 8001, guest: 8000
And then run this in the Vagrant VM:
python manage.py runserver 0.0.0.0:8000
And on your host machine, go to http://localhost:8001 to view the webpage.

Run python manage.py runserver 0:8000. It worked for me

You have to forward the port from Vagrant to your local machine.
config.vm.network :forwarded_port, host: 8001, guest: 8000
Yo need to add IP to ALLOWED_HOST in your setting.py file
0.0.0.0 to the ALLOWED_HOSTS in your settings.py
Run Project
python manage.py runserver 0.0.0.0:8000

Related

Trying to connect from a docker container to docker host running Django in development mode gets connection refused

I'm running a django development server in my Debian GNU/Linux host machine with python manage.py runserver.
After running a Debian docker container with
$ docker run -it --add-host=host.docker.internal:host-gateway debian bash
I expected I could make a curl in http://localhost:8000 with
curl http://host.docker.internal:8000
but I get
Failed to connect to host.docker.internal port 8000: Connection refused
Is it something related to running Django with python manage.py runserver?

Why I failed to connect to the django server?

I'm following a tutorial, using this command in a Docker container to start the Django server:
python3 manage.py runserver 0.0.0.0:8000
But I can not connect to it by IP.
I am sure that I have already open the 8000 port and this port is on listening. By the way, I use the ubuntu and set the server in the aliyun.
At First Django works on port 8000 not on 8080. So you should use python manage.py runserver 0.0.0.0:8000. You can eazly kill port in linux server by type: fuser 8080/tcp

How to allow others to connect to my Django website?

Now that I have created a website, I wish the users can connect to my website within a local network. However my website now can only be accessible from the localhost (my pc), the others are not able to connect to my website when typing my ip address for example xxx.xxx.xxx.xxx:8000 on their browser. I launch the service on my localhost using # python manage.py runserver. May I know if there is a way/command to allow the others to connect to my website?
Note: I have tried # python manage.py runserver 0.0.0.0:8000 as well, which allow all incoming, but it didn't work.
In settings.py write
ALLOWED_HOSTS = ['*'] and run python manage.py runserver 0.0.0.0:8000
Note: you can use any port instead of 8000
There are steps to resolve this problem are:
1. Use http://<your ip address> than https
2. Then in settings.py write
ALLOWED_HOSTS = ['*']
3. Finally ran the server with:
python manage.py runserver 0.0.0.0:8000

Docker refusing connection

I'm trying to run my first ever docker. On console everything seems to be fine, but the chrome says connection is refused. It tried to turn off windows firewall - no effect. Running on win10home.
$ docker run -p 8000:8000 -v `pwd`:/data --rm -it mydjango mynewproject/manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
December 28, 2016 - 11:48:20
Django version 1.10.4, using settings 'mynewproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Dockerfile:
From python:3
RUN pip install django
EXPOSE 8000
RUN mkdir /data
WORKDIR /data
I had this issue when running the server with the command
python manage.py runserver 8080
Running the command
python manage.py runserver 0.0.0.0:8080
Fixed it for me. Note the 0.0.0.0
Could you please try adding "docker ip" in the ALLOWED HOSTS in the mynewproject/settings.py
The url you are checking with is "docker-ip":8000 right?
To get docker docker container IP,
You can use docker inspect
Some thing like this:
CID=$(docker run -d -p 4321 base nc -lk 4321);
docker inspect $CID
Run the following command in CMD for Windows OS by going to the directory of your project then execute these commands:
python manage.py migrate #run this command to sync your Database with Django project
python manage.py runserver # run the server on http://127.0.0.1:8000/
For the more tutorial watch this channel simple Tutorials of Django is available
https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBlmzzFcLgDhKTTfNLfX1IK
I have also learned from here. If you find your answer a Thumbs up will be appreciated . Happy Coding

How to deploy nginx without root access?

Recently I rented a web server at a certain company. I have ssh access but no root privileges. They don't excpect users to actually use ssh the main way of deploying is ftp or some cms/clickibunti. The OS if FreeBSD and they have a Python installation(2.7.8).
I downloaded virtualenv, Django and gunicorn (installed in the home directory and the virtualenv). I deployed the bootstrap Django app with the development server on 0.0.0.0:8000 which works fine. They deleted pkg and ports (packagemanagers) so I build nginx from source (installed into the /home/myuser/urs/local/bin/).
Now I'm stuck.
How do I deploy nginx without root access? Is this possible? I only have (write)access to /home/myuser/.
Disclaimer: They have a cash return policy so I'm not too concerned. But I have some free time and this seems like a nice problem to master.
Install it into your home directory, and change the config so it uses a port higher than 1024:
$ ./configure --prefix=/home/steve/nginx
$ make && make install
$ cd ~/nginx
$ vi conf/nginx.conf
Change:
server {
listen 80;
to:
server {
listen 8080;
Then start it:
$ ./sbin/nginx
$ netstat -na | grep 8080
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN

Categories