How to make NGINX redirect from http to https?
Solution 1:
The problem is that you have configured two server blocks listening for SSL on the same port with the same server name and there's no way for nginx to decide which one to choose in these conditions. Change it to :
server {
listen 80 default_server;
listen 443 ssl default_server;
server_name _;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
return 302 https://sub.domain.co.uk$request_uri;
}
server {
listen 443;
server_name sub.domain.co.uk;
location / {
root /home/saves/webapps/html/;
index index.html;
}
location /api/ {
[...]
}
}