Linode Django uwsgi Nginx [英] Linode Django uwsgi Nginx

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

问题描述

以下设置仅让我看到默认的Nginx html页面.我如何去Django?

我一直在关注Linode的文档(如何设置它)(以及许多其他教程),但是它们不使用systemd,因此情况有所不同.

解决方案

以下内容对我有用,但是我不确定这是否是正确或最有效的方法,尤其是在涉及套接字的情况下./p>

systemd运行uwsgi.service,可以通过以下方式启动

:

  $ sudo systemctl启动uwsgi.service 

有时必须使用重新加载systemd,

  $ sudo systemctl守护进程重新加载 

/etc/sysemd/system/uwsgi.service

  [单位]Description = uWSGI Emperor服务之后= syslog.target[服务]ExecStart =/home/ofey/djangoenv/bin/uwsgi --emperor/etc/uwsgi/sites重启=总是KillSignal = SIGQUIT类型=通知StandardError =系统日志NotifyAccess =全部[安装]WantedBy =多用户目标 

这会用

调用我的django虚拟环境目录中的二进制文件.

ExecStart =/home/ofey/djangoenv/bin/uwsgi

并带我们到/etc/uwsgi/sites,其中uwsgi配置文件称为djangoForum.ini

/etc/uwsgi/sites/djangoForum.ini

  [uwsgi]项目= djangoForum基本=/home/ofeychdir =%(基础)/%(项目)主页=%(基本)/djangoenv模块= crudProject.wsgi:应用程序大师=真流程= 2插座= 127.0.0.1:3031chmod-socket = 664真空=真 

Django位于/home/ofey/djangoForum,而我的django项目位于/home/ofey/djangoForum/crudProject

/etc/nginx/nginx.conf

 事件{worker_connections 1024;}http {上游django {#连接到此插座#服务器unix:///tmp/uwsgi.sock;#用于文件套接字服务器127.0.0.1:3031;#用于Web端口套接字}服务器 {#您的网站将在其上服务的端口听80;#将为其服务的域名server_name example.com;#替换您机器的IP地址或FQDN字符集utf-8;#最大上传大小client_max_body_size 75M;#调整口味#Django媒体位置/媒体{别名/home/ofey/djangoForum/fileuploader/uploaded_files;#您的Django项目的媒体文件}位置/static {别名/home/ofey/djangoForum/noAppBoundStaticDirectory;#您的Django项目的静态文件}#最后,将所有非媒体请求发送到Django服务器.地点/{uwsgi_pass django;#uwsgi_pass 127.0.0.1:3031;包括/etc/nginx/uwsgi_params;#或您手动安装的uwsgi_params}}} 

nginx可以打开,

  $ sudo systemctl start nginx.service 

开始"可以替换为重新开始"或停止".

uwsgi和nginx的这些配置文件对我有用.

有用的链接:

https://gist.github.com/evildmp/3094281

https://www.linode.com/docs/websites/nginx/deploy-django-applications-using-uwsgi-and-nginx-on-ubuntu-14-04

I am using Linode with Fedora24. I have installed my virutalenv at /home/ofey/djangoenv and activated it, Django is installed using pip at /home/ofey/qqiProject Into the virtualenv I've installed uwsgi. Firstly, /etc/systemd/system/uwsgi.service

[Unit]
Description=uWSGI Emperor service
After=syslog.target

[Service]
ExecStart=/home/ofey/djangoenv/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

This executes,

/etc/uwsgi/sites/qqiProject.ini

[uwsgi]
project = qqiProject
base = /home/ofey

chdir = %(base)/%(project)
home = %(base)/djangoenv
module = %(project).wsgi:application

master = true
processes = 2

socket = %(base)/%(project)/%(project).sock
chmod-socket = 664
vacuum = true

Also,

/etc/nginx/sites-available/qqiProject

server {
    listen 80;
    server_name qqiresources.com www.qqiresources.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/django/qqiProject;
    }

    location / {
        include         uwsgi_params;
        uwsgi_pass      unix:/home/django/qqiProject/qqiProject.sock;
    }
}

The file /etc/nginx/nginx.conf has not been changed.

The user is ofey, I've used,

$ sudo systemctl daemon-reload
$ sudo systemctl restart nginx
$ sudo systemctl start uwsgi.service

Started Django with,

$ python manage.py runserver

To Django's settings.py I turned off debugging and added a host

DEBUG = False

ALLOWED_HOSTS = ['qqiresources.com']

I have also created a symbolic link,

sudo ln -s /etc/nginx/sites-available/qqiProject /etc/nginx/sites-enabled

Any help would be greatly appreciated,

Thanks

解决方案

The following is working for me, however I am not sure if this is the correct or most efficient way to do it, especially where the sockets are concerned.

systemd runs the uwsgi.service and can be started with,

$ sudo systemctl start uwsgi.service

Sometimes it is necessary to reload systemd using,

$ sudo systemctl daemon-reload

/etc/sysemd/system/uwsgi.service

[Unit]
Description=uWSGI Emperor service
After=syslog.target

[Service]
ExecStart=/home/ofey/djangoenv/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

This calls the binary inside my django virtual environment directory with,

ExecStart=/home/ofey/djangoenv/bin/uwsgi

and also takes us to /etc/uwsgi/sites where the uwsgi configuration files is called djangoForum.ini

/etc/uwsgi/sites/djangoForum.ini

[uwsgi]
project = djangoForum
base = /home/ofey

chdir = %(base)/%(project)
home = %(base)/djangoenv
module = crudProject.wsgi:application

master = true
processes = 2

socket = 127.0.0.1:3031
chmod-socket = 664
vacuum = true

Django is at /home/ofey/djangoForum and my django project is at /home/ofey/djangoForum/crudProject

/etc/nginx/nginx.conf

events {
     worker_connections 1024;
}

http{

 upstream django {
    # connect to this socket
    # server unix:///tmp/uwsgi.sock;    # for a file socket
    server 127.0.0.1:3031;      # for a web port socket
    }

server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name 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 /home/ofey/djangoForum/fileuploader/uploaded_files;      # your Django project's media files
    }

        location /static {
                alias /home/ofey/djangoForum/noAppBoundStaticDirectory;     # your Django project's static files
        }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        # uwsgi_pass 127.0.0.1:3031;
        include     /etc/nginx/uwsgi_params; # or the uwsgi_params you installed manually
        }
  }
}

nginx can be turned on with,

$ sudo systemctl start nginx.service

'start' can be replaced with, 'restart' or 'stop'.

These configuration files for uwsgi and nginx worked for me.

Useful links:

https://gist.github.com/evildmp/3094281

https://www.linode.com/docs/websites/nginx/deploy-django-applications-using-uwsgi-and-nginx-on-ubuntu-14-04

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

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