Question

How to make my django website live to the world after setting up my application with Digital Ocean Droplet?

I am trying to deploy my Django website using Digital Ocean Droplet. I followed this documentation to setup my application with Digital Ocean droplet using Nginx and Gunicorn. After this the website is properly running on my system if I visit to my domain name in the bowser. But now I am confused that how should make my website available over the internet to the world. Below is the nginx settings I have used as per the documentation I followed:

server {
    server_name 46.101.156.167;

    access_log off;

    location /static/ {
        alias /opt/myapp/static/;
    }

    location / {
        proxy_pass http://127.0.0.1:8001;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
    }
}

Above given server_name is the IP of my droplet which is redirected to the domain name of my website.

It would be great if any one can guide me with step by step documentation to make my website live. I believe the Digital Ocean should take my website from the repo in git or bitbucket so that in case of further changes I just need to push my code to the repo and than my droplet can use the updated code. But I am ber much confused about how to do it.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

@billiondollarco

Line #2, server_name , should ideally be your domain name, if the plan is to use one :-). Simply set it as:

server_name yourdomain.ext www.yourdomain.ext;

… where yourdomain.ext is yourdomain.com, yourdomain.net or the extension of your choosing. The above sets NGINX up to handle requests with and without the www.. You could also simply setup the same with:

server_name yourdomain.ext *.yourdomain.ext;

The * is referred to as a WildCard, meaning that any sub.yourdomain.ext will be routed to yourdomain.ext unless it exists, in which case the content for that sub-domain would be shown.

Beyond setting up NGINX, you’ll need to ensure that NGINX is started from the CLI (Command Line Interface) by issuing the following command:

service nginx start

Once that’s taken care of, you need to ensure that your domains DNS is properly setup. You’ll need your Droplet’s Public IP Address for this and you’ll need to create two A entries and CNAME entry. If you’ve set your domains DNS to DigitalOcean, you can make these changes through their control panel. If not, you’ll need to login to your domain registrars control panel and make the changes there.

The A entries will look like this:

A               @               DROPLET_PUBLIC_IP
A               *               DROPLET_PUBLIC_IP

… where DROPLET_PUBLIC_IP = your Droplet’s Public IP Address.

The second A entry is the WildCard entry that coincides with your NGINX server block. If you don’t setup the server block using the WildCard, you can simply omit this one and only add the first.

The CNAME entry will look like this:

CNAME           www             yourdomain.ext

… simply replace yourdomain.ext with your actual domain name.

With those updates in place, DNS changes can take as little as a few minutes up to 24-48 hours to fully resolve, so don’t be alarmed if you aren’t able to access your domain immediately.