77
loading...
This website collects cookies to deliver better user experience
sudo apt-get update
sudo apt-get install nginx
sudo systemctl status nginx
sudo service nginx status
/etc/nginx/sites-available/
directory.cd /etc/nginx/sites-available/
sudo touch django.conf
sudo nano django.conf
Hint : We need to use sudo
here because this directory is present in root and not inside our home directory.
server {
server_name server_domain_or_ip;
location / {
include proxy_params;
proxy_pass http://localhost:8000;
}
}
server_domain_or_ip
you'll put either IP address or the domain of your website./etc/nginx/sites-available/
. But the active ones are present under /etc/nginx/sites-enabled/
sites-available
and then create a soft symlink to that file inside sites-enabled
/etc/nginx/sites-enabled/
.cd sites-enabled
sudo ln -s /etc/nginx/sites-available/django.conf .
sudo systemctl restart nginx
sudo service nginx restart
sudo apt-get update
sudo apt-get install software-properties
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot python3-certbot-nginx
sudo certbot --nginx
whitenoise
alternative we discussed earlier.settings.py
file, add the below line inside it:STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
STATIC_URL = "/static/"
staticfiles
by typing the following in your terminal:mkdir staticfiles
static
) as follows:STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
python manage.py collectstatic
cd /etc/nginx/sites-available/
sudo nano django.conf
server {
server_name server_domain_or_ip;
location / {
include proxy_params;
proxy_pass http://localhost:8000;
}
# Below part is to be added for static files
location /static/ {
alias /home/ubuntu/path/to/django/project/staticfiles/;
expires 365d;
autoindex off;
}
}
/home/ubuntu/path/to/django/project/
with the actual path where your project is stored.sudo systemctl restart nginx
sudo service nginx restart