Certbot redirect flag leaves the nginx rules commented

Hi,

I’m using certbot-auto to create auto SSL but for some reason the --redirect flag leaves the Nginx rules commented out.

Here is my log

sudo /opt/letsencrypt/certbot-auto --debug --email admin@example.com --no-eff-email --agree-tos -n --nginx --keep -d mysite.com
Plugins selected: Authenticator nginx, Installer nginx
Cert not yet due for renewal
Keeping the existing certificate
Deployed Certificate to VirtualHost /etc/nginx/sites-enabled/mysite_com.conf for set(['mysite.com'])
The appropriate server block is already redirecting traffic. To enable redirect anyway, uncomment the redirect lines in /etc/nginx/sites-enabled/mysite_com.conf.

Then the mysite_com.conf will include

# Redirect non-https traffic to https
# if ($scheme != "https") {
#     return 301 https://$host$request_uri;
# } # managed by Certbot

For some reason it i s commented and I am not sure why. Any idea how to automate this without having to apply any string replacement?

Thanks

@erica, do you know the reason for this behavior?

Yes, as the error message says:

Your server block already has a rewrite or redirect in it, and we don't want to mess up your configuration. If you want Certbot to configure it automatically, you can remove your preexisting redirect; otherwise, you'll have to uncomment the lines we add manually.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.