v2ray 进阶配置 ws+tls+nginx+cf
dalaolala opened this issue · 3 comments
dalaolala commented
首先,你需要准备一个域名添加A记录解析到你的服务器,
可以去freenom免费注册,或者直接购买一个便宜的域名。
安装V2Ray
这里使用的是centos7系统
1、首先更新下系统:
yum -y update
2、安装V2Ray:
bash <(curl -L -s https://install.direct/go.sh)
3、设置开启启动
systemctl enable v2ray
安装SSL证书
这里说一下,如果要使用cf的full模式 ,可以用自签名的证书
安装EPEL:
yum -y install epel-release
安装certbot用于签发SSL证书:
yum -y install certbot
申请SSL证书:
certbot certonly --standalone -d example.com
这里的example.com替换成你的域名
如果申请成功,证书和私钥路径如下:
/etc/letsencrypt/live/example.com/fullchain.pem
/etc/letsencrypt/live/example.com/privkey.pem
配置Nginx
添加一个Nginx安装源:
vi /etc/yum.repos.d/nginx.repo
开启编辑模式,写入:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
写入完按ESC,然后输入:wq,按回车保存退出
安装Nginx:
yum -y install nginx
设置开机启动:
systemctl enable nginx
新建一个Nginx站点配置文件:
vi /etc/nginx/conf.d/v2ray.conf
写入配置
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497 https://$host$request_uri;
location /ray {
proxy_pass http://127.0.0.1:10000;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}
}
其中443是网站端口同时也是V2Ray传输端口,
127.0.0.1:10000其中的10000是监听端口,可以自行更改,
然后防火墙放行所需端口,或者直接关闭防火墙
配置V2Ray服务端
备份一下v2ray的默认配置文件:
cp /etc/v2ray/config.json /etc/v2ray/config.jsonbak
清空配置文件的内容:
echo "" > /etc/v2ray/config.json
编辑配置文件:
vi /etc/v2ray/config.json
写入
{
"inbounds": [
{
"port": 10000,
"listen":"127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "你的UUID",
"alterId": 64
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/ray"
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
}
]
}
UUID可以用这个网站生成:https://www.uuidgenerator.net
全部完成之后,关闭系统防火墙或者自行更改配置:
systemctl stop firewalld.service
同时把SELinux也关了:
vi /etc/selinux/config
SELINUX=disabled
setenforce 0
启动v2ray和nginx:
systemctl start v2ray
systemctl start nginx
套用cloudflare的cdn
申请好的域名指向服务器实际地址
然后开启FULL模式即可
dalaolala commented
dalaolala commented
宝塔默认的nginx配置文件
server {
listen 80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
listen [::]:80;
server_name www.demo.com;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/www.demo.com;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#HTTP_TO_HTTPS_START
if ($server_port !~ 443) {
rewrite ^(/.*)$ https://$host$1 permanent;
}
#HTTP_TO_HTTPS_END
ssl_certificate /www/server/panel/vhost/cert/www.demo.com/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/www.demo.com/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497 https://$host$request_uri;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-00.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/www.demo.com.conf;
#REWRITE-END
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) {
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known {
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
error_log off;
access_log /dev/null;
}
location ~ .*\.(js|css)?$ {
expires 12h;
error_log off;
access_log /dev/null;
}
location /nihao {
proxy_pass http://127.0.0.1:10550;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}
access_log /www/wwwlogs/www.demo.com.log;
error_log /www/wwwlogs/www.demo.com.error.log;
}
dalaolala commented
宝塔去掉没用的配置
server {
listen 80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
listen [::]:80;
server_name www.demo.com;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/www.demo.com;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#HTTP_TO_HTTPS_START
if ($server_port !~ 443) {
rewrite ^(/.*)$ https://$host$1 permanent;
}
#HTTP_TO_HTTPS_END
ssl_certificate /www/server/panel/vhost/cert/www.demo.com/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/www.demo.com/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497 https://$host$request_uri;
#SSL-END
location /nihao {
proxy_pass http://127.0.0.1:10550;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}
access_log /www/wwwlogs/www.demo.com.log;
error_log /www/wwwlogs/www.demo.com.error.log;
}