Удалите example.com
в server_name
второго блока и добавьте listen 443
во второй блок.
Надеюсь, это поможет.
server {
listen 80;
listen 443; # add this line
server_name example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 80;
listen 443; # add this line too.
root /var/www/html;
index index.php;
# Remove example.com
server_name www.example.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}