location settings for Django Uwsgi Nginx Configuration for production

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

location settings for Django Uwsgi Nginx Configuration for production

ayman
Django settings

STATICFILES_DIRS = [STATIC_DIR, ]  
STATIC_DIR = os.path.join(BASE_DIR, 'static')  
STATIC_ROOT = '/home/sandyman/production/django_project/assets/'  
STATIC_URL = '/assets/'  

local machine  example file  

/home/sandyman/development/django_project/css/bootstrap.min.css
Template

{% load staticfiles %}
href="{% static "css/bootstrap.min.css" %}"
Production environment

ran python manage.py collectstatic

this succesfully  created all files in sub directories of  

**/home/sandyman/production/django_project/assets/**

e.g. /home/sandyman/production/django_project/assets/css/bootstrap.min.css


** NGING configuration


**server {
   server_name sandyman.xyz www.sandyman.xyz ;
   location /static {
      alias   /home/sandyman/production/django_project/assets/;  
    }
}**
** GET Request **

Request URL:http://www.sandyman.xyz/static/css/bootstrap.min.css 
Request Method:GET  
**Status Code:404 NOT FOUND**  

file bootstrap is located in

/home/sandyman/production/django_project/assets/css/bootstrap.min.css
Please assist me .. Ive tried many iterations of values for nginx location
but no success

django

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,276402,276402#msg-276402

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: location settings for Django Uwsgi Nginx Configuration for production

ayman
Have a look in the nginx error logfile where it expects the file to be.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,276402,276403#msg-276403

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: location settings for Django Uwsgi Nginx Configuration for production

ayman
error logs and access logs contain nothing
As it is a hosting company i don't seem to have priviliges to enable
debugginh
I'm not allowed to sudo

    error_log               logs/error.log;
    access_log              logs/access.log;

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,276402,276404#msg-276404

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: location settings for Django Uwsgi Nginx Configuration for production

ayman
A 404 is logged unless logging has been disabled, ask the hosting company
where logs are, check nginx.conf what/where is logged.
.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,276402,276407#msg-276407

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: location settings for Django Uwsgi Nginx Configuration for production

Francis Daly
In reply to this post by ayman
On Fri, Sep 15, 2017 at 08:29:20AM -0400, sandyman wrote:

Hi there,

> **server {
>    server_name sandyman.xyz www.sandyman.xyz ;
>    location /static {
>       alias   /home/sandyman/production/django_project/assets/;  
>     }
> }**
> ** GET Request **
>
> Request URL:http://www.sandyman.xyz/static/css/bootstrap.min.css 
> Request Method:GET  
> **Status Code:404 NOT FOUND**  
>
> file bootstrap is located in
>
> /home/sandyman/production/django_project/assets/css/bootstrap.min.css

That nginx config with that request for that url, works for me --
http 200 with the content of the file.

If there is nothing in nginx logs, that suggests that maybe you are not
connecting to the ip:port that uses this config; or perhaps that there
is more config that is relevant that you are not showing.

You can prove that you are using the config that you think by, for
example, adding a snippet like

  location = /test-this/ { return 200 "Yes, this is correct\n"; }

and then requesting http://www.sandyman.xyz/test-this/

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: location settings for Django Uwsgi Nginx Configuration for production

ayman
Hello Francis ,

Thank you for your help this far  

what happened was  I Set DEBUG=True in Django settings , and urlpatterns +=
staticfiles_urlpatterns()
this allowed  the files to be served in a non secure setting

I'm back to where I started.  I added to my config

location = /test-this/ { return 200 "Yes, this is correct\n"; }

I stopped and started nginx , and restarted the server

and then requesting http://www.sandyman.xyz/test-this/

I get the 404

Request URL:http://www.asandhu.xyz/test-this/
Request Method:GET
Status Code:404 NOT FOUND


I'm stuck again

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,276402,276419#msg-276419

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: location settings for Django Uwsgi Nginx Configuration for production

ayman
In reply to this post by Francis Daly
2 hours later still struggling but getting some error logs now


 location /foo { return 200 "yikes ";}

returns yikes ..

however  www.asandhu.xyz   returns 502


log file states either uwsgi.sock failed (13: Permission denied)  664 and
owned by me
 or (111: Connection refused) when chmod 777 and owned by me

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,276402,276423#msg-276423

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: location settings for Django Uwsgi Nginx Configuration for production

Francis Daly
In reply to this post by ayman
On Sun, Sep 17, 2017 at 09:16:12AM -0400, sandyman wrote:

Hi there,

> I'm back to where I started.  I added to my config
>
> location = /test-this/ { return 200 "Yes, this is correct\n"; }
>
> I stopped and started nginx , and restarted the server
>
> and then requesting http://www.sandyman.xyz/test-this/
>
> I get the 404

That says that the nginx.conf that the running nginx is actually using
is not the nginx.conf that you are editing.

Until you can edit the correct section of the file, you will not be able
to fix things.

> Request URL:http://www.asandhu.xyz/test-this/

Note that "sandyman" and "asandhu" are not the same thing.

Perhaps you are not connecting to the IP address that you want to be
connecting to?

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx