I was trying to Secure Nginx with Let's Encrypt on Ubuntu 16.04.
mydomain.conf file before obtaining an SSL Certificate
server {
server_name mydomain.com www.mydomian.com ;
# Tell Nginx and Passenger where your app's 'public' directory is
root /var/www/backup/mycode/public;
# Turn on Passenger
passenger_enabled on;
rails_env development;
passenger_ruby /usr/local/rvm/gems/ruby-2.5.6/wrappers/ruby;
}
http://mydomain.com/ is working fine.
I try to Obtain an SSL Certificate by
sudo certbot --nginx -d mydomain.com -d www.mydomain.com
the result was
Your existing certificate has been successfully renewed, and the new certificate
has been installed.
The new certificate covers the following domains: https://mydomain.com and
https://www.mydomain.com
mydomain.conf file after obtaining an SSL Certificate
server {
server_name mydomain.com www.mydomain.com ;
# Tell Nginx and Passenger where your app's 'public' directory is
root /var/www/backup/mydomain.com/public;
# Turn on Passenger
passenger_enabled on;
rails_env development;
passenger_ruby /usr/local/rvm/gems/ruby-2.5.6/wrappers/ruby;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/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 {
if ($host = www.mydomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = mydomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name mydomain.com www.mydomain.com ;
listen 80;
return 404; # managed by Certbot
}
http://mydomain.com/ is redirecting to https://mydomain.com/ too many times
mydomain.com redirected you too many times.
ERR_TOO_MANY_REDIRECTS
Why is it redirecting too many times?
what is the purpose of the second server block?
server { if ($host = www.mydomain.com) { return 301 https://$host$request_uri; } # managed by Certbot if ($host = mydomain.com) { return 301 https://$host$request_uri; } # managed by Certbot server_name mydomain.com www.mydomain.com ; listen 80; return 404; # managed by Certbot }
- How to make all redirects to https://www.mydomain.com/ ?