S
S
Sergey Nizhny Novgorod2016-02-11 06:39:53
Django
Sergey Nizhny Novgorod, 2016-02-11 06:39:53

Yes, how to run this ... Django?

Task: Put the project on a VPS from Reg.ru based on CentOS:
What I do:
Ps First, in the hosting panel, I link the domain name and VPS through DNSadmin.
Pss A number of steps for installing components are omitted, as they are related to the operation of the necessary elements of the project, and not to work on the VPS.
1) I create a user with sudo rights. - bakotiinii
2) I set a set of commands:

sudo yum install epel-release
sudo yum install python-pip
sudo yum install wget
sudo pip install virtualenv virtualenvwrapper

echo "export WORKON_HOME=~/Env" >> ~/.bashrc #Все окружения буду сохранять в папку Env
echo "source /usr/bin/virtualenvwrapper.sh" >> ~/.bashrc
source ~/.bashrc

3) I put in the root folder of Python 3.4.3
wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tar.xz
tar -xvf Python-3.4.3.tar.xz
cd Python-3.4.3
./configure
make
sudo make install

4) Create an environment with python 3,4,3
mkvirtualenv -p /usr/local/bin/python3.4 django #The environment is named django.
5) Create an apifolder project, copy it via FTP with PyCharm.
6) I put the PostgreSQL database according to this tutorial
7) We write in the settings.py of our djanga:
DEBUG = False

ALLOWED_HOSTS = [
    '*',   
    ]

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'db',
        'USER': 'dbuser',
        'PASSWORD': 'dbpassword',
        'HOST': 'localhost',
        'PORT': '',
    }
}

Проверяем все это дело через наше окружение:
python manage.py makemigrations - работает.
python manage.py migration - работает.
python manage.py runsever 0.0.0.0:8080 - работает.
python manage.py collectstatic - не работает, так как еще нет сервера ngix.
8) Ставим uWSGI
sudo yum install python-devel gcc

sudo pip install uwsgi

9) Создаем конфиг:
sudo mkdir -p /etc/uwsgi/sites
cd /etc/uwsgi/sites

sudo nano apifolder.ini

################

[uwsgi]
project = apifolder # имя проекта
username = bakotiinii # пользователь
base = /home/%(username)

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

master = true
processes = 5

uid = %(username)
socket = /run/uwsgi/%(project).sock
chown-socket = %(username):nginx
chmod-socket = 660
vacuum = true

10) Создаем автозапуск:
sudo nano /etc/systemd/system/uwsgi.service
[Unit]
Description=uWSGI Emperor service

[Service]
ExecStartPre=/usr/bin/bash -c 'mkdir -p /run/uwsgi; chown bakotiinii:nginx /run/uwsgi'
ExecStart=/usr/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target

11) Конфиг Nginx
sudo yum install nginx

sudo nano /etc/nginx/nginx.conf

server {
    listen 80;
    server_name domen.ru www.domen.ru;

    location = favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/bakotiinii/apifolder;
    }

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/run/uwsgi/apifolder.sock;
    }
}

12) Делаем запуск:
sudo nginx -t

sudo usermod -a -G bakotiinii nginx
chmod 710 /home/bakotiinii

sudo systemctl start nginx
sudo systemctl start uwsgi

Что в итоге:
Доменное имя отдает, что там ничего нет.
А если зайти напрямую по IP, то появляется вот такое окно nginx: take.ms/5l0Gr
___________________________
Логи:
1)
crit] 7288#0: *52 connect() to unix:/run/uwsgi/apifolder.sock failed (2: No such file or directory) while connecting to upstream

2)
bakot uwsgi: uwsgi socket 0 bound to UNIX address /run/uwsgi/apifolder.sock fd 3
bakot uwsgi: setuid() to 1000
bakot uwsgi: Python version: 2.7.5 (default, Nov 20 2015, 02:00:19)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
bakot uwsgi: Set PythonHome to /home/bakotiinii/Env/apifolder
bakot uwsgi: ImportError: No module named site
bakot uwsgi: VACUUM: unix socket /run/uwsgi/apifolder.sock removed.
bakot uwsgi: [emperor] unrecognized vassal event on fd 7
bakot uwsgi: [emperor] unrecognized vassal event on fd 5
bakot uwsgi: Fri Feb 12 02:34:01 2016 - [emperor] removed uwsgi instance apifolder.ini
ImportError: No module named site

3) download?id=8FQvqr6xIBEd8mqNsCKVpuBb9AIx
There really is no such folder, since this folder contains only a virtual environment, and the project itself is higher: The
download?id=Z4K5EHR5gdThMkJOj5uYEvJcC1H0
virtual environment has a python version of 3.4, the server itself runs under 2.7. Nginx, etc. - I installed it globally.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
_
_ _, 2016-02-11
@AMar4enko

Turn on the Enginix logs with the debug flag and see what happens in them. Fakap somewhere at his level, it can easily be a problem with the rights

E
Egor Kazantsev, 2016-02-11
@saintbyte

I suggest starting with nginx logs

D
d7p4x, 2016-02-11
@d7p4x

Judging by the screenshot, the virtual domain looks in the wrong direction, I don’t rummage in django, but maybe you need to specify the directory for nginx in the config where to get the files? For /static/ you have root specified. And the domain must have an A record from the IP of this server.
root /var/www/public;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question