As the title says, I'm having difficulty getting Apache setup correctly to serve Django static files in production with a Gunicorn proxy for the backend.

I'm finding that when I switch DEBUG = False that the app quits working with: < unexpected token. Reading about it, it has to do with the use of STATIC_ROOT being incorrect.

I have my STATIC_ROOT = os.path.join(BASE_DIR, 'static'), and I'm running python manage.py collectstatic which is collecting all the assets to /static in the project root. Then I run gunicorn wsgi -D in the same directory as wsgi.py.

Anyway, this is how the Apache configs are setup:

HTTP:

ServerName www.website.com
ServerAlias website.com

### Redirect http to https

RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context

HTTPS:

ServerName www.website.com
ServerAlias website.com

Alias /static /home/website/src/static

ProxyPreserveHost On
ProxyPass /static http://localhost:8000/static/
ProxyPass / http://localhost:8000/ retry=5
ProxyPassReverse / http://localhost:8000/
<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

What am I doing wrong here?

0 Answers