Reputation: 55
First of all: please don't blame me for making newbie mistakes or anything like that. I am still learning and need just a bit of help. So I created a droplet on digitalocean with ubuntu 16.04 and logged in and ran:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-setuptools python-pip apache2 libapache2-mod-wsgi
and installed django:
sudo pip install Django==11.1.4
and created the project (without virtualenv) in a directory:
django-admin.py startproject mysite
However, if I do "runserver"
python manage.py runserver
and type xxx.xxx.xxx.xx:8000 in firefox there is nothing even though I see in the terminal that the runserver did work. If I type xxx.xxx.xxx.xx then I see the default page of apache. My goal is to run django over apache but I cannot even get started because the runserver which is just for testing didn't even work. How can I make this work, where did I make a mistake?
Edit: the output of the runserver is:
Performing system checks...
System check identified no issues (0 silenced).
September 02, 2017 - 22:21:12
Django version 1.11.4, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Upvotes: 0
Views: 3145
Reputation: 91545
The manage.py runserver
is NOT meant for serving your pages through Apache, it is ONLY meant as a lightweight local development server for running your code as you write it.
Instead, you should be following a guide to run DJango on Apache using mod_wsgi.
The only bit of advice I'd be willing to give that might help in this situation is that if you're trying to host runserver
inside a virtual machine or Docker container, you need to explicitly set the host binding to
manage.py runserver 0.0.0.0:8000
Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g. 192.168.2.1) or 0.0.0.0 or :: (with IPv6 enabled).
Again, runserver
is for local development ONLY. Do NOT use it to try and host a site through Apache since that's what hosting drivers like mod_wsgi
are for.
Upvotes: 3
Reputation: 3033
The runserver and apache are 2 different things.
The local runserver is used by a developer to code and run the web application locally. Usually the settings loaded locally are different, for example the production website use settings and locally you use settings_local.py that ovverrides the production settings (very simplified example).
If you run your runserver
and you load http://127.0.0.1:8000/
you should be able to see something and on your terminal you should see the runserver response to your requests from the browser.
If your goal is deploy your web application than you need something like apache
, but not locally. IMHO, I suggest you to avoid Apache and use Nginx + Gunicorn + supervisord to manage your webapp on your production server. Much much easier to configure.
Upvotes: 0