How to view the local django web server running on the digital ocean droplet from my computer

December 5, 2016 73 views
Django DigitalOcean Ubuntu 16.04

I ssh into the digital ocean server, run the django app, and i want to view the web server to see if the app is working correctly, there are no error logs so i assume so.

1 Answer

You can have the django service listen on your public IP by starting it with a command like:

./ runserver [your ip]:8080

For production, putting something like nginx in front of your app is a better idea. You can do this by first installing nginx

sudo apt-get update;
sudo apt-get install nginx;

and then updating your /etc/nginx/sites-enabled/default file to read:

server {

        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index index.html index.htm;

        server_name _;

        location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;


Then, restarting nginx:

service nginx restart

Now you'll be able to browse to your droplet's IP (without specifying a port) and view your django application.

Have another answer? Share your knowledge.