

Updated · Sep 19, 2023
Updated · Aug 28, 2023
Raj Vardhman is a tech expert and the Chief Tech Strategist at TechJury.net, where he leads the rese... | See full bio
Girlie is an accomplished writer with an interest in technology and literature. With years of experi... | See full bio
A reverse proxy is a proxy server that works between web servers and users. It masks the web server’s Internet Protocol (IP) address, protecting its identity from clients.
Reverse proxies intercept requests on behalf of the server. 23% of websites use reverse proxies. This translates to over 26 million websites, and over 25 million use Nginx.
You do not have to have a major website to use a reverse proxy. Continue reading to learn how to set up your reverse proxy using Nginx and Apache.
🔑 Key Takeaways
|
Reverse proxy servers add extra control and ensure smooth network traffic flow between clients and servers. It can also direct requests based on parameters like the user's device and location.
This type of proxy server is commonly used for load balancing. It distributes client requests among multiple servers to optimize speed and capacity.
A reverse proxy accelerates web traffic by compressing data and caching frequently requested content.
With 30,000 websites hacked daily worldwide, the importance of security is clear. Reverse proxy servers step in by safeguarding server identities and thwarting cyberattacks. They also simplify access to multiple servers using just one URL, regardless of network complexity.
Setting up your reverse proxy is relatively easy. The following sections discuss using Nginx and Apache as reverse proxy servers.
Nginx, pronounced “engine-ex,” is an open-source web server known for its speed and reliability. It can act as a reverse proxy, load balancer, and caching solution.
💡 Did You Know When setting up a Reverse Proxy, managing a heavily visited website, or operating an e-commerce platform, you can configure a reverse proxy for your server. The recommended approach is establishing it using the Nginx open-source reverse proxy software. |
Many big companies use this software for their websites and online services. Here are the steps to set up Nginx as a reverse proxy:
Begin by updating the system and installing Nginx. Execute the following commands:
sudo apt update sudo apt install nginx |
Start the Nginx service upon completing the installation. Use the command:
sudo systemctl start nginx |
Enable Nginx with the following:
sudo systemctl enable nginx |
After enabling Nginx, you will receive the following output confirming its activation:
To verify that Nginx is running correctly, check its status with this command:
sudo systemctl status nginx |
Ensure that the output confirms that Nginx is running fine.
Make a configuration file for the reverse proxy settings:
nano /etc/nginx/conf.d/custom_proxy.conf |
In this file, add the following configuration lines:
server { listen 80; listen [::]:80; server_name myexample.com; location / { proxy_pass http://localhost:3000/; } } |
Save the file and exit the editor. Then, create a link for the new proxy configuration file using the command:
ln -s /etc/nginx/conf.d/custom_server.conf |
Test the configuration.
To check the Nginx configuration for any errors, run the following command:
sudo nginx –t |
The output should look like this:
If the output indicates that the Nginx configuration is correct without any errors, proceed to restart Nginx using the command:
sudo nginx -s reload |
Once you set up the Nginx reverse proxy successfully, it will start routing any incoming traffic to the specified backend server.
Smartproxy is a top-rated proxy provider trusted by many. Its 40 million+ proxies from 195+ locations help bypass CAPTCHAs, geo-blocks, and IP bans. It offers a free trial and has a high rating of 4.7 on Trustpilot with 89% 5-star ratings, making it one of the best in the industry.
Apache is a web server software that connects visitors’ devices to your website, allowing them to view its content.
💡 Did You Know? As of May 2023, Apache leads the web server market with a 41.30% user share, owing to its speed, reliability, and security. Nginx follows for its strong performance and scalability. |
It handles HTTP requests and delivers web pages. Apache also makes the site functional and influences its performance.
Setting up Apache as a reverse proxy can be done by following these steps:
First, you must install Apache to set it up as a reverse proxy. Use the following command to do this:
$ sudo yum install httpd |
The following modules must be installed and activated on the Apache server:
Check if these modules are installed and activated by running the following command:
$ httpd -M |
If these modules are not on the list, enable them in the Apache configuration file (httpd.conf). Add these lines to the file:
$ sudo vim /etc/httpd/conf/httpd.conf LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so |
Relaunch Apache to apply the changes:
sudo systemctl httpd restart |
On the backend server (where you have also installed Apache), create an HTML page for testing. It should have the following files:
Save and close the file. Restart Apache to save the changes. Use this URL to test the page:
http://192.168.1.50 |
To set up the reverse proxy, open the Apache configuration file. Add these lines:
$ sudo vim /etc/httpd/conf/httpd.conf <VirtualHost *:80> ProxyPreserveHost On ProxyPass / http://192.168.1.50/ ProxyPassReverse / http://192.168.1.50/ </VirtualHost> |
The configuration above redirects any requests received at 'http://192.168.1.50/'. Restart Apache.
$ sudo systemctl restart httpd |
If you want, you can include another port in the URL. Using Apache Tomcat as a backend server on port 8080, use the following entries in httpd.conf:
<VirtualHost *:80> ProxyPreserveHost On ProxyPass / http://192.168.1.50:8080/test/ ProxyPassReverse / http://192.168.1.50:8080/test/ </VirtualHost> |
To test the reverse proxy, open a web browser. Enter the following URL:
http://192.168.1.100/ |
The reverse proxy server's IP address is 192.168.1.100 in this case. If everything is configured correctly, you should see the page hosted on the backend server.
✅ Pro Tip: Reverse proxies serve various purposes, including safeguarding backend servers from harmful traffic. Encountering a "504 Gateway Time-Out" error? That's the reverse proxy flagging an inaccessible backend server. Learn more in our article about comparing forward and reverse proxies. |
Using reverse proxies has a lot of advantages. However, it also comes with limitations.
Check out the pros and cons of reverse proxies in the table below:
Pros |
Cons |
Protects internal servers by acting as the face of the website and blocking direct access |
Can track IP addresses and manipulate non-encrypted traffic, which makes them vulnerable to malicious parties |
Can defend you against Distributed Denial-of-Service (DDoS) attacks |
Failure in the one domain can bring down all front-end ones |
Distributes traffic across multiple servers and prevents overloading on a single server |
Consumes additional network resources and processing power |
Improves website performance by serving content from the local cache |
Causes everything to stop when there’s no access to the backend server |
Can decrypt encrypted data and reduce the server load |
|
Routes requests to the nearest servers geographically, which minimizes access time |
|
Setting up your reverse proxy servers comes with numerous benefits. It can significantly improve your website’s security, scalability, and performance.
Nginx and Apache are among the most commonly used reverse proxy software. They are both reliable and easy to set up.
The first step in successfully setting up a reverse proxy is choosing the appropriate reverse proxy software. Tailor the settings according to your needs and manage incoming requests to your backend servers effectively.
A reverse proxy directs incoming requests to a server through Domain Name System (DNS) configuration.
Yes. Cloudflare is a reverse proxy service that safeguards websites, enhances performance, and prevents malicious attacks.
Your email address will not be published.
Updated · Sep 19, 2023
Updated · Sep 11, 2023
Updated · Sep 05, 2023
Updated · Sep 05, 2023