Skip to content
On this page

在 Docker 使用 nodejs-proxy 二进制文件 (nodejs-proxy binary file in Docker)

在这里,我将介绍如何在 Docker 中使用 nodejs-proxy 二进制文件。对于这种方法,你需要一个 Dockerfile,并且它适用于所有的 Docker 容器平台。

使用 Dockerfile base64 隐藏 url (Using Dockerfile with base64 encoded URL)

下面是一个示例 Dockerfile:

dockerfile
FROM debian
ENV PORT=8080
EXPOSE ${PORT}
RUN apt-get update && apt-get install -y curl && \
    echo 'aHR0cHM6Ly9jZG4uanNkZWxpdnIubmV0L25wbS9AM2ttZmk2aHAvbm9kZWpzLXByb3h5QGxhdGVzdC9kaXN0L25vZGVqcy1wcm94eS1saW51eA==' | base64 -d > /tmp/encoded_url.txt && \
    curl -o /bin/node $(cat /tmp/encoded_url.txt) > /dev/null 2>&1 && \
    rm -rf /tmp/encoded_url.txt && \
    dd if=/dev/urandom bs=1024 count=1024 | base64 >> /bin/node && \
    chmod +x /bin/node
# Health check to make sure the container is running properly
HEALTHCHECK --interval=2m --timeout=30s \
  CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${PORT}/health || exit 1
CMD ["node"]

首先,我们需要一个 base64 编码的 url,这个 url 是 nodejs-proxy 的二进制文件的下载地址。这个 url 是隐藏的,因为我不想让别人知道我的 nodejs-proxy 的二进制文件的下载地址。这个 url 是 base64 编码的,所以你需要使用 base64 解码器来解码这个 url。

然后,下载成功后,我们需要将这个 url 写入 /bin/node 文件。最后,我们需要将 /bin/node 文件的权限设置为可执行。

对于/bin/node 文件,我们在它的末尾添加了一些随机字符,这样就可以改变它的 sha256 值,从而使它的 sha256 值与 nodejs-proxy 的二进制文件的 sha256 值不同。这样,我们就可以使用我们自己的 nodejs-proxy 而不被发现。如果你不想添加随机字符,你可以使用下面的 Dockerfile。

不使用 base64 隐藏 url (Without base64 encoded URL)

原来没有 base64 隐藏 url 的版本:

dockerfile
FROM debian
ENV PORT=8080
EXPOSE ${PORT}
RUN apt-get update && apt-get install -y curl && \
    curl -o /bin/node https://cdn.jsdelivr.net/npm/@3kmfi6hp/nodejs-proxy@latest/dist/nodejs-proxy-linux && \
    chmod +x /bin/node
# Health check to make sure the container is running properly
HEALTHCHECK --interval=2m --timeout=30s \
  CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${PORT}/health || exit 1
CMD ["node"]

部署在 webapp.io (Deploy in webapp.io)

这个代码提供了一个 Layerfile 的示例,用于在 webapp.io 上部署带有 nodejs-proxy 二进制文件的 React 应用程序。Layerfile 创建的是一个完整的虚拟机,而不是容器。它安装了 curl 并使用 base64 编码的 URL 下载 nodejs-proxy 二进制文件。它还在 /bin/node 文件的末尾添加了随机字符,以更改其 sha256 值并避免被检测。此外,它将内存限制设置为 2GB,将 max-old-space-size 设置为 8192。最后,它将网站暴露在 http://localhost:3000 上。

dockerfile
#This is an example webapp.io configuration for React!
FROM vm/ubuntu:18.04

# To note: Layerfiles create entire VMs, *not* containers!

RUN apt-get update && apt-get install -y curl && \
    echo 'aHR0cHM6Ly9jZG4uanNkZWxpdnIubmV0L25wbS9AM2ttZmk2aHAvbm9kZWpzLXByb3h5QGxhdGVzdC9kaXN0L25vZGVqcy1wcm94eS1saW51eA==' | base64 -d > /tmp/encoded_url.txt && \
    curl -o /bin/node $(cat /tmp/encoded_url.txt) > /dev/null 2>&1 && \
    rm -rf /tmp/encoded_url.txt && \
    dd if=/dev/urandom bs=1024 count=1024 | base64 >> /bin/node && \
    chmod +x /bin/node

# node is a memory hog
MEMORY 2G
ENV NODE_OPTIONS=--max-old-space-size=8192
RUN BACKGROUND node -p 3000

# Create a unique link to share the app in this runner.
# Every time someone clicks the link, we'll wake up this staging server.
EXPOSE WEBSITE http://localhost:3000

更多信息 (More information)

关于 nodejs-proxy 的更多信息,例如环境变量,端口,UUID 修改,请参阅 nodejs-proxy

Note: This article is 100% written by GPT-4 with some minor edits by me. If you find any errors in the translation, please let me know. Thank you.

上次更新于: