-
Notifications
You must be signed in to change notification settings - Fork 1
Deploy
My project dir is called geodjango. If you cloned this, yours is probably called OSMHistoryServer. So if you see me doing something in geodjango/geodjango, on your system, it's probably OSMHistoryServer/geodjango. Just to be clear.
To begin with, you should be able to run your server so that it is accessible from the machine that is running it like this:
# cd (whatever you named your project dir)
python manage.py runserver
And then access it over any web browser on the same machine
... etc.
In order to deploy the server to the big bad world, you must do the following.
# cd (whatever you named your project dir)
cd OSMHistoryServer
# source (whatever you named your virtual env)/bin/activate
source venv/bin/activate
pip install gunicorn
source venv/bin/activate
sudo ufw allow 8000
See more here.
Now, if you are running your server from inside a virtual machine, you need to change its network settings to bridged. See more here. You will probably also have to configure a port in the host firewall settings: Windows 10, mac OS.
You should now be able to run the server so that it is locally accessible to any other machines on the same LAN like this:
# at this point you are probably in the root of your virtualenv, so switch to the user you started with, e.g.:
su kll
# then go back into the virtual env
source venv/bin/activate # (or whatever-you-named-yourse/bin/activate)
hostname -I # returns your local ip, e.g. 192.168.1.25
gunicorn geodjango.wsgi -b 0.0.0.0:8000
# OR,
gunicorn geodjango.wsgi:application -b 0.0.0.0:8000
# OR,
python manage.py runserver 0.0.0.0:8000 # but this is less interesting because we plan to use gunicorn
Then on another machine on the same network, open a web browser and navigate to the ip around in hostname -I
(in this case we use the example of 192.168.1.25).
http://192.168.1.25:8080/usernames # https will not work
This also lets you access your Django views from Javascript or other languages. For example, to get an httpresponse() containing a Javascript array of usernames (see the views.py):
// try to connect to server
var usernames = [];
$.get( "http://192.168.1.25:8000/usernames/")
.done(function( data ) {
usernames = data;
});
We need a domain name so we can serve the internet. More on that is documented here. Let's assume we have the domain name (www.) yourdomain.tld. To get and set up a domain name, go here.
To find hostname:
hostname
To find domain name:
dnsdomainname
More here.
Next we need to install PGWEB. See installation instructions here.
wget https://github.com/sosedoff/pgweb/releases/download/v0.9.6/pgweb_linux_amd64.zip # or whatever latest version is
Unzip and put the executable in your project dir, and rename it to "pgweb". Then, in your project dir:
$ ./pgweb --host 0.0.0.0 --port 5432 --user kll --db nepaldata ---pass=yourpassword --bind 0.0.0.0 --listen 8001
# (with your username instead of kll, & your database instead of nepaldata, & your password, etc)
Then you can see all sorts of cool stuff on any machine on the LAN at:
Except put the local ip of your server instead of 192.168.1.25, as we discussed previously.
We are going to eventually use nginx.
sudo -s
nginx=stable # use nginx=development for latest development version
add-apt-repository ppa:nginx/$nginx
apt-get update
apt-get install nginx
source venv/bin/activate
Next we need to edit nginx.conf. Open the file (it's in the main project directory) and edit it to use your local ip and project paths (for location /static/
and location /
, where in the examples kll is the user and geodjango is the project name).
More information on this file can be found here.
Next,
# cd (whatever you named your project dir)
sudo mv nginx.conf /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/geodjango /etc/nginx/sites-enabled
sudo nginx -t # test the conf file
sudo ufw allow 'Nginx Full'
sudo systemctl restart nginx
Not sure what happens next.