sexyfeifan

sexyfeifan

我是性感的非凡

Set up a Caddy proxy for forwarding WeChat Work messages

A VPS, available both domestically and internationally, must have a public IPv4.

Supported systems: Debian, Ubuntu, CentOS are all acceptable.

SSH Tools:#

  • Windows platform: cmd, putty, finalshell, etc.
  • Mac platform: terminal, iterm2, termius, etc.

Understand basic Linux operations, such as vi, systemctl, etc.

Caddy official documentation: https://caddyserver.com/docs/

Install Caddy#

Execute the relevant commands according to the system version.

  • For Debian and Ubuntu, execute the following commands:
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
  • For CentOS 7, execute the following commands:
yum install yum-plugin-copr
yum copr enable @caddy/caddy
yum install caddy
  • For CentOS 8, execute the following commands:
dnf install 'dnf-command(copr)'
dnf copr enable @caddy/caddy
dnf install caddy

Configure Caddyfile #

After installing Caddy without errors, use vi to create a Caddyfile in /etc/caddy. If the file already exists, you can delete all content within the file.

vi /etc/caddy/Caddyfile
  • If accessing directly via the VPS's IP, fill in the following content in the Caddyfile:
:80 {
        reverse_proxy https://qyapi.weixin.qq.com {
                header_up Host {upstream_hostport}
        }
}

Here, :80 indicates using port 80 of the server; if using another port, modify as needed;

https://qyapi.weixin.qq.com is the official interface address of WeChat Work and should not be changed;

{upstream_hostport} is a fixed writing and should not be changed;

  • If using a configured domain name, fill in the following content in the Caddyfile:
abc.xyz {
        reverse_proxy https://qyapi.weixin.qq.com {
                header_up Host {upstream_hostport}
        }
}

Here, change abc.xyz to your domain name;

Without a port, access using https or http depending on the domain certificate situation. This tutorial does not cover certificate-related content, please resolve it yourself;

If you need to use another port, simply add it after the domain name, such as abc.xyz:8080.

Restart Caddy Service#

After saving the configured Caddyfile, restart the Caddy service using systemctl restart caddy. If there are errors, check if the content format of the Caddyfile is incorrect.

Use Proxy#

In the software where you need to use this proxy, change the official WeChat address https://qyapi.weixin.qq.com to the address or domain name + port (80/443 do not need to specify the port) you set in the Caddyfile, such as http://ip:8080, https://abc.xyz, etc.

If the network is unreachable, check whether the VPS's firewall has opened the relevant ports.

Docker Method#

If only forwarding WeChat messages, use this image htnanako/wxproxy, and you can start the container with a single command. The mapped port is up to you; after the container starts, fill in according to the previous step Use Proxy.

For message forwarding implemented with code, it is no longer a reverse proxy.

docker-compose

version: "3"
services:
  wxproxy:
    image: htnanako/wxproxy:latest
    container_name: wxproxy
    ports:
      - 8000:8000
    restart: unless-stopped

docker cli

docker run -d \
  --name=wxproxy \
  -p 8000:8000 \
  --restart unless-stopped \
  htnanako/wxproxy:latest

Other Services#

For software like Telegram and Discord that are outside the Great Firewall, you can also use a VPS for proxying when there is no magical environment on NAS. You need to use an overseas VPS.

Similar to WeChat Work, change the WeChat interface address in the Caddyfile configuration to the relevant interface address.

  • Telegram interface address: https://api.telegram.org
  • Discord interface address: Fill in according to the webhook address provided by Discord, such as https://discord.com, https://discord.gg, etc.

If you need multiple services to coexist, copy multiple complete configurations, modify the interface addresses and domain names or port numbers, and use different port numbers or different subdomains.

This article is synchronized and updated to xLog by Mix Space. The original link is https://taikula.cool/posts/tutorial/shi-yong-caddy-da-jian-qi-wei-xiao-xi-zhuan-fa-dai-li

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.