Django blog deployment and ports flow

0

Hi I developed a simple personal blog with Django and Nginx as a reverse proxy server and want to deploy It with AWS in the most costo effettive way. Which Is It? And I don't understand the ports flow between localhost, Django (uwsgi+gunicorn), Nginx, docker (compose), postgrSQL and AWS RDS...can someone give me help or advice on this?

asked a year ago345 views
1 Answer
1
Accepted Answer

Sure, let's break this down.

  1. AWS Deployment Strategy:

    The most cost-effective deployment for a simple Django app on AWS would be to use AWS Elastic Beanstalk. It automatically handles the deployment, from capacity provisioning, load balancing, and automatic scaling to application health monitoring.

    In AWS RDS, you can create a PostgreSQL database instance that your Django app can use. The RDS Free Tier allows you to run a Micro instance for up to 750 hours per month, which should be sufficient for a personal blog. Make sure to manage your resources wisely to stay within the free tier.

    Also, you can use AWS Certificate Manager to get a free SSL certificate and AWS Route53 to manage DNS if you have a domain name.

  2. Understanding Ports Flow:

    Here is a simplified explanation of the port flow:

    • Localhost: This is your local development machine. Here, you typically run Django's development server, which by default runs on port 8000.

    • Django (uWSGI+Gunicorn): When you're ready to deploy, you typically switch to a production-grade WSGI server like uWSGI or Gunicorn. These servers can run your Django app on any port you specify, but common choices are 8000, 8080, or 5000.

    • Nginx: Nginx acts as a reverse proxy. This means it accepts web traffic on port 80 (HTTP) or 443 (HTTPS) and forwards it to your WSGI server (Gunicorn/uWSGI). Nginx can handle static files and SSL termination more efficiently than Django, so it's good practice to use Nginx for these tasks.

    • Docker/Docker-compose: Docker is a way to package your application and its dependencies into a "container". The ports your application uses inside the Docker container can be mapped to ports on the Docker host (i.e., the physical server or virtual machine running Docker). This is usually specified in your docker-compose.yml file. For example, you might have your Nginx server inside Docker listening on port 80, and map this to port 80 on the Docker host, so all HTTP traffic to the Docker host goes to Nginx.

    • PostgreSQL/AWS RDS: Your Django application needs to connect to a PostgreSQL database. This typically happens over port 5432. If you're using AWS RDS, you'll be given a hostname (endpoint) and port to use in your Django settings.

So, in a typical setup, a user sends a HTTP/HTTPS request to your server's IP address (port 80/443). Nginx, running on Docker, accepts this traffic and forwards it to Gunicorn/uWSGI on another port (let's say 8000). Django processes the request, perhaps making some queries to your PostgreSQL database over port 5432, then sends a HTTP response back up the chain to the user.

Please note, while these services do use these ports by default, the actual ports used in your setup may be different based on your specific configurations.

Also remember to open these ports on your AWS security group to allow traffic to flow in and out of your server.

I hope this provides you with a good starting point. If you have any other specific questions about deploying your Django blog, please feel free to ask.

profile picture
EXPERT
answered a year ago
profile picture
EXPERT
reviewed a month ago
  • Thank you very much, this is the answer I was waiting!!!

    I'll write back if I have further doubts.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions