django nginx uwsgi部署失败 [英] django nginx uwsgi deploying fail

查看:295
本文介绍了django nginx uwsgi部署失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试部署一个简单的Django项目,但一直失败。我是



在virtualenv我已经安装了uWSGI:

  pip install uwsgi 

并写了 test.py

 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 
return [bHello World]#python3
#return [Hello World]#python2

运行 uwsgi --http:8000 --wsgi-file test.py 我可以看到





然后我安装启动Nginx: p>

  sudo apt-get install nginx 
sudo /etc/init.d/nginx start

我可以看到





并运行:

  sudo ln -s〜/ home / parallels / books / mysite / mysite_nginx.conf 
/ etc / nginx / sites-enabled /

我可以在 / etc / nginx / sites-enabled / mysite_nginx.conf c>:





然后运行:

  sudo /etc/init.d/nginx restart 
uwsgi --socket:8001 - wsgi-file test。 py

我的webbrowser中没有任何内容:





我不知道为什么,每当我尝试部署Django站点时,套接字部分失败。

解决方案

最后,我通过使用XML来配置uWSGI并成功部署Django项目。但是,这一次我不使用virtualenv。



我创建了虚拟主机配置 / etc / nginx / sites-enabled / mysite

  server {
listen 80; ##听ipv4;这行是默认的,隐含的
#listen [::]:80 default ipv6only = on; ##听ipv6

server_name 10.211.55.21;

access_log /var/log/nginx/mysite-access.log;
error_log /var/log/nginx/mysite-error.log;

位置/ {
uwsgi_pass 127.0.0.1:8630;
包括uwsgi_params;
}

}

然后创建 /home/parallels/books/mysite/django.xml 文件,请注意,该文件的名称可以是任何东西,但应以 *结尾。xml

 < uwsgi> 
< socket> 127.0.0.1:8630< / socket>
< chdir> / home / parallels / books / mysite / mysite< / chdir>
< pythonpath> ..< / pythonpath>
< module> wsgi< / module>
< / uwsgi>

< chdir> / home / parallels / books / mysite / mysite< ; / chdir> 只是指向< module> wsgi< / module> ,因为有一个 wsgi.py /home/parallels/books/mysite/mysite/wsgi.py



然后我运行以下命令:

  $ sudo /etc/init.d/nginx restart 
$ uwsgi -x django.xml

现在网站可访问:





但是我无法使用 uwsgi.ini

配置和部署Django, code>。


I am trying to deploy a simple Django project, but fail all the time. I am following the instruction here.

When I use python manage.py runserver 0.0.0.0:8000 I can see that my site is running:

In the virtualenv I've installed uWSGI:

pip install uwsgi

and wrote the test.py:

# test.py
def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World"] # python3
    #return ["Hello World"] # python2

When running uwsgi --http :8000 --wsgi-file test.py I can see

I then installed en started Nginx:

sudo apt-get install nginx
sudo /etc/init.d/nginx start

I can see

and then wrote mysite_nginx.conf:

upstream django {
    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8000;
    # the domain name it will serve for
    server_name 10.211.55.21; # 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 /path/to/your/mysite/media;  # your Django project's media files - amend as required
    #}

    #location /static {
     #   alias /path/to/your/mysite/static; # your Django project's static files - amend as required
    #}

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/parallels/books/mysite/uwsgi_params; # the uwsgi_params file you installed
    }
}

because it is just a simple site I commented out the media and static paths, and uwsgi_params:

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;

the directory:

and run:

sudo ln -s ~/home/parallels/books/mysite/mysite_nginx.conf
/etc/nginx/sites-enabled/

I can see mysite_nginx.conf within /etc/nginx/sites-enabled/:

and then run:

sudo /etc/init.d/nginx restart
uwsgi --socket :8001 --wsgi-file test.py

I see nothing in my webbrowser:

I do not know why, whenever I try deploying a Django site the socket part fails.

解决方案

Finally I made it by using XML to configure uWSGI and deploying Django project successfully. However, this time I do not use a virtualenv.

I created the virtual host configuration /etc/nginx/sites-enabled/mysite:

server {
    listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    server_name 10.211.55.21;

    access_log /var/log/nginx/mysite-access.log ;
    error_log /var/log/nginx/mysite-error.log ;

    location / {
            uwsgi_pass 127.0.0.1:8630;
            include uwsgi_params;
    }

}

Then created the /home/parallels/books/mysite/django.xml file, note that the name of the file can be anything but should end with *.xml:

<uwsgi>
    <socket>127.0.0.1:8630</socket>
    <chdir>/home/parallels/books/mysite/mysite</chdir>
    <pythonpath>..</pythonpath>
    <module>wsgi</module>
</uwsgi>

the <chdir>/home/parallels/books/mysite/mysite</chdir> just point to <module>wsgi</module> because there is a wsgi.py in /home/parallels/books/mysite/mysite/wsgi.py.

I then run the following commands:

$ sudo /etc/init.d/nginx restart
$ uwsgi -x django.xml

now the website is reachable:

But I fail to configure and deploying Django using uwsgi.ini.

这篇关于django nginx uwsgi部署失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