分类 安全 下的文章

安装 firewalld

sudo apt update
sudo apt install firewalld

启动并启用 firewalld

sudo systemctl enable firewalld
sudo systemctl start firewalld

配置端口转发(将 8080 转发到 192.168.1.100:80)

sudo firewall-cmd --permanent --add-forward-port=port=8080:proto=tcp:toport=80:toaddr=192.168.1.100

或者使用更详细的规则

sudo firewall-cmd --permanent --add-rich-rule='rule family=ipv4 forward-port port=8080 protocol=tcp to-port=80 to-addr=192.168.1.100'

重新加载配置

sudo firewall-cmd --reload

查看当前规则

sudo firewall-cmd --list-all

为 localhost 生成私钥和自签名证书的最简单方法是使用以下 openssl 命令:

openssl req -x509 -out localhost.crt -keyout localhost.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name =
dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")

!/bin/bash

安装 certbot(如果你还没有安装)

sudo apt-get update
sudo apt-get install certbot python3-certbot-nginx -y # 对于基于 Debian/Ubuntu 的系统且使用 Nginx

或者对于 CentOS/RHEL 系统:

sudo yum install epel-release -y
sudo yum install certbot python3-certbot-nginx -y # 如果使用 Nginx

对于仅获取证书,不依赖特定 web 服务器插件:

sudo yum install certbot python3-certbot -y

申请证书

--agree-tos 表示同意 Let's Encrypt 的服务条款

-d 指定你的域名

--email 提供用于接收重要更新和续期通知的邮箱地址

sudo certbot certonly --agree-tos -m your@email.com -d example.com -d www.example.com

配置自动续期(Certbot 默认已经设置好了自动续期任务)

可以检查或手动运行以确保证书及时续期

sudo certbot renew --dry-run # 进行一次模拟续期操作来测试配置是否正确

现在你应该可以在 /etc/letsencrypt/live/example.com/ 目录下找到证书文件