搜索
搜索
天涯的知库
显示页面
过去修订
您的足迹:
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
====== 服务器安全设置 ====== 主要运用 ubuntu 自带的防火墙工具 UFW 进行设定。(([[https://www.myfreax.com/how-to-setup-a-firewall-with-ufw-on-ubuntu-18-04/|Ubuntu 18.04上使用UFW设置防火墙]])) (([[https://kalasearch.cn/community/tutorials/ufw-essentials-common-firewall-rules-and-commands/|UFW 通用防火墙规则和命令 ]])) (([[https://www.digitalocean.com/community/tutorials/how-to-setup-a-firewall-with-ufw-on-an-ubuntu-and-debian-cloud-server|How To Setup a Firewall with UFW on an Ubuntu and Debian Cloud Server]])) 也可以利用 iptables 白名单的方式进行保护。(([[https://www.cnblogs.com/eugene0/p/12056901.html|Ubuntu 16.04 设置防火墙白名单]])) UFW 使用比较简单,因此首先考虑使用这种方式。 安装 ''sudo apt install ufw'' \\ 检查状态 ''sudo ufw status verbose'' \\ 列举可用的配置文件 ''sudo ufw app list'' \\ 查看 Nginx 使用了哪些端口 <color #7092be>sudo ufw app info 'Nginx Full'</color> \\ 允许ssh ''<color #7092be>sudo ufw allow ssh</color>'' (<color #ed1c24>很重要,否则连不上服务器了</color>)\\ 启动UFW服务 ''sudo ufw enable'' \\ 停用服务 ''sudo ufw disable'' \\ 重置设定 ''sudo ufw reset'' \\ 列举现有的规则 ''sudo ufw status numbered'' \\ 删除3号规则 ''sudo ufw delete 3''\\ 限制端口22访问 <color #ff7f27>''%%sudo ufw limit 22%%''</color> 防止黑客对其进行攻击 <code bash> sudo ufw allow http sudo ufw allow 80/tcp sudo ufw allow 'Nginx HTTP' sudo ufw allow https sudo ufw allow 443/tcp sudo ufw allow 'Nginx HTTPS' sudo ufw allow 7100:7200/tcp # 允许特点端口 sudo ufw allow 7100:7200/udp sudo ufw allow from 64.63.62.61 # 允许白名单 sudo ufw allow from 64.63.62.61 to any port 22 # 只允许64.63.62.61的主机访问端口22 sudo ufw allow from 192.168.0.100/200 to any port 873 sudo ufw allow from 192.168.0.0/24 to any port 22 # 允许整个子网访问 sudo ufw deny from 23.24.25.0/24 # 拒绝黑名单 sudo ufw default deny incoming # 拒绝所有访问,除非指定 sudo ufw default allow outgoing # 允许数据出去 </code> [[https://ipcmen.com/iptables|iptables 详细用法]] - 启动/关闭 <color #ff7f27>''%%service iptables start%%''</color> (stop) - 删除 <color #ff7f27>''%%apt-get purge netfilter-persistent%%''</color> && reboot - 强制删除 <color #ff7f27>''%%rm -rf /etc/iptables && reboot%%''</color> [[https://cloud.tencent.com/developer/article/1334624|常用命令]] <code> sudo iptables -P INPUT ACCEPT sudo iptables -P OUTPUT ACCEPT sudo iptables -P FORWARD ACCEPT sudo iptables -F // 清除所有的已订定的规则 sudo iptables -X sudo iptables -Z </code> ====== ACME 证书 ====== ++++ 不再使用的方法 | [[https://wsgzao.github.io/post/acme/|ACME 证书申请讲解]] <code bash> apt install -y socat curl https://get.acme.sh | sh // ~/.acme.sh/ // 安装到自己目录下 </code> 直接在Termial创建一个别名,可以方便使用 <color #ff7f27>''%%alias acme.sh=~/.acme.sh/acme.sh%%''</color> 注册证书 <code bash> ~/.acme.sh/acme.sh --register-account -m goldentianya@gmail.com // 开通 80 和 443 端口,否则无法监听 // 如果一直不通就加上参数 --server letsencrypt ~/.acme.sh/acme.sh --issue -d simperator.top --standalone </code> 安装完成后会自动更新证书,查看crontab 会发现这条命令\\ <wrap lo>root@serverpi:~# crontab -l \\ 40 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null</wrap> 拷贝证书到指定地点 <code bash> ~/.acme.sh/acme.sh --installcert -d simperator.top --key-file /root/ssl-keys/private.key --fullchain-file /root/ssl-keys/cert.crt </code> <wrap em>没有通配证书,simperator.top 和 ionos.simperator.top 要分别申请。</wrap> **为 nginx 配置证书** 以域名 ionos.simperator.top 为例 1. 申请证书 <color #ff7f27>''%%acme.sh --issue -d ionos.simperator.top --nginx%%''</color> 2. 创建文件夹 <color #ff7f27>''%%mkdir -p /etc/nginx/ssl/ionos.simperator.top%%''</color> 3. 拷贝证书 <code bash> ~/.acme.sh/acme.sh --install-cert -d ionos.simperator.top \ --key-file /etc/nginx/ssl/ionos.simperator.top/key.pem \ --fullchain-file /etc/nginx/ssl/ionos.simperator.top/cert.pem \ --reloadcmd "service nginx force-reload" </code> 4 配置 conf 文件 <code> ssl_certificate "/etc/nginx/ssl/ionos.simperator.top/cert.pem"; ssl_certificate_key "/etc/nginx/ssl/ionos.simperator.top/key.pem"; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; </code> ++++ 查看证书 <wrap em>acme.sh list</wrap> 有效日期, [[https://github.com/acmesh-official/acme.sh|acme.sh Github项目]] <WRAP left round important 60%> cloudflare 现在已经不支持通过API设置.cf, .ga, .gq, .ml, 或.tk域名的DNS记录,在acme.sh设置TXT记录时会出错。只能单个证书申请。 </WRAP> freenom 的域名以后用CF的源服务器证书就好,10年有效。但 CF 自己的证书不被其它地方认证,无法在后台订阅服务中使用。网站的后台服务如果需要ssl证书,就使用 .com 或者 .eu.org 域名,使用 acme.sh ecc 签署。 ===== cloudflare ===== 托管在 cloudflare 上的域名参考 [[https://blog.augustdoit.men/acme/|用 acme.sh 脚本申请 SSL 证书并自动更新]] 定时任务更新证书,并重新加载 nginx <code> 0 3 15 */2 * acme.sh --installcert -d simperator.com --fullchain-file /root/ssl-keys/fullchain.pem --key-file /root/ssl-keys/private.key --ecc && /etc/init.d/nginx reload </code> 自动更新 <color #ff7f27>''%%acme.sh --upgrade --auto-upgrade%%''</color> 其实可以使用 cloudflare 的源服务器证书。需要开启 - 完全加密 - 始终使用 HTTPS - 打开小黄朵 - 配置通配的边缘证书 <WRAP center round tip 100%> 您的域/子域在 Cloudflare 的网络上未处于活动状态 Cloudflare 的 SSL 仅在您验证了根或 www DNS 记录的 SSL 证书后,才会向您网站的访问者显示,方法是在仪表板中将这些记录涂成橙色。如果 DNS 记录是灰色的,则 Cloudflare 颁发的 SSL 证书将不存在。 </WRAP> {{tag>vps ubuntu acme}}
it/server/security.txt
· 最后更改: 2023-08-08 15:55 由
goldentianya
回到顶部