Django Nginx Staticfiles not showing in AWS

1.2k views Asked by At

I have a Django project that I added to AWS. in the development server the site works perfectly fine however I am not able to get my static files to my aws site

Below is my project Tree and static files are in the project

enter image description here

Below is my settings.py

enter image description here

Below is my nginx server

enter image description here

Below is my supervisor.conf

[program:Khal]
command = /home/samir/KhalEventsVenv/bin/uwsgi --http :9000 --wsgi-file /home/samir/khal-events/src/Khal/Khal/wsgi.py
directory = /home/samir/khal-events/src/Khal/
user = root
autostart = true
autorestart = true
stdout_logfile = /var/log/Khal.log
stderr_logfile = /var/log/Khal_err.log

Changed the nginx to

server {
    listen 80 default_server;

    location /static/admin {
        alias /home/samir/KhalEventsVenv/lib/python3.6/site-packages/django/contrib/admin/static/admin;

    }

    location /static/ {
        alias /home/samir/khal-events/src/Khal/staticfiles;

    }

Still the page is not getting the static in see image below

enter image description here

I have checked the paths. they are good. However for some reason when I run the site from AWS it is not getting the staticfiles also when I got to the admin page. The static files for admin are not in there too. HOw can I get my static files in AWS

enter image description here

As suggested by @CoolestNerdIII

enter image description here

2

There are 2 answers

7
CoolestNerdIII On

It appears as though in your django settings file, you define the static file directory to be /home/samir/khal-events/src/Khal/staticfiles (based on your screenshot of your collectstatic command and your settings.py file).

In your nginx config file, however, you are looking for your static directory inside of home/samir/khal-events/src/Khal/static. You need to change this to the correct path, and you should be good to go. (meaning use /home/samir/khal-events/src/Khal/staticfiles)


Update #1:

You should remove the /static/admin from your nginx. Also, you can try duplicating your /static group with /static/. Make sure you restart your nginx service after you make the changes.

Finally, if neither if these appear to display the page correctly, check the console log in your web browser, as well as the nginx logs, as they typically point to where information is being loaded improperly.


Update #2:

location /static/ {
    alias /home/samir/khal-events/src/Khal/staticfiles;
}

location /static {
    alias /home/samir/khal-events/src/Khal/staticfiles;
}
0
sam hassan On

what works for me was just to change the root to alias I hope this helps