After deploying my Django app on a VPS with Nginx and configuring Nginx to handle the static files, I'm encountering a strange issue. While all the images are rendering properly, the CSS doesn't seem to be working at all...
Here is my Django setting:
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
And this is how I've configured Nginx:
location /static/{
alias /home/xxx/App/django_app/static_root/;
}
In the HTML template, I have included the following lines:
<link rel="stylesheet" href="{% static 'app1/css/style.css' %}" type="text/css" media="all">
<img src="{% static 'app1/images/page1_img1.jpg' %}" alt="">
I have already executed python manage.py collectstatic
, and set Debug = False
(everything works fine when Debug is true).
All the images are located in
/home/xxx/App/django_app/static_root/app1/images
, while the css files are under /home/xxx/App/django_app/static_root/app1/css
.
I can confirm that I am able to access the css file using the URL
https://myserver/static/app1/css/style.css
, and there are no error messages in the Nginx log.
I have tried different browsers, cleared cache, restarted the server and Nginx multiple times but still no luck. I am really running out of ideas... Any suggestions would be greatly appreciated.