gpt4 book ai didi

使用 certbot 和 nginx 制作站点 https 的 Shell 脚本

转载 作者:行者123 更新时间:2023-12-04 00:02:20 24 4
gpt4 key购买 nike

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

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

sudo apt-get install certbot python-certbot-nginx

通过执行上述操作,我将被要求继续与否?[Y/n]。我将输入'Y'。然后我将执行以下命令
sudo certbot --nginx

执行上述操作将要求我按顺序回答以下步骤:
  • 输入电子邮件地址(用于紧急续订和安全通知)(输入“c”取消)。
  • 条款和服务协议(protocol) [(A)gree/(C)ancel: A ]
  • 同意将开发新闻和事件分享到我的电子邮件地址。 [(Y)es/(N)o: N]
  • 我想为哪些名称激活 HTTPS? [选择用逗号和/或空格分隔的适当数字,或留下输入
    空白选择所有显示的选项(输入'c'取消):空白]
  • 从 http 重定向到 https [选择适当的数字 [1-2] 然后 [enter](按 'c' 取消):2 ]

  • 完成所有这些步骤后,将启用 https。现在我需要通过 shell 文件以编程方式完成这些事情。我已经想出使用这个来安装 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

    最佳答案

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

    run            Obtain & install a certificate in your current webserver

    -n Run without ever asking for user input. This may
    require additional command line flags; the client will
    try to explain which ones are required if it finds one
    missing (default: False)

    --nginx Obtain and install certificates using Nginx (default:False)


    -d Domain names to apply. For multiple domains you can
    use multiple -d flags or enter a comma separated list
    of domains as a parameter. The first domain provided
    will be the subject CN of the certificate, and all
    domains will be Subject Alternative Names on the
    certificate. The first domain will also be used in
    some software user interfaces and as the file paths
    for the certificate and related material unless
    otherwise specified or you already have a certificate
    with the same name. In the case of a name collision it
    will append a number like 0001 to the file path name.


    -m Email used for registration and recovery contact. Use
    comma to register multiple emails, ex:
    u1@example.com,u2@example.com. (default: Ask).

    --redirect Automatically redirect all HTTP traffic to HTTPS for
    the newly authenticated vhost. (default: Ask)

    --agree-tos Agree to the ACME server's Subscriber Agreement

    所以我执行的最终命令低于
    certbot run -n --nginx --agree-tos -d example.com,www.example.com -m mygmailid@gmail.com --redirect

    关于使用 certbot 和 nginx 制作站点 https 的 Shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58626546/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com