程序员

Django + nginx + uwsgi 部署(linux)

2017-02-03  本文已影响430人  single430

首先确保你的系统有安装django,uwsgi,nginx,具体如何安装网上的教程一大把,这里我就写几个自己遇到的问题


* 首先

在测试uwsgi是否工作是我们都会写一个xxx.py文件,如下

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

运行: uwsgi --http :8000 --wsgi-file xxx.py 后,登录http:127.0.0.1:8000


* 再者

就是uwsgi.ini 和 nginx.conf 的配置了
下面我贴上自己的配置文件:

uwsgi.ini(下面xxx为你的django项目名, you是你自己的/home/you/)
[uwsgi]
# Django-related settings
# socket = :8000
socket = /home/you/xxx/xxx.sock
chmod-socket = 666
uid = you
gid = you
# the base directory (full path)
chdir = /home/zbl/xxx
# Django s wsgi file
module = xxx.wsgi
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 4
# clear environment on exit
vacuum = true

xxx_nginx.conf(下面xxx为你的django项目名, you是你自己的/home/you/)
# xxx_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///home/you/xxx/xxx.sock; # for a file socket
    # server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name www.example.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 /path/to/your/mysite/media;  # your Django project's media files - amend as required
    # }

    location /static {
        alias /home/you/xxx/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/you/xxx/uwsgi_params; # the uwsgi_params file you installed
    }
}

最后

自己遇到的一些问题,写的不好,还望指教
By: single430

上一篇 下一篇

猜你喜欢

热点阅读