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

Posted December 5, 2016 7.9k views
DigitalOceanDjangoUbuntu 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.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
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.