哪吒探针配置https访问

By | 2024-02-29

概要

  1. 部署哪吒探针
  2. 下载nginx,配置nginx反代
  3. 申请证书,安装证书

申请SSL证书

这里使用acme.sh申请a.com的SSL证书,Webroot模式

原理是acme.sh会在网站对应域名的webroot目录下生成域名验证文件,然后通过公网访问之,以验证对域名的所有权

证书生成以后,接下来需要把证书安装到真正需要用它的地方。acme.sh默认生成的证书都放在安装目录下:~/.acme.sh/ ,但是官方不推荐直接使用该目录下的证书文件,仅供 acme.sh 内部使用。

正确的使用方法是使用 –installcert 命令,并指定目标位置, 然后证书文件会被复制到相应的位置。

  1. 面板机上安装acme.sh

    curl https://get.acme.sh | sh -s email=my@example.com
    

    切换CA机构

    acme.sh --set-default-ca --server letsencrypt
    
  2. 申请证书,按实际情况修改面板域名

    acme.sh --issue -d a.com -k ec-256 --webroot /var/www/html
    
  3. 安装证书,按实际情况修改面板域名和证书路径

    acme.sh --install-cert -d a.com --ecc --key-file /etc/nezha/server.key --fullchain-file /etc/nezha/server.crt --reloadcmd "systemctl force-reload nginx"
    

acme命令

  1. 查看目前申请的证书
~/.acme.sh/acme.sh --list
  1. 撤销目前申请的证书
~/.acme.sh/acme.sh --revoke -d "域名" --ecc
~/.acme.sh/acme.sh --remove -d "域名" --ecc
  1. 手动续期证书
~/.acme.sh/acme.sh --renew -d "域名" --force --ecc
  1. 卸载Acme.sh脚本
~/.acme.sh/acme.sh --uninstall
  1. 更新 Acme 脚本

升级 Acme.sh 到最新版本

~/.acme.sh/acme.sh --upgrade

如果你不想手动升级,可以开启自动升级:

~/.acme.sh/acme.sh --upgrade --auto-upgrade

之后,acme.sh 就会自动保持更新了。

配置Nginx反代

将面板机的8008端口反代到https://a.com

  1. 安装nginx

    apt-get install nginx
    systemctl status nginx
    cd /etc/nginx
    
  2. nginx配置

    user www-data;
    worker_processes auto;
    pid /run/nginx.pid;
    include /etc/nginx/modules-enabled/*.conf;
    
    events {
        worker_connections 1024;
    }
    
    http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
    
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        gzip on;
    
        access_log /root/nginx.log;
    
        server {
            listen 443 ssl http2;
            listen [::]:443 ssl http2;
            server_name a.com; 
    
            ssl_certificate          /etc/nezha/server.crt; # 你的域名证书路径
            ssl_certificate_key      /etc/nezha/server.key; # 你的域名私钥路径
    
            underscores_in_headers on;
    
            location / {
                proxy_pass http://127.0.0.1:8008;
                proxy_set_header Host $http_host;
                proxy_set_header      Upgrade $http_upgrade;
            }
            location ~ ^/(ws|terminal/.+)$  {
                proxy_pass http://127.0.0.1:8008;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "Upgrade";
                proxy_set_header Host $http_host;
            }
        }
    
        server {
            listen 80;
            location /.well-known/ {
                   root /var/www/html;
                }
            location / {
                    rewrite ^(.*)$ https://$host$1 permanent;
                }
        }
    }
    

打开warp后绑定的域名无法https访问,解决办法

套 CloudFlare 后提示“重定向的次数过多”,需要将SSL/TLS 设置,改为 完全(Full) 或 完全严格Full (strict) 模式

修改 您的 SSL/TLS 加密模式为 完全(严格)

参考

使用acme.sh免费申请HTTPS证书 | HelloDog (wsgzao.github.io)

手动使用Acme.sh证书脚本申请SSL证书 | MisakaNo の 小破站

使用 acme.sh 为网站生成永久免费证书 | Server 运维论坛 (learnku.com)

手把手教你安装哪吒探针 (nodeseek.com)