Xray is a platform that supports multiple proxy protocols such as VLESS, VMess, Shadowsocks, and Trojan. Below are the steps to install Xray on an Ubuntu VPS and set up a client connection.
Installing Xray on Ubuntu VPS
Update the System
sudo apt update && sudo apt upgrade -y
Install Required Dependencies
sudo apt install -y curl wget unzip socat
Install Xray Using the Installation Script Run the following script to install the latest version of Xray:
bash <(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)
This script will download, install, and configure Xray as a systemd service.
Configure Xray After installation, the configuration file is located at:
/usr/local/etc/xray/config.json
Edit this file to set up your desired proxy protocol (e.g., VMess, VLESS, or Trojan). Below is an example configuration for VLESS with WebSocket and TLS:
{ "inbounds": [ { "port": 443, "protocol": "vless", "settings": { "clients": [ { "id": "YOUR_UUID", // Replace with a UUID "level": 0, "email": "user@example.com" } ], "decryption": "none" }, "streamSettings": { "network": "ws", "wsSettings": { "path": "/vless" }, "security": "tls", "tlsSettings": { "serverName": "example.com", "certificates": [ { "certificateFile": "/path/to/certificate.crt", // Replace with your SSL cert "keyFile": "/path/to/private.key" // Replace with your private key } ] } } } ], "outbounds": [ { "protocol": "freedom", "settings": {} } ] }
- Replace
YOUR_UUID
with a UUID generated using the command:uuidgen
Obtain SSL Certificates
Install Certbot
sudo apt install certbot
Generate the Certificate
sudo certbot certonly --standalone -d <your-domain>
Update Xray Config Use the paths generated by Certbot, typically:
/etc/letsencrypt/live/<your-domain>/fullchain.pem
/etc/letsencrypt/live/<your-domain>/privkey.pem
Update the
tlsSettings
inconfig.json
accordingly.
- Replace
Enable and Start Xray
sudo systemctl enable xray sudo systemctl start xray
Allow Firewall Rules Open the necessary ports (e.g.,
443
for TLS):sudo ufw allow 443/tcp sudo ufw allow 443/udp
Adjust Permissions for Xray
Xray runs under its own user (nobody
by default), and it doesn't have permission to access the Let's Encrypt directory. To fix this:
Add the
nobody
user (or the user running Xray) to thessl-cert
group, which has access to the files:Create the Group:
sudo groupadd ssl-certAdd the
nobody
User to the Group:sudo usermod -aG ssl-cert nobodySet Group Ownership and Permissions:
sudo chgrp -R ssl-cert /etc/letsencryptsudo chmod -R 750 /etc/letsencrypt
Restart the Xray Service:
sudo systemctl restart xray
Setting Up the VPN Client
Configure the Client Below is an example of a client configuration for VLESS with WebSocket and TLS:
- Server Address: Your VPS domain or IP address.
- Port:
443
- UUID: The same UUID you used in the Xray server configuration.
- Network:
ws
(WebSocket) - Path:
/vless
(The path configured in the serverwsSettings
) - TLS: Enabled (Set the SNI/Server Name as your domain name)
- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Comments
Post a Comment