$ add-apt-repository universe
$ apt-get update
$ apt-get upgrade
$ apt-get install python3 nginx supervisor # postgresql postgresql-contrib (si no se quiere sqlite)
$ apt-get install python-pip python3-pip
$ pip install virtualenvwrapper
$ pip install --upgrade pip
$ pip3 install --upgrade pip
$ adduser hektor
$ usermod -aG sudo hektor
$ su hektor
mkdir ~/.environments
nano ~/.bashrc
export WORKON_HOME=~/.environments
source /usr/local/bin/virtualenvwrapper.sh
source ~/.bashrc
mkvirtualenv hektorprofe --python=$(which python3)
workon hektorprofe
(hektorprofe) mkdir ~/hektorprofe.net
(hektorprofe) cd ~/hektorprofe.net
(hektorprofe) git clone https://github.com/hcosta/hektorprofe.net.git
(hektorprofe) pip install -r requirements.txt
(hektorprofe) python manage.py migrate
(hektorprofe) pip install gunicorn
(hektorprofe) gunicorn hektorprofe.wsgi:application --bind=127.0.0.1:8000
(hektorprofe) su root
$ touch /etc/supervisor/conf.d/hektorprofe.conf
$ nano /etc/supervisor/conf.d/hektorprofe.conf
[program:hektorprofe]
user = root
directory = /home/hektor/hektorprofe.net/hektorprofe
command = /home/hektor/.environments/hektorprofe/bin/python /home/hektor/.environments/hektorprofe/bin/gunicorn hektorprofe.wsgi:application
stdout_logfile = /home/hektor/hektorprofe.net/logs/gunicorn_supervisor.log
redirect_stderr = true
mkdir -p /home/hektor/hektorprofe.net/logs
$ supervisorctl reread
$ supervisorctl update
$ supervisorctl status hektorprofe
$ supervisorctl stop hektorprofe
$ supervisorctl restart hektorprofe
$ supervisorctl start hektorprofe
$ nano /etc/nginx/sites-available/hektorprofe.conf
server {
listen 80;
server_name hektorprofe.net; # <-- esta configuración redirecciona todo de hektorprofe.net a www.hektorprofe.net
return 301 https://www.hektorprofe.net$request_uri; # <-- tampoco hace falta redireccionar a https si no se usan certificados
}
server {
# cambiar por listen 80; si no se utilizan certificados SSL
listen 443 ssl;
server_name www.hektorprofe.net;
access_log /home/hektor/hektorprofe.net/logs/nginx.access.log;
error_log /home/hektor/hektorprofe.net/logs/nginx.error.log;
# Desactivar las siguientes tres líneas si no se utilizan certificados para https, más abajo explico cómo crearlos
ssl on;
ssl_certificate /etc/letsencrypt/live/hektorprofe.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/hektorprofe.net/privkey.pem;
location /static/ {
alias /home/hektor/hektorprofe.net/hektorprofe/static/;
}
location /media/ {
alias /home/hektor/hektorprofe.net/hektorprofe/media/;
}
location = /favicon.ico {
alias /home/hektor/hektorprofe.net/hektorprofe/static/favicon.ico;
}
location / {
proxy_pass http://127.0.0.1:8000; # <-- En este puerto se inicia Gunicorn por defecto
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
$ cd /etc/nginx/sites-enabled
$ sudo ln -s ../sites-available/hektorprofe.conf
$ service nginx restart
https://www.linode.com/docs/security/ssl/install-lets-encrypt-to-create-ssl-certificates/
$ git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
$ cd /opt/letsencrypt
$ service nginx stop
$ ./letsencrypt-auto certonly --standalone --renew-by-default -d hektorprofe.net -d www.hektorprofe.net -d static.hektorprofe.net
$ service nginx start
$ service nginx stop
$ cd /opt/letsencrypt
$ sudo -H ./letsencrypt-auto certonly --standalone --renew-by-default -d hektorprofe.net -d www.hektorprofe.net
$ service nginx start
- DEBUG = False
- ALLOWED_HOSTS = ['127.0.0.1', 'hektorprofe.net', 'www.hektorprofe.net']
- STATIC_ROOT = os.path.join(BASE_DIR, 'static') + python manage.py collectstatic
- SECURE_SSL_REDIRECT = False # <-- se hace a nivel de nginx, no lo queremos automático
$ supervisorctl restart hektorprofe # <-- Para Django
$ service nginx restart # <--- Para Nginx