Use LXC containers to build V2Ray and Caddy services on Alpine Linux to provide IPv6-based SSL WebSocket proxy
Preface
In the modern Internet environment, proxy services are becoming more and more important, especially when it is necessary to break through geographical restrictions and improve privacy protection. This article will introduce in detail how to use V2Ray and Caddy to build an SSL WebSocket proxy service provided through IPv6 and domain name on the LXC container of the Alpine Linux 3.19 operating system.
Environment preparation
- Make sure your LXC container is running and has an IPv6 address assigned.
- Make sure your domain name resolves to your LXC container’s IPv6 address.
Step 1: Install and configure V2Ray
1.1 Enter your LXC container
lxc exec <your-container-name> /bin/ash
1.2 Install necessary software packages
apk update
apk add curl unzip
1.3 Download and install V2Ray
mkdir -p /root/TOOLS/v2ray
cd /root/TOOLS/v2ray
curl -L -o v2ray.zip https://github.com/v2fly/v2ray-core/releases/latest/download/v2ray-linux-64.zip
unzip v2ray.zip -d /root/TOOLS/v2ray
mv /root/TOOLS/v2ray/v2ray /root/TOOLS/v2ray/v2ray_bin
mv /root/TOOLS/v2ray/v2ctl /root/TOOLS/v2ray/v2ctl_bin
chmod +x /root/TOOLS/v2ray/v2ray_bin
chmod +x /root/TOOLS/v2ray/v2ctl_bin
1.4 Create V2Ray configuration file
Edit /root/TOOLS/v2ray/config.json and add the following configuration:
Note: your-uuid can be generated through /root/TOOLS/v2ray/v2ctl_bin uuid, your-websocket-path is the path of the WebSocket connection and can be customized.
{
"inbounds": [
{
"port": 10000,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "your-uuid",
"alterId": 64
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/your-websocket-path"
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
}
]
}
1.5 Create V2Ray service file
Edit /etc/init.d/v2ray and add the following:
#!/sbin/openrc-run
name="v2ray"
description="V2Ray Service"
command="/root/TOOLS/v2ray/v2ray_bin"
command_args="run -config /root/TOOLS/v2ray/config.json"
pidfile="/var/run/v2ray.pid"
1.6 Set service file permissions and start V2Ray
chmod +x /etc/init.d/v2ray
rc-update add v2ray default
service v2ray start
Step 2: Install and configure Caddy
2.1 Install Caddy
mkdir -p /root/TOOLS/caddy
wget -O /root/TOOLS/caddy/caddy 'https://caddyserver.com/api/download?os=linux&arch=amd64'
chmod +x /root/TOOLS/caddy/caddy
2.2 Create Caddyfile configuration file
Edit /root/TOOLS/caddy/Caddyfile with the following content:
Note: your-websocket-path should be consistent with the path in the V2Ray configuration, your-email@example.com is used to automatically obtain the SSL certificate.
abc.com {
encode gzip
tls your-email@example.com
reverse_proxy /your-websocket-path localhost:10000 {
header_up Host {host}
header_up X-Real-IP {remote}
header_up X-Forwarded-For {remote}
header_up X-Forwarded-Port {server_port}
header_up X-Forwarded-Proto {scheme}
}
}
2.3 Create Caddy service file
Edit /etc/init.d/caddy and add the following:
#!/sbin/openrc-run
name="caddy"
description="Caddy Web Server"
command="/root/TOOLS/caddy/caddy"
command_args="run --config /root/TOOLS/caddy/Caddyfile --adapter caddyfile"
pidfile="/var/run/caddy.pid"
2.4 Set service file permissions and start Caddy
chmod +x /etc/init.d/caddy
rc-update add caddy default
service caddy start
Verify configuration
3.1 Make sure V2Ray and Caddy services are running
service v2ray status
service caddy status
3.2 Test the WebSocket connection using a browser or WebSocket client
wss://abc.com/your-websocket-path
FAQ Troubleshooting
-
View V2Ray log:
-
View Caddy logs:
-
Manually start V2Ray for debugging:
Through these detailed steps, you should be able to successfully set up V2Ray and Caddy services on the LXC container of Alpine Linux 3.19 to provide IPv6-based SSL WebSocket proxy services. If you encounter any problems during the process, please leave a message in the comment area to discuss.