Showing posts with label nginx. Show all posts
Showing posts with label nginx. Show all posts

Friday

Simple Nginx Conf for Microservices Application

########################################################################

# Main Nginx configuration file for Dockerized Microservices

#

# More information about the configuration options is available on 

# * the English wiki - http://wiki.nginx.org/Main

# * the Russian documentation - http://sysoev.ru/nginx/

#

#######################################################################


#----------------------------------------------------------------------

# Main Module - directives that cover basic functionality

#

# http://wiki.nginx.org/NginxHttpMainModule

#

#----------------------------------------------------------------------


user nginx;

worker_processes auto;


error_log /opt/nginx/logs/error.log;

#error_log /var/log/nginx/error.log notice;

#error_log /var/log/nginx/error.log info;


pid /var/run/nginx.pid;


#----------------------------------------------------------------------

# Events Module 

#

# http://wiki.nginx.org/NginxHttpEventsModule

#

#----------------------------------------------------------------------


events {

    worker_connections 2048;

}


#----------------------------------------------------------------------

# HTTP Core Module

#

# http://wiki.nginx.org/NginxHttpCoreModule 

#

#----------------------------------------------------------------------


http {

    include /opt/nginx/conf/mime.types;

    default_type application/octet-stream;


    log_format main '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';


    access_log /opt/nginx/logs/access.log main;


    sendfile on;

    autoindex off;

    

    map $scheme $fastcgi_https {

        default off;

        https on;

    }


    keepalive_timeout 60;


    gzip on;

    gzip_comp_level 2;

    gzip_proxied any;

    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    gzip_disable "msie6";

    gzip_vary on;

    gzip_min_length 1024;

    gzip_http_version 1.1;

    # gzip_static on;


    # Load config files from the /etc/nginx/conf.d directory

    # The default server is in conf.d/default.conf

    include /opt/nginx/conf/conf.d/*.conf;

    # include /etc/nginx/sites-enabled/*;

    # tcp_nopush on;

}


Introduction to Django, Celery, Nginx, Redis and Docker

 




Django: A High-Level Web Framework


Django is a high-level web framework for building robust web applications quickly and efficiently. Written in Python, it follows the Model-View-Controller (MVC) architectural pattern and emphasizes the principle of DRY (Don't Repeat Yourself). Django provides an ORM (Object-Relational Mapping) system for database interactions, an admin interface for easy content management, and a powerful templating engine.


When to Use Django:


- Building web applications with complex data models.

- Rapid development of scalable and maintainable web projects.

- Emphasizing clean and pragmatic design.


Docker: Containerization for Seamless Deployment


Docker is a platform that enables developers to automate the deployment of applications inside lightweight, portable containers. Containers encapsulate the application and its dependencies, ensuring consistency across different environments. Docker simplifies the deployment process, making it easier to move applications between development, testing, and production environments.


When to Use Docker:


- Achieving consistency in different development and production environments.

- Isolating applications and dependencies for portability.

- Streamlining the deployment process with containerization.


Celery: Distributed Task Queue for Asynchronous Processing


Celery is an asynchronous distributed task queue system that allows you to run tasks asynchronously in the background. It's particularly useful for handling time-consuming operations, such as sending emails, processing data, or running periodic tasks. Celery supports task scheduling, result storage, and can be integrated with various message brokers.


When to Use Celery:


- Handling background tasks to improve application responsiveness.

- Performing periodic or scheduled tasks.

- Scaling applications by offloading resource-intensive processes.


Redis: In-Memory Data Store for Performance


Redis is an open-source, in-memory data structure store that can be used as a cache, message broker, or real-time analytics database. It provides fast read and write operations, making it suitable for scenarios where low-latency access to data is crucial. Redis is often used as a message broker for Celery in Django applications.


When to Use Redis:


- Caching frequently accessed data for faster retrieval.

- Serving as a message broker for distributed systems.

- Handling real-time analytics and data processing.


Nginx: The Versatile Web Server and Reverse Proxy


Nginx is a versatile web server and reverse proxy server known for its efficiency and scalability. It excels in handling concurrent connections and balancing loads. In Django applications, Nginx often acts as a reverse proxy, forwarding requests to the Django server.


When to Incorporate Nginx:


Enhancing performance by serving static files and handling concurrent connections.

Acting as a reverse proxy to balance loads and forward requests to the Django server.


Sample Application: Django ToDo App


I have created a beginner-level ToDo application using Django, Docker, Celery, and Redis. You can find the source code on [GitHub](https://github.com/dhirajpatra/docker-django-celery-postgres). The application demonstrates the integration of these technologies to build a simple yet powerful task management system.


Future Updates:


Feel free to explore the provided GitHub repository, and I encourage you to contribute or extend the application. I will be creating new branches to introduce additional features and improvements. Stay tuned for updates!


GitHub Repository: https://github.com/dhirajpatra/docker-django-celery-postgres

I have other similar repositories a few years back as well.

ETL with Python

  Photo by Hyundai Motor Group ETL System and Tools: ETL (Extract, Transform, Load) systems are essential for data integration and analytics...