You decide which services we may enable for analytics, personalization, and external content.
We use cookies and similar technologies on our website to personalize content, embed external media, and better understand how individual areas are used.
Necessary cookies
These entries support essential functions such as security, stability, and form processing.
Optional sections
AnalyticsMarketingPersonalizationExternal media
Your data may be processed with your consent or on the basis of legitimate interests. In the cookie settings, you can reject or explicitly allow each optional category.
Some services process personal data in third countries. By consenting, you also agree to this transfer. You can find more information in our Privacy Policy.
You can reopen and change your selection at any time. · 1.0.2
Dedicated Server: Setting Up a Reverse Proxy with nginx on Linux
Discover how to set up a secure and efficient reverse proxy for websites and game servers to improve access and protection → Learn more now
10 November 20265 min read0 Views0 helpful
Introduction
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.
FAQ
Frequently asked questions
Connect via SSH to your Linux Dedicated Server (e.g., Ubuntu) and install Nginx with sudo apt install nginx. Then adjust the firewall and configure Nginx as an intermediary between users and your target server—either for websites or specifically for game servers.
Popular use cases include websites and game servers. A reverse proxy offers benefits like enhanced security, easier access, and protection of the underlying server.
For a game server-focused reverse proxy, higher network speeds are strongly recommended, especially with many players, since the server streams raw TCP/UDP directly between client and game server. For a web-only proxy, basic specs with minimal upgrades usually suffice.
It is recommended to set up the proxy with your own domain. For each subdomain you use, create an A DNS record pointing to your Linux Dedicated Server's IP address.
Nginx is a performant and popular open-source web server that works well as a foundation for a reverse proxy.
Feedback
Was this article helpful?
Your feedback helps us prioritize and improve content.
0 of 0 Users found this article helpful.
Personal support
Need more help than the guide provides?
Our ZAP support team knows your product — briefly describe your issue and we'll help you personally.
Navigation
Dedicated Server
Preparation
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.
Tip
Recommended Server Specifications
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.
Accessing the VPS
Once your Linux Dedicated Server is ready, you need to connect. Use our SSH Getting Started guide to learn how.
Installing Nginx
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:
Code
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.
Info
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.
Code
sudo ufw allow 'Nginx Full'
Now you can test in your browser if Nginx is running by entering your server's IP address:
Code
http://[your_server_ip]
For Websites
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.
Nginx Setup
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.
Important
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:
Code
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.
Code
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.
Code
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:
If everything is okay, reload Nginx to apply the changes:
Code
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:
Code
journalctl -f -u nginx.service
to find errors.
For Game Servers
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.
Tip
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.
Nginx Setup
For this, you need the Nginx Stream module, which is not included by default in Nginx.
Install Nginx Stream Module
bash
sudo apt install -y libnginx-mod-stream
bash
sudo dnf -y install nginx-mod-stream
Nginx Stream Configuration
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:
Code
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.
Code
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:
Code
sudo nginx -t
If all is well, reload Nginx:
Code
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:
Code
journalctl -f -u nginx.service
SSL Certificate
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.
Conclusion
Congratulations, you have successfully set up a reverse proxy for your website or game server (or both :) and now benefit from increased security, reliability, and performance. If you have questions or issues, our support team is available daily to assist you! 🙂
Server hosting from €2.49 / month, online instantly, DDoS protection included.