0

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

Samir Tendulkar
  • 1,151
  • 3
  • 19
  • 47
  • Have you run the `python manage.py collectstatic` command on your server ? See [docs](https://docs.djangoproject.com/en/2.1/howto/static-files/#deployment) for more details. – Anto Nov 09 '18 at 12:21
  • @Anto I just added my `supervisor.conf` file in the question. To run server I do `supervisorctl restart all` – Samir Tendulkar Nov 09 '18 at 12:24
  • If you have an ssh access to your server just go there and run `python manage.py collectstatic` in the correct directory and then restart your wsgi server. – Anto Nov 09 '18 at 12:26
  • @Anto I did the collectstatic I have updated image of the terminal in question. But still the static file are not showing – Samir Tendulkar Nov 09 '18 at 12:31
  • Your static files (where you do collectstatic) is a different location than where nginx is pointing to – CoolestNerdIII Nov 09 '18 at 12:35

2 Answers2

0

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;
}
CoolestNerdIII
  • 770
  • 4
  • 10
  • changed the static in nginx see image above also ran collectstatic command but still the admin page is weird and even in the normal site there is no static imported – Samir Tendulkar Nov 09 '18 at 13:03
  • @SamirTendulkar I updated my answer with something to try. – CoolestNerdIII Nov 09 '18 at 13:20
  • I have changed my nginx as per your advise and updated it in th equestion above. Does that look right I am planning on restarting nginx with `sudo systemctl restart nginx` – Samir Tendulkar Nov 09 '18 at 13:35
  • tried your code also tried `location /static/ { alias /home/samir/khal-events/src/Khal/staticfiles; } location /static { alias /home/samir/khal-events/src/Khal/staticfiles/; }` still the same Also tried extra `/` in the second path – Samir Tendulkar Nov 09 '18 at 13:51
  • Did you look at your nginx logs and look for console errors in your browser? – CoolestNerdIII Nov 09 '18 at 13:57
  • http://ec2-54-157-27-88.compute-1.amazonaws.com/admin/login/?next=/admin/ that is the aws link. does not show any errors – Samir Tendulkar Nov 09 '18 at 14:02
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/183373/discussion-between-coolestnerdiii-and-samirtendulkar). – CoolestNerdIII Nov 09 '18 at 14:29
0

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

sam hassan
  • 197
  • 3
  • 14