TechWithAdi

Apache Reverse Proxy for Django (Complete Hindi Guide)

Django applications ko production me deploy karte waqt Apache Reverse Proxy ka use bahut common hai. Apache client requests ko receive karta hai aur Gunicorn/Django application tak forward karta hai.

Architecture

User --> Apache --> Gunicorn --> Django App

Step 1: Apache Install Karein

sudo apt update
sudo apt install apache2 -y

Step 2: Required Modules Enable Karein

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod headers
sudo systemctl restart apache2

Step 3: Gunicorn Start Karein

gunicorn --bind 127.0.0.1:8000 project.wsgi

Step 4: Apache VirtualHost Configure Karein

<VirtualHost *:80>
    ServerName example.com

    ProxyPass / http://127.0.0.1:8000/
    ProxyPassReverse / http://127.0.0.1:8000/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Step 5: Site Enable Karein

sudo a2ensite mysite.conf
sudo systemctl reload apache2

Configuration Test

sudo apachectl configtest
Tip: Production environment me Gunicorn ko Supervisor ya Systemd service ke saath run karein.

Common Errors

502 Bad Gateway

sudo systemctl status gunicorn

503 Service Unavailable

Gunicorn service down ho sakti hai.

Permission Denied

Logs aur application directory permissions verify karein.

Useful Commands

sudo systemctl restart apache2
sudo systemctl status apache2
sudo tail -f /var/log/apache2/error.log

FAQ

Apache ya Nginx?
Dono achhe hain, lekin Apache beginners ke liye easy hota hai.

Kya SSL add kar sakte hain?
Haan, Let's Encrypt aur Certbot ka use karke SSL enable kar sakte hain.

निष्कर्ष

Apache Reverse Proxy Django deployment ka important part hai. Sahi configuration ke saath aap secure aur scalable production environment bana sakte hain.


Related Articles: