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 collectstatic which is collecting all the assets to /static in the project root. Then I run gunicorn wsgi -D in the same directory as

Anyway, this is how the Apache configs are setup:



### 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. to
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context



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

What am I doing wrong here?

0 Answers