0%

ss + v2ray-plugin 使用

ss + v2ray-plugin 使用

申请域名

到 freenom 上去注册账号并申请免费域名,并解析域名到你的服务器ip地址,

2021-09-28 新增一键公益部署脚本

这是傻瓜式一键,目前自用,且不保证可用性。可能后续会删除此一键脚本
支持系统(自用未详细测试): CentOS 7 8 , Debian 9 10 ,Ubuntu 18 20
如果失效或者不想用一键,继续阅读后续部分即可,,一键脚本使用方式:

首先尽量确保系统是空白系统。。也就是刚新购的 vps。如果安装了其余服务,例如宝塔,可能导致安装冲突,从而失败

然后 确认已经申请了域名并且将域名 dns 解析到了此 vps 的ip上。 这是前置条件

接下来执行一键即可:

如果执行过程中 没有 curl 命令,
debian 和 ubuntu 需要执行:sudo apt update && sudo apt install curl
CentOS 需要执行:sudo yum update && sudo yum install curl

1
curl -fsSL ss-script.netsite.cc | bash -s example.com password

将最末尾的两个参数: example.com 修改为你自己的域名, password 修改成你的密码

这是傻瓜式一键,并不提供修改其他参数的选项。只有两个必备的 域名、密码需要自行修改

脚本执行的几个步骤:

  • 检查系统,debian 或 centos 系列
  • 更新 apt 或者 yum
  • 创建本地配置文件(根据输入的域名及密码)
  • 下载配置模板
  • 检查网络端口,并开启 80 和 443 端口防火墙
  • 自动安装 acme.sh , nginx 及 docker
  • 启动一个临时网站自动申请 https 证书
  • 申请证书成功后启动正式的网站加速服务
  • 打印客户端配置信息
  • 推送公益节点

注意:这是一个公益脚本,部署的是一个文件加速代下载服务,详情点击:文件加速下载

部署完成将会自动加入到公益节点中。并不会滥用,,且不会泄露你的数据及密码

脚本完全开放,可自行下载脚本内容进行审查


下载 v2ray-plugin 插件

github的v2ray-plugin中找到你要下载的插件的链接。我下的是 linux v1.1.0 的arm版本

cd 到下载目录

然后 linux使用命令

1
wget https://github.com/shadowsocks/v2ray-plugin/releases/download/v1.1.0/v2ray-plugin-linux-amd64-v1.1.0.tar.gz

下载完成后,使用命令解压

1
tar -zxvf xxx

xxx 是下载下来的文件名称

记住插件所在的目录(在后面使用插件的时候,要设置这个插件的路径)

开启 ss 服务

首先使用 秋水逸冰 的一键脚本 开启 libev 的服务器,但是由于秋水逸冰的一键脚本还不支持 v2ray-plugin ,所以安装的时候,不要安装 simple-obfs 插件。

安装后,不使用任何插件即可使用代理了

配置 ss 开启插件

打开 /etc/shadowsocks-libev/config.json 文件,在其中添加两个json键值对
(这个配置文件可能不同,具体看安装的时候放在哪里,如果是秋水逸冰的脚本,可以参照他的说明)

plugin 就是上面解压出来的文件,输入绝对路径

1
2
"plugin":"/***/***/***",
"plugin":"server;mode=websocket;path=/admin"

贴一下我的配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
{
"server":"0.0.0.0",
"server_port":8090,
"password":"xxx",
"timeout":300,
"user":"root",
"method":"aes-128-gcm",
"fast_open":false,
"nameserver":"8.8.8.8",
"mode":"tcp_and_udp",
"plugin":"/root/plugin/v2ray_plugin",
"plugin_opts":"server;path=/admin;mode=websocket;host=xxxxxxx"
}

客户端使用

配置好了之后,执行 ss-server 然后直接使用 shadowsocks 客户端访问指定的 server_port 并配置好host/path 就可以访问了。

例如使用windows客户端:
首先到 github 上下载 v2ray-plugin windows 版插件,然后放到客户端所在文件夹
然后打开 ss ,在插件程序里,把插件程序名称输入进去,例如我下载的是:v2ray-plugin_windows_amd64
在插件选项里,输入如下配置:

host 等号后面是你的域名

1
path=/admin;loglevel=none;host=xxxxxxxx;

到了这里,就已经可以使用 v2ray-plugin 访问代理了,如果不想做端口转发,就不需要往下了

下面是如何配置端口转发

在服务器上开启一个 http 服务

到百度上自行百度方法安装一个 Nginx 服务器,然后让它成功跑起来就行了,我是找到 菜鸟教程的安装方法,执行到 make install 就已经安装成功了,之后直接执行 安装目录的 sbin/nginx 就可以运行了
但是访问这个网站的时候,可能会出现一些错误,所以需要自己解决,如果出现权限错误,注意检查 user nobody (我改成了 user root) 以及文件读写权限。

一般来说,如果是 ubuntu 或者 debian centos 等,执行 sudo apt-get install nginx 或者 sudo yum install nginx ,就已经安装成功了

使用这个服务器监听 80 端口,并将访问 xxx/admin 的数据转发到 ss 的端口上

由于 shadowsocks 是使用 websocket 作为代理的,所以需要配置 Nginx 转发 websocket
配置 端口转发

主要添加下面的配置

在 http 标签的 {} 中添加

1
2
3
4
5
6
7
8
9
10
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

upstream websocket {
server localhost:8090;
}

}

