django + nginx + postgresql + gunicorn настройка сервера с нуля

apt-get install sudo ssh openssh-server
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-virtualenv
sudo apt-get install libpq-dev python-dev
sudo apt-get install postgresql postgresql-contrib
sudo apt-get install nginx

sudo su - postgres
createdb mydb
createuser -P

myuser
p@ss "enter"
p@ss "enter"
n "enter"
n "enter"
n "enter"


psql
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;



mkdir /opt/project_env
cd /opt/project_env
sudo virtualenv /opt/project_env
source /opt/project_env/bin/activate
pip install django
pip install gunicorn
pip install psycopg2

django-admin.py startproject django_project
cd django_project
nano settings.py

---
   DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2', 
            'NAME': 'mydb',
            'USER': 'myuser',
            'PASSWORD': 'p@ss',
            'HOST': 'localhost',
            'PORT': '',
        }
    }
---

python manage.py syncdb
cd /opt/project_env
sudo nano gunicorn_config.py

---
    command = '/opt/project_env/bin/gunicorn'
    pythonpath = '/opt/project_env/django_project'
    bind = '127.0.0.1:8001'
    workers = 3
    user = nobody
---

/opt/project_env/bin/gunicorn -c /opt/project_env/gunicorn_config.py django_project.wsgi
mkdir /opt/project_env/static/
nano /etc/nginx/sites-available/django_project


---
server {
        server_name test.iamroot.ru;

        access_log off;

        location /static/ {
            alias /opt/project_env/static/;
        }

        location / {
                proxy_pass http://127.0.0.1:8001;
                proxy_set_header X-Forwarded-Host $server_name;
                proxy_set_header X-Real-IP $remote_addr;
                add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
        }
    }
---

cd /etc/nginx/sites-enabled
sudo ln -s ../sites-available/django_project
sudo service nginx start

Статья помогла? поддержите проект!

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *

Time limit is exhausted. Please reload the CAPTCHA.