Issue
I am running a development of a django project via gunicorn on my local machine. For reasons™, I want to set up nginx as a proxy for it. So far so, good:
location /intranet {
return 301 /intranet/;
}
location /intranet/ {
rewrite ^/intranet(.*) /$1 break;
proxy_redirect default;
proxy_pass http://127.0.0.1:8000;
}
This does the trick nicely. However, none of the static files are severed: all I get is 404 for those.
How can I modify the above nginx configuration so that the static content is severed?
Note that using https::127.0.0.1:8000
, the static files are served just fine.
Solution
In the project you shoud point the URL:
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
If you have a static folder in every app you can use:
python manage.py collectstatic
This grabs all your static files and put them on the same static folder (STATIC_ROOT)
Then your Ngnix also must to know where statifiles are stored
server {
access_log /pathto/log/acces.log;
error_log /pathto/log/error.log;
server_name ******
charset utf-8;
location /static {
alias /path/to/your/static; <---- This Line
}
location /intranet/ {
rewrite ^/intranet(.*) /$1 break;
proxy_redirect default;
proxy_pass http://127.0.0.1:8000;
}
}
Answered By - Zartch