1
votes

I have a django application. I can't seem to get nginx to serve the static files correctly, but that's not this issue.

The current issue is that when following this guide: https://gist.github.com/evildmp/3094281

I try to use the unix sockets rather than the web socket.

e.g.

server unix:///tmp/uwsgi.sock;    # for a file socket
#server 127.0.0.1:8001;      # for a web port socket

using the /tmp/uwsgi.sock socket rather than the 127.0.0.1:8001 web port socket.

The issue is that when I use the web port socket, and I navigate to domainname.com:8001 I reach the website as served by uWSGI, but there are no staticfiles loaded. So that means that at least uwsgi is working. But when I switch over to the file socket, I cannot even get it to work at all.

What am I doing wrong?

Here is my nginx.conf:

# nginx.conf
upstream django {
    # connect to this socket
    # server unix:///tmp/uwsgi.sock;    # for a file socket (TRYING TO USE)
    server 127.0.0.1:8001;      # for a web port socket (RATHER THAN THIS)
    }

server {
    # the port your site will be served on
    listen      8000;
    # the domain name it will serve for
    server_name .cshenkan.com;   # substitute your machine's IP address or FQDN
    charset     utf-8;

    #Max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
            alias /home/ubuntu/sasite-rewrite/media;      # your Django pro$
    }

    location /static {
            alias /home/ubuntu/sasite-rewrite/static;     # your Django pro$
    }
    location /assets  {
            alias /home/ubuntu/sasite-rewrite/assets
    } 

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /etc/nginx/uwsgi_params; # or the uwsgi_params you installe$
        }
    }

And my base.py settings file snippet:

STATIC_ROOT = normpath(join(SITE_ROOT, 'static'))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    normpath(join(SITE_ROOT, 'static')),
    normpath(join(SITE_ROOT, 'assets')),
)

And how I run uwsgi when using the web socket:

uwsgi --http :8001 --chdir /home/ubuntu/sasite-rewrite --wsgi-file /home/ubuntu/sasite-rewrite/sasite/wsgi.py

And how I run it when using the unix socket:

uwsgi --socket /tmp/uwsgi.sock --chdir /home/ubutnu/sasite-rewrite --wsgi-file /home/ubuntu/sasite-rewrite/sasite/wsgi.py

I just can't seem to get it to work when using the unix socket.

Neither can I get nginx to serve the correct static files, for example if I add a file to the media directory called 1.png or 1.txt and try to access them with domainname.com:8000/media/1.png I always get a hang or a no response from server error.

What am I doing wrong?

How can I get the unix socket to work correctly? And is the command I'm using correct?

I also don't understand this, when I use the web socket, I can connect to domainname.com:8001 and get the page with no static files, it looks like crap but loads from uwsgi. But with the unix sockets I have no idea how to access the page served by uwsgi to see if it works with the unix socket. Before I can move onto getting nginx working, I need to solve this issue, as I tried using web sockets with nginx and still had no luck there, I'm hoping once my unix sockets are set up correctly nginx will work better.

Any suggestions, or examples you could provide? Would be much appreciated, I am a long time django programmer, but I have very rarely deployed the sites myself. So I am really struggling here.

Any help is much appreciated, thanks.

1
What does the nginx error.log say? What do you mean by "not working"? What status code is nginx giving you?Blender
I am just unable to access the website from the port specified in nginx.conf. So to get the static files working with the site I need to get nginx to serve the static files and let uWSGI communicate with Django to serve the rest. UWSGI does so alone with no static files. But nginx doesn't seem to be working at sll. When I get into the office in the morning I will post the nginx access log.shenk
You should get something (like a generic nginx error page). If not, then you should try getting nginx to run before doing anything else with it. Once that's working, post the last few lines of the error.log.Blender
Will do when I get into office and no I am not seeing the standard nginx error page. I am seeming to have issues getting uWSGI and nginx to cooperate.shenk
If you can't load anything, then nginx probably isn't even running.Blender

1 Answers

1
votes

Today I had the same problem with NGINX + Socket Unix for uwsgi protocol. I discovered that version 1.8 of the NGINX is bugged.

Try installing version 1.10 that will work via UNIX SOCKET.

If you use open-SuSE, you can get the rpm here:

http://download.opensuse.org/repositories/home:/ghostlyrat/openSUSE_Leap_42.2/x86_64/nginx-1.10.1-3.3.x86_64.rpm

Or, directly in the official nginx downloads area:

http://nginx.org/en/download.html