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 你的服务器域名

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

端口为客户端右下角的

相关推荐
青云计划9 小时前
知光项目知文发布模块
java·后端·spring·mybatis
Victor3569 小时前
MongoDB(9)什么是MongoDB的副本集(Replica Set)?
后端
Victor3569 小时前
MongoDB(8)什么是聚合(Aggregation)?
后端
yeyeye11111 小时前
Spring Cloud Data Flow 简介
后端·spring·spring cloud
Tony Bai11 小时前
告别 Flaky Tests:Go 官方拟引入 testing/nettest,重塑内存网络测试标准
开发语言·网络·后端·golang·php
+VX:Fegn089512 小时前
计算机毕业设计|基于springboot + vue鲜花商城系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
程序猿阿伟12 小时前
《GraphQL批处理与全局缓存共享的底层逻辑》
后端·缓存·graphql
小小张说故事12 小时前
SQLAlchemy 技术入门指南
后端·python
识君啊12 小时前
SpringBoot 事务管理解析 - @Transactional 的正确用法与常见坑
java·数据库·spring boot·后端
想用offer打牌13 小时前
MCP (Model Context Protocol) 技术理解 - 第五篇
人工智能·后端·mcp