I have a website built (in plain HTML) using letsencrypt certificates. The Nginx config is redirecting traffic from http to https. I submitted this website to Google's Search Console, and they are sending me emails that "Page with redirect" issue detected and "must remove to enable the best experience" (?).
This is my nginx configuration.
server {
root /var/www/example/html;
index index.html index.htm index.nginx-debian.html;
server_name example.gr www.example.gr;
location / {
try_files $uri $uri/ =404;
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.gr-0001/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.gr-0001/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
listen 80;
listen [::]:80;
server_name example.gr;
if ($host = example.gr) {
return 301 https://$host$request_uri; # <-- this line might be causing the issue
} # managed by Certbot
return 404; # managed by Certbot
}
What am I doing wrong?