Skip to content

Instantly share code, notes, and snippets.

@amirhosseindz
Created February 5, 2025 18:39
Show Gist options
  • Select an option

  • Save amirhosseindz/224acaff667cdd5ce0bff89d272a3b90 to your computer and use it in GitHub Desktop.

Select an option

Save amirhosseindz/224acaff667cdd5ce0bff89d272a3b90 to your computer and use it in GitHub Desktop.

Setting Up a VMESS Server on Ubuntu

This guide provides step-by-step instructions for setting up a VMESS server on an Ubuntu server.


Prerequisites

  1. Ubuntu Server: Ensure you have an Ubuntu server up and running.
  2. Root Access: Access to the server with root privileges.
  3. Domain Name (optional): If you plan to use a domain, ensure DNS records point to your server's IP.

Step 1: Update the System

sudo apt update && sudo apt upgrade -y

Step 2: Install V2Ray

Use the official V2Ray installation script:

bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)

This script installs V2Ray binaries and configures the necessary directories:

  • Executable: /usr/local/bin/v2ray
  • Configuration: /usr/local/etc/v2ray/config.json

Step 3: Configure V2Ray

Edit the default configuration file:

sudo nano /usr/local/etc/v2ray/config.json

Example Configuration (Basic VMESS over TCP):

{
  "inbounds": [
    {
      "port": 12345,
      "protocol": "vmess",
      "settings": {
        "clients": [
          {
            "id": "86D4AF88-8101-490D-8E94-FF12D513CCE0", 
            "alterId": 64
          }
        ]
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "settings": {}
    }
  ]
}

Key Parameters:

  • port: The port for your VMESS server (e.g., 12345).
  • id: A UUID for client authentication (generate one using uuidgen).
  • alterId: Additional encryption setting, typically 64.

Save and exit (CTRL+O, ENTER, CTRL+X).


Step 4: Start and Enable V2Ray

Start the V2Ray service:

sudo systemctl start v2ray

Enable it to start on boot:

sudo systemctl enable v2ray

Check the status to ensure it is running:

sudo systemctl status v2ray

Step 5: Adjust Firewall Settings

Allow traffic on the VMESS port (e.g., 12345):

sudo ufw allow 12345/tcp
sudo ufw allow 12345/udp

Enable the firewall if not already enabled:

sudo ufw enable

Step 6: (Optional) Set Up a Domain with WebSocket and TLS

6.1: Install Nginx

sudo apt install nginx -y

6.2: Configure Nginx for WebSocket

Edit the Nginx configuration file:

sudo nano /etc/nginx/sites-available/v2ray

Add the following configuration:

server {
    listen 80;
    server_name yourdomain.com;

    location /v2ray {
        proxy_pass http://127.0.0.1:12345;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
    }
}

Enable the configuration:

sudo ln -s /etc/nginx/sites-available/v2ray /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

6.3: Secure with Let's Encrypt

Install Certbot:

sudo apt install certbot python3-certbot-nginx -y

Run Certbot to get a certificate:

sudo certbot --nginx -d yourdomain.com

Step 7: Test Your Setup

  1. Open your V2Ray client (e.g., v2box).
  2. Enter the following details:
    • Server Address: Your server IP or domain name.
    • Port: 12345 (or 443 if using TLS).
    • UUID: The UUID from the configuration file.
    • AlterId: 64.
    • Network: tcp (or ws if using WebSocket).
  3. Connect and verify functionality.

Troubleshooting

  1. Check Logs:

    sudo journalctl -u v2ray
  2. Verify Port Accessibility:

    sudo netstat -tuln | grep 12345
  3. Nginx Errors:

    sudo tail -f /var/log/nginx/error.log

You now have a functional VMESS server running on Ubuntu! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment