diff --git a/.env b/.env index 21e213b..15d53fe 100644 --- a/.env +++ b/.env @@ -1,6 +1,15 @@ -APP_NAME=myserver -APP_DOMAIN=example.com -ACME_EMAIL=myemail@example.com +#APP_NAME=myserver +#APP_DOMAIN=example.com +#ACME_EMAIL=myemail@example.com + +APP_NAME=vs +APP_DOMAIN=alibaba-portal.com +ACME_EMAIL=alphacodinghub@outlook.com + +LISTENING_PORT=3003 +CLIENT_ID=2e5762cc-20d2-42b1-b0ad-cbe55dc5fa35 +CLIENT_ALTERID=64 +CLIENT_WSPATH=/allproducts # with above settings, you can visit traefik dashboard at: # https://traefik.example.com diff --git a/Dockerfile b/Dockerfile index 72f1a44..ba35e6c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,8 +14,9 @@ LABEL Maintainer="George Zhou" \ Language="HTML" \ OS="Alpine Linux" \ Service="V2Ray" \ - Content="V2RAY" + Content="V2RAY and Nginx server" +ENV LISTENING_PORT 3456 ENV CLIENT_ID "2e5762cc-20d2-42b1-b0ad-cbe55dc5fa35" ENV CLIENT_ALTERID 64 ENV CLIENT_WSPATH "/allproducts" diff --git a/README.md b/README.md index 9ee552f..ae9ae0e 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,76 @@ -# v2ray-ws-tls-all-in-one +# v2ray websocks tls + web all-in-one Docker ![](https://img.shields.io/badge/language-Web-orange.svg) ![](https://img.shields.io/badge/platform-Docker-lightgrey.svg)[![](https://img.shields.io/badge/Traefik-v2.x-blue.svg)](https://containo.us/traefik/) ![](https://img.shields.io/badge/license-MIT-000000.svg) -**A v2ray docker image work with nginx** +## [中文指引请点击此处](https://github.com/alphacodinghub/v2ray/blob/master/README_cn.md) -- v2ray work with websocket -- v2ray request proxy_pass by nginx -- custom v2ray settings -- add environment variables to edit optional setting - - CLIENT_ID (default ad806487-2d26-4636-98b6-ab85cc8521f7) - - CLIENT_ALTERID (default 64) - - CLIENT_WSPATH (default /ws) - - VER (default 4.23.1) -- don't need custom domain and ssl certificate -- only cost 1 pods +## V2Ray quick deployment using Traefik -**USE: deploy this image and add default secure route with port 8080 in arukas** +- The Docker image is based on the latest official release and integrated with Nginx and a basic website. +- Deployment using Traefik, easy operation. +- Traefik automatically manages ssl certificates. +- A basic static website is integrated with the image. It will redirect to baidu.com by default however you can replace it with your own real website. +- V2Ray parameters can be easily customized using the `.env` file. You don't need to change the `docker-compose.yml` file. +- Main parameters you can customize indlude domain name, UUID, v2ray listening port, and the camouflaged path. -- path to v2ray: https://your.domain/fuckgfw_letscrossgfw -- path to websites: /usr/share/nginx/html/ +## V2Ray server setup and configuration -实例教程参考 : +### 1. VPS -- [V2Ray+WebSocket+TLS+Nginx 配置与使用教程](https://doubibackup.com/v2ray-ws-tls-nginx.html) -- https://toutyrater.github.io/advanced/wss_and_web.html -- https://bawodu.com/openshift-v2ray/ +- To buy a VPS and install Docker engine and git tool. +- To buy a domain, e.g. example.com. +- Choose an app name for your V2Ray server, e.g. `myapp`. Your camouflaged website url will then be `https://myapp.example.com`. +- Configure the DNS to point the domain `myapp.example.com` to the IP address of your VPS. + +### 2. Clone this project to your VPS + +``` +- mkdir /app +- cd /app +- git clone https://github.com/alphacodinghub/v2ray-nginx-docker.git +- cd v2ray-nginx-docker +``` + +### 3. Configure VPS + +To edit `.env` file and set necessary parameters. These three parameters must be set to your own values: APP_NAME (as chosen in Step 1), APP_DOMAIN, ACME_EMAIL (your email address for Let's Encrypt to apply for and renew ssl certificates). All other parameters can use the default values as provided. The final `.env` file should look like this (you should set your own values): + +``` +APP_NAME=myapp +APP_DOMAIN=example.com +ACME_EMAIL=myemail@example.com +LISTENING_PORT=3033 +CLIENT_ID=2e5762cc-20d2-42b1-b0ad-cbe55dc5fa35 +CLIENT_ALTERID=64 +CLIENT_WSPATH=/allproducts +``` + +In the above settings, `CLIENT_WSPATH` is the so-called camouflaged path which should be set to the same value at the VPS server and user clients. + +### 4. Website settings + +By default, the caouflaged website will be redirected to baidu.com. You can copy your real website content to `./conf/html` folder to replace original files. + +### 5. Start V2Ray server + +After above settings, you can run the following command in folder `/app/v2ray-nginx-docker` to start the V2Ray server: `docker-compose up -d`. The `-d` option is to tell the programme to run in the background. + +Run this command to check the running containers: `docker ps`. + +To access to Traefik Dashboard:https://traefik.example.com +To visit the camouflaged website:https://myapp.example.com + +## Client configuration + +Download the Windows client V2RayN, run it and click the menu: server - add [VMess] server. Please set the values according to the below figure: +![v2ray配置](https://github.com/alphacodinghub/v2ray/blob/master/images/v2rayn.png) + +> **References** + +- [Official Project V Website](https://www.v2ray.com/) +- [新白话文教程-V2Ray 配置指南](https://guide.v2fly.org/) - Official Dockerfile - https://github.com/v2ray/ext -- https://toutyrater.github.io/app/docker-deploy-v2ray.html -- SSR proxy settings - a great explaination diff --git a/README_cn.md b/README_cn.md new file mode 100644 index 0000000..a5d0902 --- /dev/null +++ b/README_cn.md @@ -0,0 +1,83 @@ +# v2ray websocks tls + web all-in-one Docker + + +![](https://img.shields.io/badge/language-Web-orange.svg) +![](https://img.shields.io/badge/platform-Docker-lightgrey.svg)[![](https://img.shields.io/badge/Traefik-v2.x-blue.svg)](https://containo.us/traefik/) +![](https://img.shields.io/badge/license-MIT-000000.svg) + +## Traefik 快速部署 V2RAY + +- Docker 镜像基于 v2ray 官方最新版本,并集成 Nginx 服务器和一个简易网站 +- 使用 Traefik 反向代理进行部署,操作简单,系统稳定 +- Traefik 自动管理 Let's Encrypt,自动申请 ssl 证书,证书过期前自动更新 +- 集成了一个简易伪装网站,缺省跳转至百度;也可以作为正式网站使用,只要将网站内容放到指定目录即可 +- 可以定制 v2ray 参数,只要在.env 中按照模板设置相应参数即可,无需修改 docker-compose.yml +- 可以定制的 v2ray 参数包括:域名、UUID、监听端口、伪装路径等 + +## 服务器安装和配置步骤 + +### 1. 准备虚拟主机 + +- 申请虚拟主机,安装最新的 Docker 引擎和 git 工具。 +- 申请一个域名,例如 `example.com`。 +- 选择一个名字作为`v2ray`应用的名称,例如`myapp`,那么`https://myapp.example.com`就是那个伪装的网站入口。 +- 配置域名服务器,将`myapp.example.com`指向上一步申请的虚拟主机的 IP 地址。 + +### 2. 将本项目克隆到虚拟机相应目录,例如 /app/v2ray-nginx-docker + +```script class:"lineNo" +- mkdir /app +- cd /app +- git clone https://github.com/alphacodinghub/v2ray-nginx-docker.git +- cd v2ray-nginx-docker +``` + +### 3. 配置参数(服务器) + +紧接着修改`.env`文件,设定相关参数,以下三个参数必须设置:`APP_NAME`(第一步中选定的 v2ray 应用名称),`APP_DOMAIN`(第一步中申请的域名),`ACME_EMAIL`(你的 Email 地址,Let's Engcrypt 申请和更新证书的时候需要),其它参数都可以使用缺省参数,甚至可以从`.env`文件中去掉,`docker-compose.yml`中设置了缺省参数,可以打开查看。设置好的`.env`文件看起来这样: + +```env +APP_NAME=myapp +APP_DOMAIN=example.com +ACME_EMAIL=myemail@example.com +LISTENING_PORT=3033 +CLIENT_ID=2e5762cc-20d2-42b1-b0ad-cbe55dc5fa35 +CLIENT_ALTERID=64 +CLIENT_WSPATH=/allproducts +``` + +#### 上述配置中 + +``` +- LISTENING_PORT: 是v2ray服务的监听端口 +- CLIENT_ID: 是UUID,必须按规定的格式设置,v2ray用UUID加密传输,可以使用在线工具(https://www.uuidgenerator.net/)生成UUID +- CLIENT_ALTERID: 是`alterid`,为了进一步防止被探测,一个用户可以在主 UUID 的基础上,再额外生成多个 ID。这里只需要指定额UUUU ID 的数量,推荐值为 4。不指定的话,默认值是 0。最大值 65535。客户端也有对应的设置,客户端的这个值不能超过服务器端所指定的值 +- CLIENT_WSPATH: 设置的伪装路径,客户端的配置要和服务器端的一致 +- 如上配置的伪装网站为`https://myapp.example.com`,完整的v2ray伪装路径是`myapp.example.com/allproducts` +``` + +### 4. 伪装网站的配置 + +缺省情况下访问伪装网站`https://myapp.example.com`时会跳转至百度。可以将所需伪装成的网站拷贝至目录`./conf/html`下替换原有文件即可。如果直接访问伪装路径`https://myapp.example.com/allproducts`则会返回`Bad Request`。 + +### 5. 启动服务器 + +按上述步骤配置以后,在目录`/app/v2ray-nginx-docker`下运行下述命令即可: `docker-compose up -d`,其中参数`-d`表示在后台运行。查看启动的容器用这个命令: +`docker ps`。至此,服务器端的部署已经完成。 + +访问 Traefik Dashboard:https://traefik.example.com +访问伪装网站:https://myapp.example.com + +## 客户端配置 + +下载 Windows 客户端 V2RayN。 +打开软件,依次点击:服务器 - 添加[VMess]服务器,按下图配置参数: + +![v2ray配置](https://github.com/alphacodinghub/v2ray/blob/master/images/v2rayn.png) + +> **参考资料:** + +- [官方 Project V 网站](https://www.v2ray.com/) +- [新白话文教程-V2Ray 配置指南](https://guide.v2fly.org/) +- Official Dockerfile +- https://github.com/v2ray/ext diff --git a/conf/html/404.html b/conf/html/404.html new file mode 100644 index 0000000..23e030e --- /dev/null +++ b/conf/html/404.html @@ -0,0 +1,10 @@ + + + + HTML Meta Tag + + + +

