Re: Serving static files in production

2023-04-27 Thread David Nugent
Don't think I ever used alias for this.

You could try something like this (works for me - this is a cut and paste
of an existing working config) though you may be a little more constrained
with names of directories:

server {
[... elided]

location / {

location ~ /static/ {
sendfileon;
tcp_nopush  on;
root/srv/approot;
}

location / {
proxy_set_headerHost $http_host;
proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_headerX-Forwarded-Proto $scheme;
proxy_redirect  off;
proxy_pass  http://;
}
}
[... elided]
}

Note that files being served are contained in the actual directory
/srv/approot/static, and you can serve media here also from the "media" dir
using

location ~ /(media|static)/ { ...

HTH, David

On Thu, Apr 27, 2023 at 3:42 PM Brian Odhiambo 
wrote:

> Thanks for your response @David.
> Here is my nginx configuration.[image:
> 1c9b64ec-c74f-4004-8b8d-9a6e7a3d8069.png]
> Pointed it to staticfiles after running collectstatic files command.
>
> On Thu, Apr 27, 2023 at 8:11 AM Prosper Lekia 
> wrote:
>
>> Is whitenoise installed and added to MiddleWare?
>>
>> On Thu, Apr 27, 2023, 00:37 David Nugent  wrote:
>>
>>> Ensure that nginx is correctly configured, since from what you have
>>> provided the django configuration looks correct (although I generally use
>>> /static/ as STATIC_URL - with the leading / but should work as you have
>>> it). Check the nginx error log to try to discover the cause of the 404s. I
>>> suspect that the location blocks are defined in the wrong order or the
>>> directory pointing to the incorrect location.
>>>
>>> In any case, whitenoise is not a bad solution tbh, and very flexible
>>> besides. I would solve the above - which should work - before investigating
>>> that further.
>>>
>>> Regards,
>>> David
>>>
>>> On Thu, Apr 27, 2023 at 1:01 AM Brian Odhiambo <
>>> brianodhiambo...@gmail.com> wrote:
>>>
 Hello everyone,
 I am deploying a django project to a dedicated server.
 I have set nginx to find static files in this file "staticfiles".

 This is the setting in settings.py file:

 STATIC_ROOT = BASE_DIR / 'staticfiles'
 STATIC_URL = 'static/'

 After running collectstatic command, my project can't still load the
 static files.
 Could I get a general way of going about this, without having to rely
 on a third party library like whitenoise?

 My appreciation in advance.

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/eefed174-efad-4101-80c1-b0a589c64507n%40googlegroups.com
 
 .

>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAE5VhgWQ%3D589ZJwwycoO3g0%3DXh6x%2Bqjhu9---iUtV6nRQE4jhw%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CALGeGE1oLKr5e2hAz1WLV1k%3DO9JYpNss_1GX1CPRr_r4FuuvEg%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPjQKqZcbd8nPu-2cLAER_nGZnPtm%2BBbEXRDvFTtb-ZG40Bo5w%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe 

Re: Serving static files in production

2023-04-26 Thread Brian Odhiambo
@Prosper,
I installed whitenoise at some point, but later removed its configuration.

On Thu, Apr 27, 2023 at 8:11 AM Prosper Lekia 
wrote:

> Is whitenoise installed and added to MiddleWare?
>
> On Thu, Apr 27, 2023, 00:37 David Nugent  wrote:
>
>> Ensure that nginx is correctly configured, since from what you have
>> provided the django configuration looks correct (although I generally use
>> /static/ as STATIC_URL - with the leading / but should work as you have
>> it). Check the nginx error log to try to discover the cause of the 404s. I
>> suspect that the location blocks are defined in the wrong order or the
>> directory pointing to the incorrect location.
>>
>> In any case, whitenoise is not a bad solution tbh, and very flexible
>> besides. I would solve the above - which should work - before investigating
>> that further.
>>
>> Regards,
>> David
>>
>> On Thu, Apr 27, 2023 at 1:01 AM Brian Odhiambo <
>> brianodhiambo...@gmail.com> wrote:
>>
>>> Hello everyone,
>>> I am deploying a django project to a dedicated server.
>>> I have set nginx to find static files in this file "staticfiles".
>>>
>>> This is the setting in settings.py file:
>>>
>>> STATIC_ROOT = BASE_DIR / 'staticfiles'
>>> STATIC_URL = 'static/'
>>>
>>> After running collectstatic command, my project can't still load the
>>> static files.
>>> Could I get a general way of going about this, without having to rely on
>>> a third party library like whitenoise?
>>>
>>> My appreciation in advance.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/eefed174-efad-4101-80c1-b0a589c64507n%40googlegroups.com
>>> 
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAE5VhgWQ%3D589ZJwwycoO3g0%3DXh6x%2Bqjhu9---iUtV6nRQE4jhw%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALGeGE1oLKr5e2hAz1WLV1k%3DO9JYpNss_1GX1CPRr_r4FuuvEg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPjQKqaN8dHhw7OoYsBCXxycKo7qgAFkAWHT0o%3DRYMvauPL%3DtA%40mail.gmail.com.


Re: Serving static files in production

2023-04-26 Thread Brian Odhiambo
Thanks for your response @David.
Here is my nginx configuration.[image:
1c9b64ec-c74f-4004-8b8d-9a6e7a3d8069.png]
Pointed it to staticfiles after running collectstatic files command.

On Thu, Apr 27, 2023 at 8:11 AM Prosper Lekia 
wrote:

> Is whitenoise installed and added to MiddleWare?
>
> On Thu, Apr 27, 2023, 00:37 David Nugent  wrote:
>
>> Ensure that nginx is correctly configured, since from what you have
>> provided the django configuration looks correct (although I generally use
>> /static/ as STATIC_URL - with the leading / but should work as you have
>> it). Check the nginx error log to try to discover the cause of the 404s. I
>> suspect that the location blocks are defined in the wrong order or the
>> directory pointing to the incorrect location.
>>
>> In any case, whitenoise is not a bad solution tbh, and very flexible
>> besides. I would solve the above - which should work - before investigating
>> that further.
>>
>> Regards,
>> David
>>
>> On Thu, Apr 27, 2023 at 1:01 AM Brian Odhiambo <
>> brianodhiambo...@gmail.com> wrote:
>>
>>> Hello everyone,
>>> I am deploying a django project to a dedicated server.
>>> I have set nginx to find static files in this file "staticfiles".
>>>
>>> This is the setting in settings.py file:
>>>
>>> STATIC_ROOT = BASE_DIR / 'staticfiles'
>>> STATIC_URL = 'static/'
>>>
>>> After running collectstatic command, my project can't still load the
>>> static files.
>>> Could I get a general way of going about this, without having to rely on
>>> a third party library like whitenoise?
>>>
>>> My appreciation in advance.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/eefed174-efad-4101-80c1-b0a589c64507n%40googlegroups.com
>>> 
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAE5VhgWQ%3D589ZJwwycoO3g0%3DXh6x%2Bqjhu9---iUtV6nRQE4jhw%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALGeGE1oLKr5e2hAz1WLV1k%3DO9JYpNss_1GX1CPRr_r4FuuvEg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPjQKqZcbd8nPu-2cLAER_nGZnPtm%2BBbEXRDvFTtb-ZG40Bo5w%40mail.gmail.com.


Re: Serving static files in production

2023-04-26 Thread Prosper Lekia
Is whitenoise installed and added to MiddleWare?

On Thu, Apr 27, 2023, 00:37 David Nugent  wrote:

> Ensure that nginx is correctly configured, since from what you have
> provided the django configuration looks correct (although I generally use
> /static/ as STATIC_URL - with the leading / but should work as you have
> it). Check the nginx error log to try to discover the cause of the 404s. I
> suspect that the location blocks are defined in the wrong order or the
> directory pointing to the incorrect location.
>
> In any case, whitenoise is not a bad solution tbh, and very flexible
> besides. I would solve the above - which should work - before investigating
> that further.
>
> Regards,
> David
>
> On Thu, Apr 27, 2023 at 1:01 AM Brian Odhiambo 
> wrote:
>
>> Hello everyone,
>> I am deploying a django project to a dedicated server.
>> I have set nginx to find static files in this file "staticfiles".
>>
>> This is the setting in settings.py file:
>>
>> STATIC_ROOT = BASE_DIR / 'staticfiles'
>> STATIC_URL = 'static/'
>>
>> After running collectstatic command, my project can't still load the
>> static files.
>> Could I get a general way of going about this, without having to rely on
>> a third party library like whitenoise?
>>
>> My appreciation in advance.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/eefed174-efad-4101-80c1-b0a589c64507n%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAE5VhgWQ%3D589ZJwwycoO3g0%3DXh6x%2Bqjhu9---iUtV6nRQE4jhw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALGeGE1oLKr5e2hAz1WLV1k%3DO9JYpNss_1GX1CPRr_r4FuuvEg%40mail.gmail.com.


Re: Serving static files in production

2023-04-26 Thread David Nugent
Ensure that nginx is correctly configured, since from what you have
provided the django configuration looks correct (although I generally use
/static/ as STATIC_URL - with the leading / but should work as you have
it). Check the nginx error log to try to discover the cause of the 404s. I
suspect that the location blocks are defined in the wrong order or the
directory pointing to the incorrect location.

In any case, whitenoise is not a bad solution tbh, and very flexible
besides. I would solve the above - which should work - before investigating
that further.

Regards,
David

On Thu, Apr 27, 2023 at 1:01 AM Brian Odhiambo 
wrote:

> Hello everyone,
> I am deploying a django project to a dedicated server.
> I have set nginx to find static files in this file "staticfiles".
>
> This is the setting in settings.py file:
>
> STATIC_ROOT = BASE_DIR / 'staticfiles'
> STATIC_URL = 'static/'
>
> After running collectstatic command, my project can't still load the
> static files.
> Could I get a general way of going about this, without having to rely on a
> third party library like whitenoise?
>
> My appreciation in advance.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/eefed174-efad-4101-80c1-b0a589c64507n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE5VhgWQ%3D589ZJwwycoO3g0%3DXh6x%2Bqjhu9---iUtV6nRQE4jhw%40mail.gmail.com.


Serving static files in production

2023-04-26 Thread Brian Odhiambo
Hello everyone,
I am deploying a django project to a dedicated server.
I have set nginx to find static files in this file "staticfiles".

This is the setting in settings.py file:

STATIC_ROOT = BASE_DIR / 'staticfiles'
STATIC_URL = 'static/'

After running collectstatic command, my project can't still load the static 
files.
Could I get a general way of going about this, without having to rely on a 
third party library like whitenoise?

My appreciation in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eefed174-efad-4101-80c1-b0a589c64507n%40googlegroups.com.