- ssh user@your_ip
- Generar llave
ssh-keygen -b 4096
(dentro de .ssh) - Enviar llave al server
ssh-copy-id -i .ssh/name.pub user@your_ip
- Conectar:
ssh user@your_ip
- update
apt-get update
- Ingresar como root
apt-get install nginx
(todo lo que sea instalar con apt-get con root) - Revisar desde la web si esta la pagina de bienvenida de nginx
- Install postgresql
apt-get install postgresql postgresql-contrib
- Log w/ user
sudo -i -u postgres
- Verificar si puede ingresar a
psql
sudo adduser postgres_user
- Log w/ user
sudo -i -u postgres
psql
CREATE USER postgres_user WITH PASSWORD 'password';
(debe hacer match con el usuario creado);CREATE DATABASE my_postgres_db OWNER postgres_user;
\q
exit
logout- Log w/ user
sudo -i -u postgres_user
- Check
psql my_postgres_db
- Install
apt-get install python-pip
- Install
pip install virtualenv
- create workarea
mkdir workarea; cd workarea
- create virtualenv
virtualenv venv
- activate
source venv/bin/activate
- activate
source venv/bin/activate
- Create ssh key for download project from repo server (bitbuket, github etc)
ssh-keygen -b 4096
(inside server) as root user- copy key and add in server repo (bitbuket, github etc)
- git clone url_repo
pip install -r requirements.txt
(inside virtualenv)
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'my_postgres_db',
'USER': 'postgres_user',
'PASSWORD': '.....',
'HOST': 'localhost',
'PORT': '',
}
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
python manage.py migrate --settings=app.settings.production
python manage.py createsuperuser --settings=app.settings.production
python manage.py collectstatic --settings=app.settings.production
python manage.py runserver 0.0.0.0:8000 --settings=app.settings.production
- check in web server run django in port 8000 (remember enabled port in dashboard azure, amazon etc) (http://server_domain_or_IP:8000)
- install Gunicorn
pip install gunicorn
(inside virtualenv) - run
gunicorn -b 0.0.0.0:8000 app.wsgi
(app is name folder the core django project) - check in web server run django in port 8000 (remember enabled port in dashboard azure, amazon etc) (http://server_domain_or_IP:8000)
- Install Supervisor
apt-get install supervisor
(with root user) - enter in config supervisor
cd /etc/supervisor/conf.d/
- create myapp.conf
vim myapp.conf
:
[program:myapp]
directory=/home/your_user/your_workspace/your_project
command = /home/your_user/your_workspace/venv/bin/gunicorn -b 0.0.0.0:8080 app.wsgi
user = your_user
supervisorctl reread
supervisorctl update
supervisorctl restart all
supervisorctl status
- Project already without run commands (projecy run in port 8000)
- enter in config nginx
cd /etc/nginx/sites-available/
- create file
vim myapp
:
upstream myapp_app {
server 127.0.0.1:8000;
}
server {
listen 80;
server_name your_domain;
access_log /var/log/nginx/myapp.log;
error_log /var/log/nginx/myapp.error.log;
location / {
proxy_pass http://myapp_app;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location /static/ {
root /home/your_user/your_workarea/your_project;
}
}
- Enter in
cd /etc/nginx/sites-enabled
- Create link simbol
ln -s /etc/nginx/sites-available/myapp .
- run
nginx -t
- run
service nginx restart
Failed building wheel for cryptography ´sudo apt-get install build-essential libssl-dev libffi-dev python-dev´ settings --setting django
- ´try touch init.py in your settings directory´ but see next error ImportError: No module named
- Craete _init_.py file for packages in python https://docs.python.org/3/tutorial/modules.html#packages
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04
This gist saved my life.