NGINX is a popular choice for a reverse proxy because it is lightweight and has a high performance. It can also handle a large number of concurrent connections efficiently. To install it, run the following command.
apt update && apt install -y nginx
Code language: Bash (bash)
Let’s configure nginx reverse proxy now. To do this run:
nano /etc/nginx/nginx.conf
Code language: Bash (bash)
Press Ctrl
+ End
to go to the end of the file. Now copy & paste the below code into it. Please substitute the current subdomains with the ones that you have created.
stream {
map $ssl_preread_server_name $singbox {
trojan.example.com trojan;
trojan-ws.example.com trojan-ws;
trojan-ws-6.example.com trojan-ws-6;
vmess.example.com vmess;
vmess-ws.example.com vmess-ws;
vmess-ws-6.example.com vmess-ws-6;
}
upstream trojan {
server 127.0.0.1:52000;
}
upstream trojan-ws {
server 127.0.0.1:52001;
}
upstream trojan-ws-6 {
server 127.0.0.1:52002;
}
upstream vmess {
server 127.0.0.1:52003;
}
upstream vmess-ws {
server 127.0.0.1:52004;
}
upstream vmess-ws-6 {
server 127.0.0.1:52005;
}
server {
listen 443 reuseport;
listen [::]:443 reuseport;
proxy_pass $singbox;
ssl_preread on;
proxy_protocol on;
}
}
Code language: PHP (php)
After you have made changes to the nginx.conf
file, you need to apply those changes to the nginx service for them to take effect. Here’s how you can do it:
- Check the syntax of the
nginx.conf
file by running the following command:
sudo nginx -t
Code language: Bash (bash)
This command will check the syntax of the nginx.conf
file and report any errors.
- If there are no syntax errors, reload the nginx service to apply the changes by running the following command:
sudo systemctl reload nginx
Code language: Bash (bash)
This will apply the changes you made to the nginx.conf
file without interrupting the active connections to the server.
Alternatively, you can also restart the nginx service to apply the changes, by running the following command:
sudo systemctl restart nginx
Code language: Bash (bash)
This will stop and then start the nginx service, which will apply the changes you made to the nginx.conf
file. However, this will also interrupt any active connections to the server.