linux安装xray

前置准备

ubuntu服务器和域名

下载nginx

shell 复制代码
sudo apt install nginx -y
修改配置文件
shell 复制代码
sudo vim /etc/nginx/sites-available/default

增加内容如下:

js 复制代码
location /xray {  # 自定义路径
    proxy_redirect off;
    proxy_pass http://127.0.0.1:10000;  # xRay监听的端口
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
}

至此,nginx的工作就算做完了

下载xray

shell 复制代码
sudo bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install

修改配置文件

先准备一个uuid,在配置文件与客户端都需要用到

shell 复制代码
xray uuid

将返回的uuid复制下来

shell 复制代码
sudo vim /usr/local/etc/xray/config.json

以下是全部内容,可以直接复制使用,按需调整port/uuid/path

js 复制代码
{
  "log": {
    "loglevel": "warning"
  },
  "inbounds": [
    {
      "port": 10000, #监听的端口
      "listen": "127.0.0.1",
      "protocol": "vless", 
      "settings": {
        "clients": [
          {
            "id": "UUID" #自定义一个uuid,这里跟客户端一样即可,范围是1-30字节的字符(这里就是填刚才获得的uuid,你也可以不使用uuid,随便几个字符串也行)
          }
        ],
        "decryption": "none"
      },
      "streamSettings": {
        "network": "ws",
        "wsSettings": {
          "path": "/xray" #nginx的路径
        }
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "tag": "direct"
    }
  ]
}

申请证书

shell 复制代码
#安装Certbot
sudo apt install certbot python3-certbot-nginx -y
#申请证书
sudo certbot --nginx -d domian.com #填你的域名
#自动续期
sudo systemctl enable certbot.timer

开放端口

shell 复制代码
sudo ufw allow 22/tcp  # SSH端口
sudo ufw allow 80/tcp   # HTTP
sudo ufw allow 443/tcp  # HTTPS
sudo ufw allow 10000/tcp #xray的端口
sudo ufw enable  #开启防火墙

所有准备工作都做完了,现在可以启动我们的xray和nginx服务了

如果之前启动了,那么修改了配置文件之后,记得重启

shell 复制代码
#启动xray
sudo systemctl start xray 
#重启nginx
sudo systemctl start nginx

客户端的配置

下载地址

GitHub - 2dust/v2rayN: A GUI client for Windows, Linux and macOS, support Xray and sing-box and others

在release下载自己的版本就好了,下面以window版举例。

1-点击配置项,添加一个vless服务

标题
别名 随便取一个
地址 你的服务器域名
端口 443
用户id 配置文件的uuid
传输协议 ws
伪装域名 你的服务器域名
路径 nginx配置的路径
传输层安全 tls
SNI 你的服务器域名

至此,服务端与客户端就搭建好了,最后,在网络设置打开代理模式,

端口为客户端右下角的

相关推荐
Ares-Wang14 小时前
flask》》Blueprint 蓝图
后端·python·flask
饺子大魔王的男人14 小时前
不想再给云存储交月费?Go2RTC + EasyNVR 让摄像头录像留在本地不花钱
后端·数据分析
Rust研习社14 小时前
Rust 并发同步:Mutex 与 RwLock 智能指针
开发语言·后端·rust
geovindu14 小时前
go: Abstract Factory Pattern
开发语言·后端·设计模式·golang
架构源启14 小时前
深度解析:Spring Boot + Apache OpenNLP 构建企业级 NLU 系统
spring boot·后端·apache
战斗强14 小时前
从零搭建内网文件共享平台:WebDAV + AList + OnlyOffice 完整部署指南
后端·onlyoffice·文件共享·alist·webdav
skilllite作者15 小时前
SkillLite 架构优化分析报告:项目开发日记
大数据·开发语言·后端·架构·rust·rust沙箱
止语Lab1 天前
Go并发编程实战:Channel 还是 Mutex?一个场景驱动的选择框架
开发语言·后端·golang
小码哥_常1 天前
Spring Boot一键限速:守护你的接口“高速路”
后端
阿丰资源1 天前
基于SpringBoot的物流信息管理系统设计与实现(附资料)
java·spring boot·后端