0

I am a beginner in aws and I am trying to deploy a django app on aws-ec2. I have set-up gunicorn application server and nginx web server and app loads but without static files. I have followed many answers on stackoverflow but I am unable to fix my problem.

I tried with both root and alias but they didn't work. The project structure is as follows:- /home/ubuntu/myskillhut/

django.conf(nginx configuration file)

server {
        ...

        location / {
                include proxy_params;
                proxy_pass http://unix:/home/ubuntu/myskillhut/app.sock;
        }

        location /static/ {
                autoindex on;
                alias /home/ubuntu/myskillhut/static/;
        }
}

settings.py

...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static/"), )
...
Vineet
  • 723
  • 4
  • 12
  • 31

1 Answers1

0

Configuration below works for my project

location ~* \.(jpe?g|gif|png)$ {
    root /home/ubuntu/myskillhut/static/;
    expires 1M;
}

location ~* \.(css|js)$ {
    root /home/ubuntu/myskillhut/static/;
    expires 1d;
}

Also, make sure nginx can access those files in that dir (../static/)

Randy Lam
  • 579
  • 5
  • 11
  • Just pick up a skill to see which location the request ends up in. more detail ref to https://stackoverflow.com/questions/12703702/nginx-test-which-location-used-to-process-request/40297052#40297052 – Randy Lam Aug 28 '20 at 06:26