Welcome to Baidu world!

+ + \ No newline at end of file diff --git a/conf/html/index.html b/conf/html/index.html new file mode 100644 index 0000000..23e030e --- /dev/null +++ b/conf/html/index.html @@ -0,0 +1,10 @@ + + + + HTML Meta Tag + + + +

Welcome to Baidu world!

+ + \ No newline at end of file diff --git a/docker-build.sh b/docker-build.sh index 693a938..6429358 100644 --- a/docker-build.sh +++ b/docker-build.sh @@ -1,6 +1,4 @@ #!/bin/bash -set -ex - TAG="4.23" docker build -t alphacodinghub/v2ray-nginx:$TAG . docker build -t alphacodinghub/v2ray-nginx:latest . diff --git a/docker-compose.yml b/docker-compose.yml index 667d7ce..d574010 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: #### Traefik Proxy Setup ##### ############################################### traefik: - image: traefik:v2.2 + image: traefik:v2.2.1 restart: always container_name: traefik ports: @@ -18,11 +18,10 @@ services: - --api.dashboard=true # <== Enabling the dashboard to view services, middlewares, routers, etc... - --api.debug=true # <== Enabling additional endpoints for debugging and profiling ## Log Settings (options: ERROR, DEBUG, PANIC, FATAL, WARN, INFO) - https://docs.traefik.io/observability/logs/ ## - - --log.level=WARN # <== Setting the level of the logs from traefik + - --log.level=DEBUG # <== Setting the level of the logs from traefik ## Provider Settings - https://docs.traefik.io/providers/docker/#provider-configuration ## - --providers.docker=true # <== Enabling docker as the provider for traefik - --providers.docker.exposedbydefault=false # <== Don't expose every container to traefik, only expose enabled ones - - --providers.docker.network=web # <== Operate on the docker network named web on frontend ## Entrypoints Settings - https://docs.traefik.io/routing/entrypoints/#configuration ## - --entrypoints.web.address=:80 # <== Defining an entrypoint for port :80 named web - --entrypoints.web-secured.address=:443 # <== Defining an entrypoint for https on port :443 named web-secured @@ -31,8 +30,8 @@ services: - --certificatesresolvers.mytlschallenge.acme.email=${ACME_EMAIL} # <== Setting email for certs - --certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json # <== Defining acme file to store cert information volumes: - - ./config/traefik/letsencrypt:/letsencrypt # <== Volume for certs (TLS) - - /var/run/docker.sock:/var/run/docker.sock # <== Volume for docker admin + - ./conf/traefik/letsencrypt:/letsencrypt # <== Volume for certs (TLS) + - /var/run/docker.sock:/var/run/docker.sock # <== Volume for docker admin. Don't change it! labels: #### Labels define the behavior and rules of the traefik proxy for this container #### traefik.enable: true # <== Enable traefik on itself to view dashboard and assign subdomain to view it @@ -57,11 +56,20 @@ services: ############################################## v2ray: image: alphacodinghub/v2ray-nginx + ports: + - ${LISTENING_PORT:-3003} container_name: v2ray restart: always + environment: + LISTENING_PORT: ${LISTENING_PORT:-3003} + CLIENT_ID: ${CLIENT_ID:-2e5762cc-20d2-42b1-b0ad-cbe55dc5fa35} + CLIENT_ALTERID: ${CLIENT_ALTERID:-64} + CLIENT_WSPATH: ${CLIENT_WSPATH:-/allproducts} + volumes: + - ./conf/html:/var/www/html labels: #### Labels define the behavior and rules of the traefik proxy for this container #### traefik.enable: true # <== Enable traefik to proxy this container - traefik.http.routers.v2ray.rule: Host(`$(APP_NAME).${APP_DOMAIN}`) # <== Your Domain Name for the https rule + traefik.http.routers.v2ray.rule: Host(`${APP_NAME}.${APP_DOMAIN}`) # && PathPrefix(`${CLIENT_WSPATH:-/allproducts}`) # <== Your Domain Name for the https rule traefik.http.routers.v2ray.entrypoints: web-secured # <== Defining entrypoint for https, **ref: line 31 traefik.http.routers.v2ray.tls.certresolver: mytlschallenge # <== Defining certsresolvers for https diff --git a/docker-conf/config.json b/docker-conf/config.json index d82b7e3..af48ce4 100644 --- a/docker-conf/config.json +++ b/docker-conf/config.json @@ -1,30 +1,30 @@ { - "log": { - "access": "/var/log/v2ray/access.log", - "error": "/var/log/v2ray/error.log", - "loglevel": "debug" - }, - "inbound": { - "port": 30003, - "listen":"127.0.0.1", - "protocol": "vmess", - "settings": { - "clients": [ - { - "id": "CLIENT_ID", - "alterId": CLIENT_ALTERID - } - ] - }, - "streamSettings":{ - "network":"ws", - "wsSettings": { - "path": "CLIENT_WSPATH" - } - } - }, - "outbound": { - "protocol": "freedom", - "settings": {} - } + "log": { + "access": "/var/log/v2ray/access.log", + "error": "/var/log/v2ray/error.log", + "loglevel": "debug" + }, + "inbound": { + "port": LISTENING_PORT, + "listen": "127.0.0.1", + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "CLIENT_ID", + "alterId": CLIENT_ALTERID + } + ] + }, + "streamSettings": { + "network": "ws", + "wsSettings": { + "path": "CLIENT_WSPATH" + } + } + }, + "outbound": { + "protocol": "freedom", + "settings": {} + } } diff --git a/docker-conf/default.conf b/docker-conf/default.conf index 8aa9304..d9558c5 100644 --- a/docker-conf/default.conf +++ b/docker-conf/default.conf @@ -9,7 +9,7 @@ server { location CLIENT_WSPATH { proxy_redirect off; - proxy_pass http://127.0.0.1:30003; + proxy_pass http://127.0.0.1:LISTENING_PORT; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; diff --git a/entrypoint.sh b/entrypoint.sh index 2665aa2..aa2c410 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,8 @@ #!/bin/sh +sed -i "s/LISTENING_PORT/$LISTENING_PORT/g" /etc/v2ray/config.json sed -i "s/CLIENT_ID/$CLIENT_ID/g" /etc/v2ray/config.json sed -i "s/CLIENT_ALTERID/$CLIENT_ALTERID/g" /etc/v2ray/config.json sed -i "s#CLIENT_WSPATH#$CLIENT_WSPATH#g" /etc/v2ray/config.json sed -i "s#CLIENT_WSPATH#$CLIENT_WSPATH#g" /etc/nginx/conf.d/default.conf +sed -i "s/LISTENING_PORT/$LISTENING_PORT/g" /etc/nginx/conf.d/default.conf exec "$@" \ No newline at end of file diff --git a/images/v2rayn.png b/images/v2rayn.png new file mode 100644 index 0000000..3a9a2c1 Binary files /dev/null and b/images/v2rayn.png differ