V2ray | Caddy
2020年已不再使用V2ray
bash <(curl -L -s https://install.direct/go.sh)
创建启动脚本/etc/init.d/v2ray
#!/bin/sh
#
# v2ray Startup script for v2ray
#
# chkconfig: - 24 76
# processname: v2ray
# pidfile: /var/run/v2ray.pid
# description: V2Ray proxy services
#
### BEGIN INIT INFO
# Provides: v2ray
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: V2Ray proxy services
# Description: V2Ray proxy services
### END INIT INFO
DESC=v2ray
NAME=v2ray
DAEMON=/usr/bin/v2ray/v2ray
PIDFILE=/var/run/$NAME.pid
LOCKFILE=/var/lock/subsys/$NAME
SCRIPTNAME=/etc/init.d/$NAME
RETVAL=0
DAEMON_OPTS="-config /etc/v2ray/config.json"
# Exit if the package is not installed
[ -x $DAEMON ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Source function library.
. /etc/rc.d/init.d/functions
start() {
local pids=$(pgrep -f $DAEMON)
if [ -n "$pids" ]; then
echo "$NAME (pid $pids) is already running"
RETVAL=0
return 0
fi
echo -n $"Starting $NAME: "
mkdir -p /var/log/v2ray
$DAEMON $DAEMON_OPTS 1>/dev/null 2>&1 &
echo $! > $PIDFILE
sleep 2
pgrep -f $DAEMON >/dev/null 2>&1
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
success; echo
touch $LOCKFILE
else
failure; echo
fi
return $RETVAL
}
stop() {
local pids=$(pgrep -f $DAEMON)
if [ -z "$pids" ]; then
echo "$NAME is not running"
RETVAL=0
return 0
fi
echo -n $"Stopping $NAME: "
killproc -p ${PIDFILE} ${NAME}
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${LOCKFILE} ${PIDFILE}
}
reload() {
echo -n $"Reloading $NAME: "
killproc -p ${PIDFILE} ${NAME} -HUP
RETVAL=$?
echo
}
rh_status() {
status -p ${PIDFILE} ${DAEMON}
}
# See how we were called.
case "$1" in
start)
rh_status >/dev/null 2>&1 && exit 0
start
;;
stop)
stop
;;
status)
rh_status
RETVAL=$?
;;
restart)
stop
start
;;
reload)
reload
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|reload|restart}" >&2
RETVAL=2
;;
esac
exit $RETVAL
chmod -R 755 /etc/init.d/v2ray
chkconfig --add v2ray
chkconfig v2ray on
service v2ray start
服务端
/etc/v2ray/config.json
{
"inbounds": [{
"port": 22393,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "60644d74-2710-4c96-a341-03e4b5475bb7",
"level": 1,
"alterId": 64
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/html"
}
}
}],
"outbounds": [{
"protocol": "freedom",
"settings": {}
},{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}],
"routing": {
"rules": [
{
"type": "field",
"ip": ["geoip:private"],
"outboundTag": "blocked"
}
]
}
}
Caddyfile
curl https://getcaddy.com | bash -s personal
***.com {
proxy / http://127.0.0.1:8080 {
header_upstream Host {host}
header_upstream X-Real-IP {remote}
header_upstream X-Forwarded-For {remote}
header_upstream X-Forwarded-Proto {scheme}
}
proxy /path localhost:81 {
websocket
header_upstream -Origin
}
}
执行./caddy -conf Caddyfile
客户端
{
"log": {
"access": "",
"loglevel": ""
},
"inbound": {
"port": 1080,
"listen": "127.0.0.1",
"protocol": "http",
"settings": {
"auth": "noauth",
"udp": false
}
},
"outbound": {
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "",
"port": 443,
"users": [
{
"id": "60644d74-2710-4c96-a341-03e4b5475bb7",
"alterId": 64
}
]
}
]
},
"streamSettings": {
"network": "ws",
"security": "tls",
"tlsSettings": {
"serverName": ""
},
"wsSettings": {
"path": "/html"
}
}
},
"outboundDetour": [
{
"protocol": "freedom",
"settings": {},
"tag": "direct"
}
],
"routing": {
"strategy": "rules",
"settings": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"type": "field",
"ip": [
"0.0.0.0/8",
"10.0.0.0/8",
"100.64.0.0/10",
"127.0.0.0/8",
"169.254.0.0/16",
"172.16.0.0/12",
"192.0.0.0/24",
"192.0.2.0/24",
"192.168.0.0/16",
"198.18.0.0/15",
"198.51.100.0/24",
"203.0.113.0/24",
"::1/128",
"fc00::/7",
"fe80::/10"
],
"outboundTag": "direct"
},
{
"type": "chinasites",
"outboundTag": "direct"
},
{
"type": "chinaip",
"outboundTag": "direct"
}
]
}
}
}