How Can I Deploy Django with Apache and Gunicorn on CentOs7?

Viewed 226

I have been trying to deploy django on my CentOs 7 server (release 7.9.2009) for a bit now, and I have tried the nginx + gunicorn route as well as the Apache + mod_wsgi route. However, both of them hit roadblocks, namely that Apache was blocking nginx, and that my version of CentOs7 is not compatible with mod_wsgi. So, I tried mod_proxy_uswgi but there is not much in the way of tutorials or information on how to using that module with Apache. Then, I finally settled on attempting to use gunicorn to serve my files, and using an Apache config. Still, nothing of any use.

The structure of my django project is

.
├── manage.py
├── static
│   └── admin
├── testproject
│   ├── asgi.py
│   ├── __init__.py
│   ├── __pycache__
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── venv

Here is the relevant code

django.conf

<VirtualHost *:80>

ServerName mydomainname.com

ProxyPreserveHost On
ProxyPass /static/ !
ProxyPass / http://0.0.0.0:8000/
ProxyPassReverse / http://0.0.0.0:8000/
ProxyTimeout 300

Alias /static/ /home/user/django_test/static/

<Directory /home/user/django_test/testproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

<Directory "/home/user/django_test/static/">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>


</VirtualHost>

Relevant portion of settings.py

ALLOWED_HOSTS = ['*']
...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")

However, when I try to run gunicorn, it runs fine but I cannot see the django app on my domain or the assigned port of the domain. Can someone let me know what I am doing wrong? Thank you!

0 Answers
Related