I have a website running on a server that redirects all HTTP requests to HTTPS as shown below. I also have a few Django APIs that the server serves (let's say https://www.example.com/apis/log). I am running the Django implementation on Ubuntu + Nginx and have installed SSL certificate using Let's Encrypt.
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name xxx.xx.xx.xx example.com www.example.com;
listen 80;
return 404; # managed by Certbot
}
Now, I would like to do the following:
- Run the website in the present settings (all HTTP requests should redirect to HTTPS)
- Django APIs should work with both HTTP and HTTPS. Hence, I would like to have both http://www.example.com/apis/log and https://www.example.com/apis/log accessible.
nginxto serveapionHTTP