使用certbot和nginx的Shell脚本使站点成为https

问题描述 投票:1回答:1

我知道如何使用命令行安装ssl证书。但是这次我需要一个shell脚本来执行此任务。

通常在手动执行此操作时,我首先执行以下操作:-

sudo apt-get install certbot python-certbot-nginx

通过执行上述操作,将要求我继续还是不继续?[是/否]。我将输入“ Y”。然后我将执行以下命令

sudo certbot --nginx

执行上述操作将要求我按顺序回答以下步骤:

  1. 输入电子邮件地址(用于紧急更新和安全通知)(输入'c'取消)。
  2. 条款与服务协议[(A)gree /(C)ancel:A]
  3. 同意将开发新闻和活动共享到我的电子邮件地址。 [(Y)es /(N)o:N]
  4. 我想为哪个名称激活HTTPS? [选择适当的数字,用逗号和/或空格隔开,或保留输入空白以选择显示的所有选项(输入'c'取消):空白]
  5. 从http重定向到https [选择适当的数字[1-2],然后[输入](按'c'取消):2]]

完成所有这些步骤后,将启用https。现在,我需要通过shell file以编程方式完成这些操作。我已经找到了使用此工具安装certbot和python-certbot-nginx的方法]

sudo apt-get install certbot python-certbot-nginx -y

但是我不知道如何进一步,因为我从未使用过shell脚本

PS:当我执行sudo certbot --nginx并自己输入详细信息时,我提供的是示例结果。

sudo certbot --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): mygmailid@gmail.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: example.com
2: www.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel):
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for example.com
http-01 challenge for www.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/demowebsite.conf
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/demowebsite.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/demowebsite.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/demowebsite.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled
https://example.com and
https://www.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=example.com
https://www.ssllabs.com/ssltest/analyze.html?d=www.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem
   Your cert will expire on 2020-01-28. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

我知道如何使用命令行安装ssl证书。但是我这次需要一个shell脚本来执行此任务。通常,在手动执行此操作时,我首先执行以下操作:-sudo apt-get ...

shell lets-encrypt certbot
1个回答
0
投票

虽然我在这里很晚,但最终我做到了如@JohnHanley在评论中所建议。我浏览了文档,这是通过命令行执行问题中上述步骤所需的内容。

热门问题
推荐问题
最新问题