Skip to content

Instantly share code, notes, and snippets.

@zaemiel
Last active March 6, 2023 23:57
Show Gist options
  • Save zaemiel/edfc6c176b2c9d210e3ebe02caa76834 to your computer and use it in GitHub Desktop.
Save zaemiel/edfc6c176b2c9d210e3ebe02caa76834 to your computer and use it in GitHub Desktop.
Gist to Django Vue.js deploy to remote server video
1. To get IP address:
ip addr
2. To connect via SSH:
ssh username@ip_addr
3. Update system:
sudo apt update && sudo apt upgrade -y
4. Install this packages:
sudo apt install python3-pip python3-dev python3-venv libpq-dev postgresql postgresql-contrib nginx supervisor
5. Configure PosgtreSQL database:
sudo -u postgres psql
- Create a postgresql database...
CREATE DATABASE test_db;
\l - to list databases
- Create a Postgres user:
CREATE USER django_user WITH PASSWORD '1234';
- Change user's encoding to UTF8:
ALTER ROLE django_user SET client_encoding TO 'utf8';
- Set the isolation level:
ALTER ROLE django_user SET default_transaction_isolation TO 'read committed';
- set permissions:
GRANT ALL PRIVILEGES ON DATABASE test_db TO django_user;
\q - to quit
6. In settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'test_db',
'USER': 'django_user',
'PASSWORD': '1234',
'HOST': '127.0.0.1',
'PORT': '5432'
}
}
7. Apply migrations
python manage.py migrate
8. Install uvicorn
pip install uvicorn
9. Start uvicorn
python -m uvicorn djv.asgi:application --uds /tmp/uvicorn.sock
10. Configure the Supervisor
/etc/supervisor/supervisord.conf
[program:django]
command = /home/django/djv/venv/bin/python3 -m uvicorn djangovue_pr.asgi:application --uds /tmp/uvicorn.sock
directory = /home/django/djv/backend/
stderr_logfile=/var/log/long.err.log
stdout_loffile=/var/log/long.out.log
autostart=true
autorestart=true
11. Restart Supervisor:
sudo service supervisor restart
12. Look at logs:
tail /var/log/long.err.log
13. Nginx configuration
- copy the default config:
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-availables/default-backup
- sudo vim /etc/nginx/sites-available/default
server {
listen 80;
server_name 192.168.1.156;
charset utf-8;
client_max_body_size 10M;
location /static {
alias /home/django/djangovue-deploy-example/backend/staticfiles;
}
location /media {
alias /home/django/djangovue-deploy-example/backend/media;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://uvicorn;
}
}
upstream uvicorn {
server unix:/tmp/uvicorn.sock;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment