sudo apt update && apt upgrade -y
sudo apt install python3-pip python3-dev ufw nginx
create a user and give him sudo permission
ssh into server as a user
sudo apt install python3-pip python3-dev nginx
sudo pip3 install virtualenv
git clone https://github.com/dev-rathankumar/fashion-pvt-04.git .
sudo apt-get install postgresql postgresql-contrib
sudo systemctl start postgresql.service
sudo systemctl enable postgresql.service
sudo systemctl status postgresql.service
psql -d postgres -c "ALTER USER postgres WITH PASSWORD 'Linode@2021';"
CREATE DATABASE fashion_db;
sudo nano .env ### add the environment variables with postgres db name and password
sudo nano fashion_main/settings.py ### add IP address in allowed host
pip install -r requirements.txt
python manage.py createsuperuser
python manage.py runserver 0.0.0.0:8000
sudo apt install gunicorn
gunicorn --bind 0.0.0.0:8000 fashion_main.wsgi
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=altocan
Group=www-data
WorkingDirectory=/home/altocan/fashiondir
ExecStart=/home/altocan/fashiondir/env/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
fashion_main.wsgi:application
[Install]
WantedBy=multi-user.target
sudo systemctl start gunicorn.socket
sudo systemctl enable gunicorn.socket
Configuring Nginx as a reverse proxy
sudo nano /etc/nginx/sites-available/fashion_main
server {
listen 80;
server_name altocanp1.website;
location ~ ^/\.well-known {
root /home/altocan/fashiondir;
allow all;
}
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/altocan/fashiondir;
}
location /media/ {
root /home/altocan/fashiondir;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
sudo ln -s /etc/nginx/sites-available/fashion_main /etc/nginx/sites-enabled/
cd /etc/nginx/sites-enabled/
sudo rm default
increase file upload size to avoid 413 errors
sudo nano /etc/nginx/nginx.conf
# add this line
client_max_body_size 100M;
sudo ufw allow 80
sudo ufw allow 'Nginx Full'
sudo ufw allow 586
sudo ufw deny 8000
sudo nano fashiondir/fashion_main/settings.py
# Add the domain name into allowed host
sudo systemctl restart nginx
sudo systemctl restart gunicorn