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.
User --> Apache --> Gunicorn --> Django App
sudo apt update sudo apt install apache2 -y
sudo a2enmod proxy sudo a2enmod proxy_http sudo a2enmod headers sudo systemctl restart apache2
gunicorn --bind 127.0.0.1:8000 project.wsgi
<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>
sudo a2ensite mysite.conf sudo systemctl reload apache2
sudo apachectl configtest
sudo systemctl status gunicorn
Gunicorn service down ho sakti hai.
Logs aur application directory permissions verify karein.
sudo systemctl restart apache2 sudo systemctl status apache2 sudo tail -f /var/log/apache2/error.log
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: