[Django]-Running django application via SSH on Windows

8👍

✅

The author enumerates the different requirements for the app in the Prerequisites section of the article you mentioned:

To follow this tutorial you will need:

  • a running Linux virtual machine with Docker and Docker Compose
    installed where your app will be deployed (AWS EC2, Google Compute
    Engine, Digital Ocean, Linode are all viable options)
  • a domain name

Need a cheap domain to practice with? Several domain registrars
have specials on ‘.xyz’ domains. Alternatively, you can create a
free domain at Freenom.

I changed the order of the elements in the list, to reflect the actual order of the requirements.

The first thing you need is some machine in which you can run your application.

This machine could be hosted anywhere you consider appropriate, on premises, in your own data center or, as suggested as well in the article, nowadays you can provision a machine very easily in the cloud, for example, in any of the different public cloud providers, AWS, GCP, or Azure, among others.

The requirements for this machine are the following:

  • This machine should be accessible through the internet, among other things, for creating your DNS entry and to allow Let’s Encrypt and the associated bot to handle your SSL certificate.
  • You can use a Windows or Linux machine, although for simplicity, tight integration with Docker, and licensing purposes, especially for testing purposes, a free Linux version, Ubuntu or Debian, for example, should be the more appropriate.
  • In this machine docker and docker-compose should have been installed.

Assuming you are using Ubuntu, for example, you can follow for example this excellent guide to install the docker software.

You need to install docker-compose as well.

But, how to connect to a linux instance from a Windows machine to perform these operations and later run your application?

In Linux typically you will use SSH for that purpose.

In Linux or Unix based systems SSH support is provided out of the box; in Windows you most likely will need to use Putty.

The Web is plenty of tutorials about Putty and how to use it: consider for instance this one.

In Linux you can connect to your machine using a terminal and typing the following:

ssh user@your-ip-or-domain

The Putty GUI will offer your all the stuff required to perform a similar connection: just define the public IP address of your machine, a username and a password (alternatively you can use SSH keys to authenticate against the machine).

This username and password are typically provided by the provider of your machine in the machine setup process.

To make this possible, probably you will need to configure some kind of firewall software in your hosting provider to allow connections to the machine for SSH, on port 22, and for HTTP/S, on ports 80 and 443, for your Django web app. Please, be careful here and, al least at first glance, restrict the IP address that can connect to the instance to your own IP address, this is especially important for the SSH port.

Then, I would perform the DNS setup.

DNS basically allows you to provide a recognizable alias for your machine IP address.

In addition to facilitate the access to your site by name you need to assign a DNS record to your machine in order to use Let’s Encrypt because it requires that information as a verification step when issuing your site SSL certificate.

This DNS can be assigned in different ways: you only need the IP address of your machine and some DNS provider.

There are a lot of them, for example, AWS Route 53, GCP DNS or Azure DNS, GoDaddy, etc (see this, for instance).

I have never use that service, but probably you could use Freenom as suggested in the article as well for that purpose.

Once configured, the Certbot installed as a companion to your nginx server will make it job and will issue the necessary certificates.

After that, as explained in the article, upload your application software to your machine.

In Linux is normal to use SCP for that purpose.

Again, if you are running Linux or Unix as a client, the protocol is provided out of the box:

scp -r $(pwd)/{app,nginx,.env.staging,.env.staging.db,.env.staging.proxy-companion,docker-compose.staging.yml} user@your-ip-or-domain:/path/to/django-on-docker

When running Windows you can use WinSCP to perform this step.

To finish, connect again to the machine with Putty and SSH
and run your containers with docker compose as explained in the article:

cd /path/to/django-on-docker
docker-compose -f docker-compose.staging.yml up -d --build

Leave a comment