This repository contains a Django web application which is deployed using NGINX as the web server, uWSGI as the WSGI server, and is managed by systemd on an AWS EC2 instance. This setup ensures a robust production environment for handling web requests.
- NGINX: Serves as the front-facing web server to handle client requests and static assets.
- uWSGI: Acts as the WSGI server which serves the Django application by translating web requests from NGINX to Python calls.
- Systemd: Used for initializing and managing the uWSGI process.
- Django: The Python web framework where the application logic resides.
- Python 3.6 or higher
- Django 2.2 or higher
- uWSGI
- NGINX
- Virtualenv (recommended)
- AWS EC2 instance
- SSH client
- Private key file (e.g.,
django-master-key.pem
)
-
Remove inherited permissions and assign unique permissions to your user:
icacls.exe "django-master-key.pem" /reset icacls.exe "django-master-key.pem" /grant:r "$($env:USERNAME):(R)" icacls.exe "django-master-key.pem" /inheritance:r
-
Connect to your instance using the provided public DNS (replace
'IP-segmented-by-dashes'
with your actual IP address):ssh -i "django-master-key.pem" ubuntu@ec2-'IP-segmented-by-dashes'.compute-1.amazonaws.com
- Clone the repository:
git clone https://github.com/Erick-Bryan-Cubas/DjangoMaster.git
- Navigate to the project directory:
cd DjangoMaster/carros
- Create a virtual environment and activate it:
virtualenv venv source venv/bin/activate
- Install the required dependencies:
pip install -r requirements.txt
- Install NGINX and create
carros.conf
:sudo apt install nginx cd /etc/nginx/sites-available sudo nano carros.conf
- Add the following server block to
carros.conf
, replacing<YOUR_IP>
with your server's IP:upstream django { server unix:///var/www/DjangoMaster/carros/carros.sock; # for a file socket } server { listen 80; server_name <YOUR_IP>; client_max_body_size 75M; location /media { alias /var/www/DjangoMaster/carros/media; # your Django project's media files } location /static { alias /var/www/DjangoMaster/carros/static; # your Django project's static files } location / { uwsgi_pass django; include /var/www/DjangoMaster/carros/uwsgi_params; # the uwsgi_params from Django } }
- Create
carros_uwsgi.ini
inside your project directory with the following content:[uwsgi] chdir = /var/www/DjangoMaster/carros module = app.wsgi home = /var/www/DjangoMaster/carros/venv master = true processes = 10 socket = /var/www/DjangoMaster/carros/carros.sock chmod-socket = 666 vacuum = true
- Create a systemd service file for your project:
sudo nano /etc/systemd/system/carros.service
- Add the following configuration, adjusting paths as needed:
[Unit] Description=uWSGI instance to serve carros After=network.target [Service] User=root Group=root WorkingDirectory=/var/www/DjangoMaster/carros ExecStart=/var/www/DjangoMaster/carros/venv/bin/uwsgi --ini /var/www/DjangoMaster/carros/carros_uwsgi.ini [Install] WantedBy=multi-user.target
To start the application, use the following systemd commands:
sudo systemctl daemon-reload
sudo systemctl start carros
sudo systemctl enable carros
sudo systemctl status carros
Please see the LICENSE.md file for details.
We welcome contributions! Please read the CONTRIBUTING.md file to see how you can help improve this project.