VMess + WS + TLS with Nginx in front using X-UI panel
The sources of this post include:
- https://www.youtube.com/watch?v=s90feRmdr9A
- https://bulianglin.com/archives/nicename.html
- https://github.com/computerscot/XrayVision
- https://bandwagonhost.com/cn2gia-vps.php
- https://github.com/net4people/bbs/issues/186
Buy VPS
International lines out of China are congested. Therefore it is important to pay attention to the routing of traffic to your VPS. The most expensive option is IPLC/IEPL. Assuming you can’t or won’t go that far, the next most expensive is a VPS with CN2 GIA routing in Hong Kong. That service is offered by BandwagonHost. Again, it is still very expensive. A CN2 GIA server in Los Angeles is more affordable. To find all the CN2 GIA options on the BandwagonHost website, click CN2 GIA, read the description of the different possibilities, then scroll down and click All Services. Search the services page (Ctrl+f) for CN2 GIA.
Some other options for China are Vultr and Aliyun (Alibaba Cloud).
For Iran, the difficulty is in making payment. Try AlphaVPS, RackNerd, Noez, or Aeza.
Since IP addresses frequently get blocked, ask potential providers if you can change your server’s IP address whenever necessary.
For the VPS hardware, 1 GB of RAM is sufficient for a small number of users. Choose a recent version of Debian or Ubuntu as your operating system.
Get terminal app
You can use the terminal application in macOS or Linux to SSH into your server. Modern versions of Windows PowerShell also support SSH.
You may prefer to use a purpose-built SSH app such as PuTTY, XSHELL, or FinalShell.
Buy domain name
A cheap domain name registrar is NameSilo. You can search for top-level domains (TLDs) with a low cost for the first year. If necessary, you can just buy a new domain name when the first-year discounted domain name expires.
Add DNS record(s)
You can add your DNS record(s) at your domain name registrar, or you can switch your domain over to use Cloudflare DNS services. That gives you the option of proxying certain ports through Cloudflare. On the other hand, censors have sometimes started to block access to Cloudflare.
Once your DNS record(s) have propagated, ping your DNS name to both check DNS resolution and check access to your IP address.
Prepare server
SSH into your server using Windows PowerShell or the terminal app in Linux or macOS. Replace <SERVER-IP-ADDRESS>
by your actual server IP address in the command below:
1 | ssh root@<SERVER-IP-ADDRESS> |
Suppress lengthy login messages:
1 | touch .hushlogin |
Get the existing package metadata up to date, and upgrade all existing packages:
1 | apt update && apt upgrade |
You may be prompted to reboot and then SSH back in again.
Protect your server with iptables
, replacing <HOME-IP-ADDRESS>
by your actual home IP address:
1 | iptables -A INPUT -i lo -j ACCEPT |
Check that you can still access the server with these rules before you make them permanent:
1 | exit |
Make the iptables
rules permanent:
1 | apt install iptables-persistent |
Enable BBR congestion control algorithm
Copy and paste these three commands into your SSH session to enable the Bottleneck Bandwidth and Round-trip propagation time (BBR) congestion control algorithm:
1 | echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf |
Install X-UI
For English-speaking users, use the following command to install the version that supports English:
1 | bash <(curl -Ls https://raw.githubusercontent.com/FranzKafkaYu/x-ui/master/install_en.sh) |
- When asked if you want to continue, put
y
for yes - When asked for an admin user name, put anything you want, e.g.
chief
, but preferably not the old default ofadmin
- When asked for a password, put a temporary password. e.g.
ChangeMe!
- When asked for a port number, put anything you want, e.g.
9999
, but preferably not the old default of54321
First-time login
Temporarily open port 9999
:
1 | iptables -I INPUT -p tcp --dport 9999 -j ACCEPT |
Open a browser and log in over HTTP (no security yet) on the specified port:
1 | http://<FULLY-QUALIFIED-DOMAIN-NAME>:9999 |
Enter the admin id and password you chose a moment ago, and click login.
If necessary, switch the version of xray
to the latest version.
Change the settings:
- Set the listening IP address to
127.0.0.1
only - Make a note of the panel root path, which we will call
<XUI-PATH>
Press Save and Restart.
Close the browser.
In your SSH session, close port 9999
:
1 | iptables -D INPUT -p tcp --dport 9999 -j ACCEPT |
Install Nginx
Next install Nginx:
1 | apt install nginx |
Note that we opened ports 80 and 443 in the original iptables
rules.
Install ACME
Install the recommended prerequisite:
1 | apt install socat |
Download and run the Automatic Certificate Management Environment (ACME) script:
1 | curl https://get.acme.sh | sh |
Add a soft link in /usr/local/bin
, which should be in your execution path:
1 | ln -s /root/.acme.sh/acme.sh /usr/local/bin/acme.sh |
Specify the certificate authority (CA) organization:
1 | acme.sh --set-default-ca --server letsencrypt |
Apply for a certificate, replacing <FULLY-QUALIFIED-DOMAIN-NAME>
by your server’s hostname, as specified in its DNS record:
1 | acme.sh --issue -d <FULLY-QUALIFIED-DOMAIN-NAME> -k ec-256 --webroot /var/www/html |
Install the certificate, replacing <FULLY-QUALIFIED-DOMAIN-NAME>
by your server’s hostname:
1 | acme.sh --install-cert -d <FULLY-QUALIFIED-DOMAIN-NAME> --ecc --key-file /etc/x-ui/server.key --fullchain-file /etc/x-ui/server.crt --reloadcmd "systemctl force-reload nginx" |
Search for camouflage URL
A plausible camouflage website has a large amount of traffic to and from it. For this reason, the original video recommends masquerading as a file-storage server. The video shows how to search for a Cloudreve subdomain accessible over plain HTTP on port 80.
Example of search: intext:登录 Cloudreve
.
Let’s call your choice <CAMOUFLAGE-DOMAIN>
.
Reconfigure Nginx
Edit the configuration file /etc/nginx/nginx.conf
.
1 | nano /etc/nginx/nginx.conf |
Delete the existing contents and completely replace as follows. Substitute in your actual values instead of the placeholders in angle brackets. Nginx checks that the camouflage URL can be resolved. If not, it will give you an error [emerg] host not found in upstream
.
1 | user www-data; |
Save the file.
Check the syntax:
1 | nginx -t |
Every time you modify the Nginx configuration file, you must use the command:
1 | systemctl reload nginx |
Second-time login
Log in over HTTPS:
1 | https://<FULLY-QUALIFIED-DOMAIN-NAME>/<XUI-PATH> |
Now that you are logged in over HTTPS, go to settings > User Setting, and change the password ChangeMe!
to a stronger password. (This permanent password has never been transmitted over insecure HTTP.)
Add Inbound
Click on the inbounds. Click Add Inbound.
- Put any remark
- Create a
vmess
node - Listening IP
127.0.0.1
- The port is set to
10000
- Change the network to
ws
- Make the path
/ray
- tls is not set (because Nginx takes care of TLS)
- Click the plus sign by add user to add
User1
- Click add at the bottom of the dialog box
To get the VMess URL, click Operation then QR then copy.
Download v2rayN
Download the lastest version of v2rayN from https://github.com/2dust/v2rayN/releases. The file you want is v2rayN-With-Core.zip
.
Unzip the zip file.
Start the v2rayN application. If necessary, click More info and Run anyway.
Click the v2rayN icon in the system tray.
In the menu, click the three dots, and choose language en for English. Close the v2rayN panel. Exit the program on the context menu in the system tray.
Restart to see v2rayN in English.
Right-click on the v2rayN icon in the system tray. Select Set system proxy. The icon turns red.
Configure v2rayN
Paste in the VLESS URL (Ctrl+v).
- Change the address to be your server hostname,
<FULLY-QUALIFIED-DOMAIN-NAME>
- Change the port to be
443
- Security is
zero
- Toggle TLS to on (because you deal with Nginx before you reach x-ui)
- Click Confirm