Setup of icons, sitemap and robots -files with Django


Icons
The usual expected sizes of the favicon.ico -file are 16x16 or 32x32. The apple-touch-icon.png and the apple-touch-icon-precomposed.png sizes are 180x180. You should have the files

favicon.ico
favicon.png (new browsers support png)
apple-touch-icon.png
apple-touch-icon-precomposed.png

Create these files with some drawing editor and locate them to the /../Project/static_main -folder. On the terminal server type the command

python manage.py collectstatic

Add lines

<link rel="icon" href="/static/favicon.ico" />
<link rel="apple-touch-icon" href="/static/apple-touch-icon.png"/>
<link rel="apple-touch-icon-precomposed" href="/static/apple-touch-icon-precomposed.png"/>

inside the header < head> ... < /head> of the html-page.

Edit your mysite_nginx.conf file

upstream mysite {
   server unix:///tmp/mysite.sock;
}

server {
   server_name mlconvex.dev www.mlconvex.dev;
   listen 80;
   return 301 https://mlconvex.dev;
}
server {
   server_name mlconvex.dev www.mlconvex.dev;
   listen 443 ssl;
   charset utf-8;
   ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
   ssl_certificate /etc/ssl/mlconvexdev_cert_chain.crt;
   ssl_certificate_key /etc/ssl/mlconvexdev.key;
   client_max_body_size 4G;
   access_log /dev/null;
   error_log /dev/null;
   location /media {
      alias /../Project/media;
   }
   location /static {
      alias /../Project/static;
   }
   location /favicon.ico {
      alias /../Project/static/favicon.ico;
   }
   location /apple-touch-icon.png {
      alias /../Project/static/apple-touch-icon.png;
   }
   location /apple-touch-icon-precomposed.png {
      alias /../Project/static/apple-touch-icon-precomposed.png;
   }
   location / {
      include /../Project/uwsgi_params;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto https;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      uwsgi_pass mysite;
   }
}

Restart Django and Nginx and the icons should be now available.

Sitemap
Create a sitemap. Example of a sitemap.xml file is

<?xml version="1.0" encoding="UTF-8"?>
<urlset
   xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
    http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
  <loc>https://mlconvex.dev/</loc>
  <lastmod>2019-06-28</lastmod>
  <changefreq>weekly</changefreq>
  <priority>1.00</priority>
</url>
</urlset>

Locate the file to the /../Project/static_main -folder. On the terminal server type the command

python manage.py collectstatic

Add lines

   location /sitemap.xml {
      alias /../Project/static/sitemap.xml;
   }

to your mysite_nginx.conf file. Restart Django and Nginx.

Robots file
Create a robots.txt file. An example of the file is

Sitemap: https://mlconvex.dev/sitemap.xml
User-agent:*
Disallow:

Locate the file to the /../Project/static_main -folder. On the terminal server type the command

python manage.py collectstatic

Add lines

   location /robots.txt {
      alias /../Project/static/robots.txt;
   }

to your mysite_nginx.conf file. Restart Django and Nginx.


Return to the Mac main page.