A reverse proxy server acts as an intermediary between end users and another server. Websites and game servers are common use cases for a reverse proxy, each offering benefits like enhanced security, easier access, and protection.
This guide shows you how to set up a general reverse proxy for websites as well as one specifically for game servers.
To set up a reverse proxy, you need a Linux server to host your proxy. In this example, we use Ubuntu as the Linux distribution, but the installation steps are very similar on most Linux distributions.
For a reverse proxy tailored to game servers, we strongly recommend choosing higher network speeds, especially if your server has many players. Your server streams raw TCP/UDP directly between the client (player) and the game server. For a web proxy, basic specs with minimal upgrades are usually sufficient. :)
We recommend setting up the proxy with a domain you own. For each subdomain you want to use, create an A DNS record (e.g., zapdocs.example.com) pointing to the IP address of your Linux Dedicated Server. Users will then access your website or game server via this subdomain.
Once your Linux Dedicated Server is ready, you need to connect. Use our SSH Getting Started guide to learn how.
You will use Nginx to host the reverse proxy because it is a performant and popular open-source web server.
After logging into your VPS, install Nginx with the following command:
sudo apt install nginx
After installation, adjust your firewall to allow the service to be reachable from the internet. For this guide, we use the UFW firewall since Nginx registers as an app, making configuration simple. More info on UFW can be found in our Linux Security Tips guide.
If you use other firewalls (e.g., Iptables), ensure Nginx has access to ports 80 and 443, as the service runs there.
You can list Nginx profiles with sudo ufw app list. Here, we choose the Nginx Full option, which opens HTTP for testing and HTTPS for production.
sudo ufw allow 'Nginx Full'
Now you can test in your browser if Nginx is running by entering your server's IP address:
http://[your_server_ip]
A reverse proxy for websites offers many advantages, such as forwarding to internal server resources like a Vaultwarden instance (without a port in the URL) or forwarding to external content, which is great for load balancing and protection.
A major benefit is that your server can handle requests from multiple sources/domains, unlike a single web server that only listens on ports 80/443.
First, create an entry in the Nginx directory for the domain you selected earlier. This is usually a subdomain like zapdocs.example.com in our example.
Make sure you have created an A record pointing to your proxy server's IP address beforehand. Without this, the domain and everything else will not work correctly.
Change to the server block folder with:
cd /etc/nginx/sites-available/
Now create a new configuration file. We recommend using the domain name as the filename for easy identification (e.g., zapdocs.example.com). Replace [your_filename] with your desired filename.
sudo nano [your_filename]
The Nano editor will open. Paste the following template. Replace [your_domain] with your domain to proxy and [your_target_server] with the target server to forward to.
upstream targetServer {
# Target server you want to reach. This can be:
# Internal "localhost" forwarding (e.g., 127.0.0.1:9090)
# External server (e.g., 103.146.43.52:9000)
server [your_target_server];
}
server {
listen 80;
listen [::]:80;
# Domain to serve (e.g., zapdocs.example.com)
server_name [your_domain];
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass_request_headers on;
proxy_http_version 1.1;
proxy_pass http://targetServer;
}
}
After making your changes, save the file with CTRL + X, confirm with Y, and press ENTER.
Activate the server block by creating a symlink to the enabled directory:
sudo ln -s /etc/nginx/sites-available/[your_filename] /etc/nginx/sites-enabled/[your_filename]
Check the syntax with:
sudo nginx -t
If everything is okay, reload Nginx to apply the changes:
systemctl reload nginx.service
Now test in your browser if your domain loads the content you defined as targetServer. If there are issues, check the logs with:
journalctl -f -u nginx.service
to find errors.
A reverse proxy for game servers offers many benefits, such as an additional security layer and increased reliability through better protection and access restrictions to the main server.
Most dedicated game servers work great with a raw TCP/UDP endpoint proxy set up here. A small minority of games like BeamMP may have issues with VPNs and proxies, so you need to test per game.
For this, you need the Nginx Stream module, which is not included by default in Nginx.
sudo apt install -y libnginx-mod-stream
sudo dnf -y install nginx-mod-stream
Add a new stream block in the main nginx.conf file, defining the upstream server and the port the proxy will listen on.
Open the file with:
sudo nano /etc/nginx/nginx.conf
Insert this template. Replace [your_target_server] with the server to stream to, including port (e.g., :30120 for FiveM). Replace [your_port_listener] with the port users will connect to the proxy.
stream {
upstream targetServer {
# Target server you want to reach (e.g., 103.146.43.52:30120)
server [your_target_server];
}
server {
# Listener port that accepts and forwards connections (e.g., 30120)
listen [your_port_listener];
proxy_pass targetServer;
}
}
Nginx listens on the defined port and streams all connections to the target server.
Save the file with CTRL + X, confirm with Y, and press ENTER.
Check the syntax with:
sudo nginx -t
If all is well, reload Nginx:
systemctl reload nginx.service
Now test if you can connect to your game server via the proxy domain. If there are issues, check the logs with:
journalctl -f -u nginx.service
We strongly recommend installing an SSL certificate for your domains to ensure data is securely transmitted via HTTPS. See our Certbot Installation guide, which explains the full process for requesting and automatically renewing SSL certificates.