generated from github/dotnet-codespaces
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
To create a VLESS configuration with TLS that hides your first server behind a new server (acting as a CDN), we'll use the UUID generated from the UUID server and configure the VLESS proxy with TLS. Here's the full Python code to generate the configuration:
Full Python Code for VLESS with CDN (TLS)
import uuid
import json
def generate_vless_cdn_config(backend_host, backend_port, cdn_host, cdn_port, uuid_str, sni, path, service_name):
"""
Generates a VLESS configuration that uses a CDN to hide the backend server.
"""
config = {
"v": "2", # Default version
"ps": service_name, # Profile name
"add": cdn_host, # CDN server address
"port": cdn_port, # CDN server port
"id": uuid_str, # User UUID
"aid": "0", # AlterID (VLESS doesn't use this, but it's required)
"net": "ws", # Network type (WebSocket)
"type": "none", # No obfuscation
"tls": "tls", # Enable TLS
"sni": sni, # Server Name Indication for TLS
"path": path, # WebSocket path
"protocol": "vless", # Protocol type
"backend": {
"host": backend_host, # Actual backend server
"port": backend_port, # Backend server port
},
}
return config
def save_config(config, filename):
"""
Saves the configuration to a JSON file.
"""
with open(filename, "w") as f:
json.dump(config, f, indent=4)
def main():
# User input
backend_host = input("Enter Backend Server Host (e.g., real-server.com): ")
backend_port = int(input("Enter Backend Server Port (e.g., 443): "))
cdn_host = input("Enter CDN Server Host (e.g., cdn-server.com): ")
cdn_port = int(input("Enter CDN Server Port (e.g., 443): "))
uuid_str = input(f"Enter User UUID (press Enter to generate one): ") or str(uuid.uuid4())
sni = input("Enter SNI (e.g., cdn-server.com): ")
path = input("Enter WebSocket Path (e.g., /vless): ") or "/vless"
service_name = input("Enter Profile Name (e.g., VLESS-CDN): ") or "Generated VLESS CDN Config"
# Generate configuration
config = generate_vless_cdn_config(backend_host, backend_port, cdn_host, cdn_port, uuid_str, sni, path, service_name)
# Save to file
filename = "vless_cdn_config.json"
save_config(config, filename)
print(f"VLESS CDN configuration saved to {filename}")
# Print the configuration
print("\nGenerated VLESS CDN Configuration:")
print(json.dumps(config, indent=4))
if __name__ == "__main__":
main()How It Works
- Backend Server: This is your actual server that you want to hide behind the CDN.
- CDN Server: This is the server that acts as the proxy to the backend server.
- UUID: The UUID identifies the user and is used in the VLESS configuration.
- TLS and SNI: Ensures secure communication between the client and the CDN server.
- WebSocket Path: The path used for WebSocket communication.
Example Input and Output
User Input:
- Backend Server Host:
real-server.com - Backend Server Port:
443 - CDN Server Host:
cdn-server.com - CDN Server Port:
443 - User UUID: (Press Enter to auto-generate)
- SNI:
cdn-server.com - WebSocket Path:
/vless - Profile Name:
VLESS-CDN
Generated Configuration (vless_cdn_config.json):
{
"v": "2",
"ps": "VLESS-CDN",
"add": "cdn-server.com",
"port": 443,
"id": "f9b8a7c6-d5e4-4f3a-8b2c-1d0e9f8a7b6c",
"aid": "0",
"net": "ws",
"type": "none",
"tls": "tls",
"sni": "cdn-server.com",
"path": "/vless",
"protocol": "vless",
"backend": {
"host": "real-server.com",
"port": 443
}
}How to Use
-
Import into V2RayNG:
- Save the
vless_cdn_config.jsonfile. - Open V2RayNG, go to
Settings>Import/Export>Import from JSON, and select the file.
- Save the
-
Server Setup:
- Set up your backend server to handle VLESS traffic.
- Configure the CDN server (e.g., Cloudflare, Nginx, or any other reverse proxy) to forward traffic to the backend server.
Notes
- CDN Configuration: The CDN server must be properly configured to forward WebSocket traffic to the backend server.
- TLS Certificate: The CDN server must have a valid TLS certificate for the SNI provided.
- Backend Security: Ensure that only the CDN server can access the backend server (e.g., using IP restrictions or firewall rules).
Let me know if you need help setting up the CDN or backend server!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels