[GH-ISSUE #1718] Django Static files serving #1277

Closed
opened 2026-02-26 06:36:31 +03:00 by kerem · 11 comments
Owner

Originally created by @Maxino22 on GitHub (Jan 2, 2022).
Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/1718

Hello am new to nginx proxy manger and soo far i have understood the workflow however in the location section am having a bit of trouble.. am running a django app with gunicorn which only handles python code hence my static files(javaScript & CSS) are not being served..
i want to include them in the location area but every time I do it the host goes offline... if I used an nginx config file traditionally this is what it would look like

server {
    listen 80;
    server_name YOUR_IP_ADDRESS;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/djangoadmin/pyapps/btre_project;
    }
    
    location /media/ {
        root /home/djangoadmin/pyapps/btre_project;    
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

I want the proxy params , media and static to be included in location but I can't find a way... kindly assist

Originally created by @Maxino22 on GitHub (Jan 2, 2022). Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/1718 Hello am new to nginx proxy manger and soo far i have understood the workflow however in the location section am having a bit of trouble.. am running a django app with gunicorn which only handles python code hence my static files(javaScript & CSS) are not being served.. i want to include them in the location area but every time I do it the host goes offline... if I used an nginx config file traditionally this is what it would look like ```nginx server { listen 80; server_name YOUR_IP_ADDRESS; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /home/djangoadmin/pyapps/btre_project; } location /media/ { root /home/djangoadmin/pyapps/btre_project; } location / { include proxy_params; proxy_pass http://unix:/run/gunicorn.sock; } } ``` I want the proxy params , media and static to be included in location but I can't find a way... kindly assist
kerem 2026-02-26 06:36:31 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@chaptergy commented on GitHub (Jan 2, 2022):

The way I understand you are trying to do it is not possible. I'm assuming you run the django app with gunicorn in a container? Then npm has no access to the files you are trying to serve. Furthermore static file serving is not supported officially by npm, there only is a feature request for it. You should theoretically be able to have static file serving by mounting the files into the container and using the advanced config, but we can't officially support this, you might want to try the reddit community.
But as a tip: only the three non-/ locations are relevant, the / location and stuff above the locations are automatically generated. You also want to use the advanced config, as the custom locations generate code for proxying, not for file serving. But pasting the three locations into the advanced tab and mounting the files into the npm container should work.

<!-- gh-comment-id:1003784078 --> @chaptergy commented on GitHub (Jan 2, 2022): The way I understand you are trying to do it is not possible. I'm assuming you run the django app with gunicorn in a container? Then npm has no access to the files you are trying to serve. Furthermore static file serving is not supported officially by npm, there only is a [feature request](https://github.com/jc21/nginx-proxy-manager/issues/58) for it. You should theoretically be able to have static file serving by mounting the files into the container and using the advanced config, but we can't officially support this, you might want to try the [reddit community](https://reddit.com/r/nginxproxymanager). But as a tip: only the three non-`/` locations are relevant, the `/` location and stuff above the locations are automatically generated. You also want to use the advanced config, as the custom locations generate code for proxying, not for file serving. But pasting the three locations into the advanced tab and mounting the files into the npm container should work.
Author
Owner

@Maxino22 commented on GitHub (Jan 3, 2022):

Thank you very much for replying . I honestly did not understand but I found a work around using whitehorse to serve my statics directly from the python. I tried looking at the credit community for answers but none of them were to detail. finally I would like some assist on redirecting as the HTTP versions of my domain are still accessible and the www does not redirect to non www .... i saw redirect host but documentation and online searches don't quite show

<!-- gh-comment-id:1004334442 --> @Maxino22 commented on GitHub (Jan 3, 2022): Thank you very much for replying . I honestly did not understand but I found a work around using whitehorse to serve my statics directly from the python. I tried looking at the credit community for answers but none of them were to detail. finally I would like some assist on redirecting as the HTTP versions of my domain are still accessible and the www does not redirect to non www .... i saw redirect host but documentation and online searches don't quite show
Author
Owner

@chaptergy commented on GitHub (Jan 3, 2022):

Create a redirect host for www.example.com and redirect it to example.com usually with a 301 redirect. If you know, that this redirect will change in the future, use a 302 redirect to indicate it is temporary.
To make sure you only use HTTPS just enable Force SSL and HSTS in your proxy host.

<!-- gh-comment-id:1004337603 --> @chaptergy commented on GitHub (Jan 3, 2022): Create a redirect host for `www.example.com` and redirect it to `example.com` usually with a `301` redirect. If you know, that this redirect will change in the future, use a `302` redirect to indicate it is temporary. To make sure you only use HTTPS just enable _Force SSL_ and _HSTS_ in your proxy host.
Author
Owner

@Maxino22 commented on GitHub (Jan 3, 2022):

Wow thank you that actually worked

<!-- gh-comment-id:1004339624 --> @Maxino22 commented on GitHub (Jan 3, 2022): Wow thank you that actually worked
Author
Owner

@keniobats commented on GitHub (Sep 30, 2022):

@Maxino22 Hi! any updates on this? I'm facing the same issue. Couldn't find any references to "whitehorse" you mention. Thanks!

<!-- gh-comment-id:1263569163 --> @keniobats commented on GitHub (Sep 30, 2022): @Maxino22 Hi! any updates on this? I'm facing the same issue. Couldn't find any references to "whitehorse" you mention. Thanks!
Author
Owner

@Maxino22 commented on GitHub (Sep 30, 2022):

sorry mate its not whitehorse rather white noise... it makes running django quite easy.... http://whitenoise.evans.io/en/stable/ ... it will be easy read the docs i beleive will solve problem

<!-- gh-comment-id:1263575915 --> @Maxino22 commented on GitHub (Sep 30, 2022): sorry mate its not whitehorse rather white noise... it makes running django quite easy.... http://whitenoise.evans.io/en/stable/ ... it will be easy read the docs i beleive will solve problem
Author
Owner

@keniobats commented on GitHub (Sep 30, 2022):

Thanks @Maxino22 I'll give it a shot!

<!-- gh-comment-id:1263681827 --> @keniobats commented on GitHub (Sep 30, 2022): Thanks @Maxino22 I'll give it a shot!
Author
Owner

@keniobats commented on GitHub (Oct 1, 2022):

I've already solved with Whitenoise, thanks @Maxino22 !!!

<!-- gh-comment-id:1264470309 --> @keniobats commented on GitHub (Oct 1, 2022): I've already solved with Whitenoise, thanks @Maxino22 !!!
Author
Owner

@Maxino22 commented on GitHub (Oct 2, 2022):

you welcome... Glad i could help 🔥

<!-- gh-comment-id:1264564091 --> @Maxino22 commented on GitHub (Oct 2, 2022): you welcome... Glad i could help 🔥
Author
Owner

@snake-soft commented on GitHub (Dec 17, 2022):

It can cause problems when adding an advanced configuration and enable "cache assets".
I got a 404 trying to load asset files (Django static and media).
It works after disabling "cache assets".

<!-- gh-comment-id:1356463114 --> @snake-soft commented on GitHub (Dec 17, 2022): It can cause problems when adding an advanced configuration and enable "cache assets". I got a 404 trying to load asset files (Django static and media). It works after disabling "cache assets".
Author
Owner

@mr-engin3er commented on GitHub (Sep 23, 2024):

It can cause problems when adding an advanced configuration and enable "cache assets". I got a 404 trying to load asset files (Django static and media). It works after disabling "cache assets".

This solved my issue.

<!-- gh-comment-id:2367406566 --> @mr-engin3er commented on GitHub (Sep 23, 2024): > It can cause problems when adding an advanced configuration and enable "cache assets". I got a 404 trying to load asset files (Django static and media). It works after disabling "cache assets". This solved my issue.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nginx-proxy-manager-NginxProxyManager#1277
No description provided.