【Lightsail】AWS Lightsail for Nginx虚拟机生成letsencrypt证书

本文详细指导如何在AWSLightsail的Debian10虚拟机上安装Snapd,使用certbot获取和管理Nginx的SSL证书,以及设置自动续订功能。包括安装步骤和配置示例。
摘要由CSDN通过智能技术生成

AWS Lightsail for Nginx虚拟机生成letsencrypt证书(Debian 10)

1.ssh到Debian虚拟机

2.install snapd

sudo apt update
sudo apt install snapd
sudo snap install core

参考连接:https://snapcraft.io/docs/installing-snapd

3.删除 certbot-auto 和任何 Certbot OS 软件包

sudo apt-get remove certbot
#或
sudo dnf remove certbot
#或
sudo yum remove certbot

4.安装certbot

sudo snap install --classic certbot

5.准备 Certbot 命令

sudo ln -s /snap/bin/certbot /usr/bin/certbot

6.运行certbot

#运行此命令来获取证书,并让 Certbot 自动编辑您的 nginx 配置来为其提供服务,一步即可打开 HTTPS 访问。
sudo certbot --nginx
#如果您感觉更保守并且想手动更改 nginx 配置,请运行此命令。
sudo certbot certonly --nginx

注意:这一步要stop nginx

7.测试自动续订

sudo certbot renew --dry-run

8.查看证书主体命令

sudo openssl x509 -in certificate.pem -noout -subject
#或
sudo openssl x509 -in certificate.pem -noout -text

9./opt/bitnami/nginx/conf/server_blocks下创建一个***.conf文件

server{
    # Port to listen on, can also be set in IP:PORT format
    listen 80;
    server_name ****.com www.****.com;
    ssl_certificate      bitnami/certs/fullchain.pem;
    ssl_certificate_key  bitnami/certs/privkey.pem;
    keepalive_timeout 65;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;
    client_max_body_size 80M;
    listen 443 ssl;

   location /{
      proxy_pass http://127.0.0.1:8080;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
   }
}

参考连接:https://certbot.eff.org/instructions?ws=nginx&os=debianbuster

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在 AWS EC2 实例中使用 Terraform 部署 Nginx 的步骤: 1. 在 AWS 控制台中创建一个 IAM 用户,并为该用户授权 AWS 访问密钥和安全凭证。 2. 安装 Terraform,并配置 AWS 访问密钥和安全凭证: ``` $ terraform init $ export AWS_ACCESS_KEY_ID="your_access_key_here" $ export AWS_SECRET_ACCESS_KEY="your_secret_key_here" ``` 3. 创建一个 Terraform 项目,并在 main.tf 文件中定义以下资源: ``` provider "aws" { region = "us-west-2" } resource "aws_instance" "nginx" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro" tags = { Name = "nginx-server" } provisioner "remote-exec" { inline = [ "sudo apt-get update", "sudo apt-get install -y nginx", ] } connection { type = "ssh" user = "ubuntu" private_key = file("~/.ssh/id_rsa") host = aws_instance.nginx.public_ip } lifecycle { create_before_destroy = true } # Allow HTTP traffic ingress { from_port = 80 to_port = 80 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } # Allow SSH traffic ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } # Allow HTTPS traffic ingress { from_port = 443 to_port = 443 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } # Allow ICMP traffic ingress { from_port = -1 to_port = -1 protocol = "icmp" cidr_blocks = ["0.0.0.0/0"] } } ``` 上述代码中定义了一个 AWS EC2 实例和一些安全组规则,以允许 HTTP、SSH、HTTPS 和 ICMP 流量通过。还在 provisioner 部分中安装了 Nginx。 4. 运行 Terraform 命令创建实例: ``` $ terraform apply ``` 5. 在浏览器中输入实例 IP 地址,应该可以看到 Nginx 的欢迎页面。 现在,您已经成功在 AWS EC2 实例中部署了 Nginx,而且使用 Terraform 进行自动化管理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值