mariepiercm
mariepiercm

Reputation: 119

Deploying Django with uwsgi and nginx, uwsgi ok but nginx not working

I am trying to run my site, when i run

uwsgi --socket 0.0.0.0:8080 --protocol=http --chdir /opt/virtualenv/landivarpj/ --wsgi-file /opt/virtualenv/landivarpj/landivarpj/wsgi.py 

i can access 192.xxx.xxx.xxx:8080 fine and my test text appears, but if i try to go trought 192.xxx.xxx.xxx i only get an nginx welcome page, and if i try to go in trought my domain www.xxxxxxxx.com, then it doesnt work at all.

in my project folder(opt/virtualenv/landivarpj) i have a uswgi_params file with

uwsgi_param  QUERY_STRING       $query_string;
uwsgi_param  REQUEST_METHOD     $request_method;
uwsgi_param  CONTENT_TYPE       $content_type;
uwsgi_param  CONTENT_LENGTH     $content_length;

uwsgi_param  REQUEST_URI        $request_uri;
uwsgi_param  PATH_INFO          $document_uri;
uwsgi_param  DOCUMENT_ROOT      $document_root;
uwsgi_param  SERVER_PROTOCOL    $server_protocol;
uwsgi_param  REQUEST_SCHEME     $scheme;
uwsgi_param  HTTPS              $https if_not_empty;

uwsgi_param  REMOTE_ADDR        $remote_addr;
uwsgi_param  REMOTE_PORT        $remote_port;
uwsgi_param  SERVER_PORT        $server_port;
uwsgi_param  SERVER_NAME        $server_name;

then in (opt/virtualenv/landivarpj/landivarpj) the wsgi.py is

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "landivarpj.settings")

application = get_wsgi_application()

in etc/nginx/sites-available is have drlandivar.conf

upstream django {
    server 192.xxx.xxx.xxx:8080; # for a web port socket (we'll use this first)
}

server {
    listen      80;
    server_name drlandivar.com www.drlandivar.com;
    charset     utf-8;

    client_max_body_size 75M;   # adjust to taste

    location /media  {
        alias /opt/virtualenv/landivarpj/media;  
    }

    location /static {
        alias /opt/virtualenv/landivarpj/static; 
    }

    location / {
        uwsgi_pass  django;
        include     /opt/virtualenv/landivarpj/uwsgi_params; 
    }
}

the site-available and site-enable are linked

what have i done wrong why it work on 192.xxx.xxx.xxx:8080 but not trought the domain and nginx

***** new edit as recommended on nginx/availables-site/drlandivar.conf

upstream django {
    server 192.254.145.207:8080;
}

server {
    listen      80;
    server_name drlandivar.com www.drlandivar.com;
    charset     utf-8;

    client_max_body_size 75M;   # adjust to taste

    location /media  {
        alias /opt/virtualenv/landivarpj/media;  
    }

    location /static {
        alias /opt/virtualenv/landivarpj/static; 
    }

    location / {
        proxy_pass  http://django;
    }
}

it still give me same problem page only load trought 192.xxx.xxx.xxx:8080 not trought drlandivar.com please help

Upvotes: 1

Views: 998

Answers (2)

Dave W. Smith
Dave W. Smith

Reputation: 24966

Comparing yours to a working example of mine, one thing stands out. Try

...
location / {
    include uwsgi_params;
    proxy_pass http://django;
}

Adding --logto /var/log/uwsgi/uwsgi.log to your uwsgi invocation (after creating /var/log/uswgi and making it writeable to the uwsgi process) might shed some additional light.

Upvotes: 0

sipp11
sipp11

Reputation: 486

You need to proxy_pass instead. The following configuration should do the trick.

upstream django {
    server 192.254.145.207:8080;
}

server {

    ...

    location / {
        proxy_pass  http://django;
    }
}

Upvotes: 1

Related Questions