配置一个正常的域名服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
server{
listen 80 default;
server_name _;

location / {
# 注意,不建议返回 404 ,建议找几个 index.html 文件,当做网站根目录
return 404;
}

# 这里是转发到后端 ss 的关键配置
location /admin {
proxy_pass http://websocket/admin;
proxy_set_header Host $http_host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}

这样在浏览器打开这个网页能够正常返回页面,而使用shadowsocks的 v2ray-plugin 访问 host/admin ,则可以使用代理。

nginx 配置了 80 端口转发流量到 8090
客户端在使用的时候,port配置为 80
这样可以隐藏掉服务器的真实 ss 端口,防止端口被发现

将 http 升级成 https

  1. 首先,在 shadowsocks config 的 plugin_opts 中修改配置

cert 和 key 等号后面是证书链和 key 的绝对路径

1
"plugin_opts":"server;path=/admin;mode=websocket;tls;host=xxx.com;cert=xxx;key=xxx"

如果是使用 acme.sh 申请的证书,那么是不需要配置 certkey 的,因为默认使用的就是 acme.sh 的路径

所以如果你要使用 acme.sh 申请证书,配置文件是下面这样的:

1
"plugin_opts":"server;path=/admin;mode=websocket;tls;host=xxx.com;"
  1. 使用 acme.sh生成证书文件

首先按照 acme.sh 的官方一键安装脚本进行安装

curl https://get.acme.sh | sh
或:
wget -O - https://get.acme.sh | sh

注意:在生成证书的时候,必须开启服务器,而且必须使用 -w 参数指定网站根目录,否则会生成失败,因为它是通过网络证书申请的,所以会访问这个网站并验证

这是成功生成的命令

1
2
3
4
5
6
acme.sh --issue -d example.com -d www.example.com -d cp.example.com -w /home/wwwroot/example.com

acme.sh --install-cert -d example.com \
--key-file /path/to/keyfile/in/nginx/key.pem \
--fullchain-file /path/to/fullchain/nginx/cert.pem \
--reloadcmd "service nginx force-reload"

需要注意的是,reloadcmd 可能是不同的,比如我的 reloadcmd 命令是 nginx -s reload

根据说明:

Please take care: The reloadcmd is very important. The cert can be automatically renewed, but, without a correct ‘reloadcmd’ the cert may not be flushed to your server(like nginx or apache), then your website will not be able to show renewed cert in 60 days.

可以得知,这个命令是很有必要的,如果不设定此两面,则证书到期后,无法正常访问网站。

  1. 在 nginx 服务器中修改配置

server{} 块中新增 https 配置:

1
2
3
4
5
6
7
8
9
10
11
12
server {
listen 443;

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 30m;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

proxy_ssl_certificate xxxxxxxxxxxxxx;
proxy_ssl_certificate_key xxxxxxxxxxxx;
}
  1. 指向生成的 cert.pem 以及 key.pem

这两个文件的绝对路径也就是上面 ss 配置中 plugin_opts cert 和 key 的路径
也就是修改 这两项

1
2
#proxy_ssl_certificate xxxxxxxxxxxxxx;
#proxy_ssl_certificate_key xxxxxxxxxxxx;

proxy_ssl_certificate 是 acme.sh 生成证书时, --fullchain-file 参数后面指定的路径
proxy_ssl_certificate_key 是 --fullchain-file 参数后面指定的路径

  1. 配置端口转发

转发规则基本和 之前的 http 转发一样,只是在 proxy_pass 后面的 http://websocket/admin 需要改成 https://websocket/admin

至此,就已经完成了

如果你按照上面的步骤升级成了 https
那么客户端在使用的时候,port 配置成 443

可能一步步说明会看不懂nginx配置,贴一篇完整的 https 的配置文件

关键的部分的配置使用 xxxxxxx 替代,需要自行更换

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
server {
listen 443 ssl http2;
server_name xxxxxxxxxx;

ssl_certificate xxxxxx;
ssl_certificate_key xxxxxx;

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 30m;

ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;

ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

# 请替换自己的 root 路径
location / {
root html;
index index.html index.htm;
}
# shadowsocks
location /admin {
proxy_pass https://websocket/admin;

proxy_ssl_certificate xxxxxxxxxx;
proxy_ssl_certificate_key xxxxxxxxxx;

proxy_set_header Host $http_host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}

添加开机启动

如果你是 Ubuntu,或者 Debian ,或者 centos
是使用的 apt-get install nginx 或者 yum install nginx 安装的web服务器
那么无需任何设置,nginx 会自动开机重启

如果是编译安装的Nginx,可以直接在 /etc/rc.local 中添加 nginx 即可

1
2
3
4
#!/bin/sh

# 如果nginx 是自行编译安装,添加下面这一行即可开机自启nginx
nginx

使用 cdn 隐藏你的服务器ip地址

目前我用的是 cloudFlare 的免费cdn,首先需要到 CloudFlare 中,填写域名
然后CloudFlare 要求到 Freedom 中,设定域名解析服务器,
设定好了之后,在 Dns 选项中填写 A 类型解析记录
然后就可以了

配置好之后,ping 一下你的网站,就会显示一个 ip 地址,这个ip 是cdn 服务商的 ip 地址,使用域名即可正常连接

使用cdn划重点:最好在CloudFlare的防火墙设置中,将 /admin 路径加入白名单,否则会出现一下可以连,一下不能连的情况

Over

有任何问题可以前往 Blog 主页留言板