Hi im having trouble with my first Django site and not sure what im doing wrong.
I basically want to redirect http:// www. example.com and http:// example.com and https:// www. example.com all to > https://example.com
The redirect from http:// example.com seems to work.
This is what my conf file looks like.
server {
#listen 80 default_server;
#listen [::]:80 default_server ipv6only=on;
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 4G;
server_name _;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/django/django_project/django_project/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/django/django_project/django_project/static;
}
# Proxy the static assests for the Django Admin panel
location /static/admin {
alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
server {
listen 80;
server_name www.example.com;
return 301 $scheme://$host$request_uri;
}
server {
listen 80;
server_name example.com;
return 301 $scheme://$host$request_uri;
}
server {
listen [::]:443 ssl;
listen 443 ssl;
server_name www.example.com;
return 301 $scheme://$host$request_uri;
}
What am i doing wrong?
The answer from Richard has solved my problem.