linux下c语言http服务器 https_IPV6下NAS的Linux防火墙配置+HTTPS反向代理配置

  • 系统:Openmediavault5(OMV5)/Debian10

防火墙配置

UFW是为了轻量化配置iptables 而开发的一款工具

安装UFW防火墙

sudo apt install ufw

启用UFW防火墙

sudo ufw enable

添加SSH,Samba, NFS,http, https协议进白名单

sudo ufw allow ssh
sudo ufw allow samba
sudo ufw allow nfs
sudo ufw allow http
sudo ufw allow https

如果要开放特定端口

sudo ufw allow 8888/tcp #开放TCP协议
sudo ufw allow 8888/udp #开放UDP协议

拒绝白名单以外的端口监听

sudo ufw default deny

检查以标题为单位的防火墙规则

sudo ufw status numberd

输出如下

状态: 激活

     至                          动作          来自
     -                          --          --
[ 1] 22/tcp                     ALLOW IN    Anywhere
[ 2] Samba                      ALLOW IN    Anywhere
[ 3] 2049                       ALLOW IN    Anywhere
[ 4] 443/tcp                    ALLOW IN    Anywhere
[ 5] 80/tcp                     ALLOW IN    Anywhere
[ 6] 22/tcp (v6)                ALLOW IN    Anywhere (v6)
[ 7] 3333/tcp (v6)              ALLOW IN    Anywhere (v6)
[ 8] Samba (v6)                 ALLOW IN    Anywhere (v6)
[ 9] 2049 (v6)                  ALLOW IN    Anywhere (v6)
[10] 443/tcp (v6)               ALLOW IN    Anywhere (v6)
[11] 80/tcp (v6)                ALLOW IN    Anywhere (v6)

检查含有v6的的Samba,NFS规则(禁止不适合局域网以外的协议)

禁用Samba,NFS(2049端口)的IPV6连接

sudo ufw delete 行数

记得每禁止完一条重新查看规则的序号

禁止被ping命令

iptables -A INPUT -p icmp --icmp-type8 -s 0/0 -j DROP

Let's Encrypt 免费SSL证书申请

确保AAAA/A记录正确解析到服务器

安装certbot, nginx相关软件包

sudo apt install certbot letsencrypt python-certbot-nginx nginx
systemctl start nginx

检查nginx是否正常运行,如果开启了防火墙请放行http https端口

526abfbb8c8f0d1f99a7e67357f66989.png

新建文件夹和站点配置文件

mkdir /usr/share/nginx/.well-known/acme-challenge -p
nano /etc/nginx/sites-enabled/域名.conf

域名.conf输入以下内容

server {
        server_name 域名;
        listen [::]:80;
        location ~ /.well-known {
                allow all;
        }
}

生成证书

certbot -d 域名 --nginx

输入邮箱,一路同意

1a0fdeb4db341f3e09b1845a02927aec.png

下图这一步输入2回车,开启http重定向至https

98413349b8a57e94f4d9ad96452389a6.png

成功截图如下

b447e7939e38cf1cb6e3821fe8eb8061.png

申请证书过程中可能有如下错误

17af2e35cc933340fa2c4cec0aee2bbb.png

等待几分钟再执行生成证书命令即可成功

用浏览器访问域名看有无安全提示(无),是否出现小锁图标(是)

ba8714eb687d6d306db5e5f42b1b72ce.png

看到这张图表示配置成功


反向代理站点设置

现在jellyfin http监听8096端口,要用nginx反向代理访问

91db5fc5a977b15fcaffd7681fd26221.png

编辑站点文件

nano /etc/nginx/sites-enabled/域名.conf

看到下列内容

295aeaea792d4912afeda7f87b0d7427.png

在listen [::]:443 ssl;上插入以下内容

#   Jellyfin反向代理
location / {
    proxy_pass http://localhost:8096;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto $remote_addr;
    proxy_set_header X-Forwarded-Protocol $scheme;
}

保存退出,重启nginx

systemctl restart nginx

UFW阻断8096端口外部连接

sudo ufw deny 8096/tcp

浏览器通过域名访问jellyfin

2c3eb3aeb643ac2a45e75aea60976b82.png

进入过程无任何安全提示

看到小锁即为成功!

证书有效期为3个月,到期需要执行以下命令更新证书

certbot renew
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值