LocalTunnel 服务器设置文档

发布: (2025年12月5日 GMT+8 08:44)
2 min read
原文: Dev.to

Source: Dev.to

Cover image for LocalTunnel Server Setup Documentation

1. 文件

1.1 docker-compose.yml

version: "3.8"

services:
  lt-server:
    image: defunctzombie/localtunnel-server:latest
    container_name: lt-server
    restart: always
    ports:
      - "3000:3000"
    networks:
      - localtunnel-net
    command: bin/server --port 3000 --host 0.0.0.0

  localtunnel-nginx:
    image: nginx:latest
    container_name: localtunnel-nginx
    depends_on:
      - lt-server
    restart: always
    ports:
      - "8081:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./site.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - localtunnel-net

networks:
  localtunnel-net:
    driver: bridge

1.2 nginx.conf

events {
    worker_connections 1024;
}

http {
    include /etc/nginx/conf.d/*.conf;
}

1.3 site.conf

server {
    listen 80;

    location / {
        proxy_pass http://lt-server:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

1.4 运行 LocalTunnel 客户端命令

nohup npx localtunnel --port 3000 --host http://34.68.37.115:8081 > tunnel.log 2>&1 &
  • 该命令将在后台运行 LocalTunnel,并将输出记录到 tunnel.log

示例日志输出

nohup: ignoring input
your url is: http://angry-liger-20.34.68.37.115

2. 安装

2.1 前置条件

  • 已安装 Docker 与 Docker Compose。
  • 已安装 Node.js 和 npx(用于运行 LocalTunnel 客户端)。

2.2 步骤

  1. 将配置文件克隆或复制到一个目录中:

    mkdir ~/localtunnel
    cd ~/localtunnel
    # Add docker-compose.yml, nginx.conf, site.conf
  2. 启动 LocalTunnel 服务器和 Nginx 反向代理:

    docker-compose up -d
    • lt-server 在内部监听 3000 端口。
    • localtunnel-nginx 在外部暴露 8081 端口。
  3. 验证容器是否正在运行:

    docker ps

3. 使用

3.1 启动 LocalTunnel 客户端

nohup npx localtunnel --port 3000 --host http://:8081 > tunnel.log 2>&1 &
  • 将 “ 替换为你的公网服务器 IP 或域名。
  • tunnel.log 保存输出,包括你的公网 URL。

示例

your url is: http://angry-liger-20.34.68.37.115

3.2 检查日志

cat tunnel.log
  • 确认隧道正在运行并显示公网 URL。

3.3 停止隧道

查找后台任务并将其终止:

jobs
kill %1   # 或相应的任务编号
Back to Blog

相关文章

阅读更多 »