SSH Access
https://spy-soft.net/generate-ssh-key-windows-10/
Add User
ssh root@your_server_ip
adduser user
usermod -aG sudo user
usermod -a -G user www-data
ssh sammy@your_server_ip
Update & Python Install
sudo apt update
sudo apt install python3-venv python3-dev
VENV
mkdir django
cd django/
python3 -m venv venv
source venv/bin/activate
Requirements
pip install -r requirements.txt
Static
STATIC_URL = 'static/'
if DEBUG:
STATICFILES_DIRS = (
BASE_DIR / 'static',
)
else:
STATIC_ROOT = BASE_DIR / 'static'
python3 manage.py collectstatic ( DEBUG = False)
python3 manage.py migrate
Allowed Host
ALLOWED_HOSTS = ['*'] (временно разрешаем все хосты)Test run
python3 manage.py runserver 0.0.0.0:8000
Gunicorn
pip install gunicorn
sudo nano /etc/systemd/system/gunicorn.socket
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
sudo nano /etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=vetrof
Group=www-data
WorkingDirectory=/home/vetrof/django
ExecStart=/home/vetrof/django/venv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
settigs-folder.wsgi:application
[Install]
WantedBy=multi-user.target
sudo nano /etc/hosts
127.0.0.1 localhost store-server
::1 localhost store-server ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
sudo systemctl start gunicorn.socket
sudo systemctl enable gunicorn.socket
test
sudo systemctl status gunicorn.socket
sudo systemctl status gunicorn
NGINX
sudo apt install nginx
sudo nano /etc/nginx/sites-available/django
server {
listen 80;
server_name 188.68.220.202;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/vetrof/django;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
sudo ln -s /etc/nginx/sites-available/django /etc/nginx/sites-enabled
sudo nginx -t
sudo systemctl restart nginx
MediaFiles
sudo nano /etc/nginx/sites-enabled/django
server {
listen 80;
server_name 188.68.220.202;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/vetrof/django;
}
location /media/ {
root /home/vetrof/django;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
Firewall UFW
sudo apt install ufw
sudo ufw app list
sudo ufw allow OpenSSH (разрешить ssh)
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status
Domain add
Заполняем у регистратора n1 n2 полученные у хостера
Dns checker
и проверяем синхронизацию серверов https://dnschecker.org/
sudo nano /etc/nginx/sites-available/django
server {
listen 80;
server_name yogangie.ru;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/vetrof/django;
}
location / {
sudo systemctl restart nginx
sudo nginx -t
sudo systemctl restart gunicorn / status
sudo systemctl restart nginx / status
SSL
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx -d you_site(без www)
nano /etc/nginx/sites-enabled/django - проверка
RESTART Gunicorn & Nginx
sudo systemctl restart gunicorn
sudo systemctl restart nginx
ALLOWED_HOSTS = env.list('ALLOWED_HOSTS')
ALLOWED_HOSTS=127.0.0.1,localhost,188.68.220.202