Home Hosting Tutorials & Examples: How to configure and set up a Reverse Proxy (Nginx & Apache)

Tutorials & Examples: How to configure and set up a Reverse Proxy (Nginx & Apache)

Tutorials & Examples: How to configure and set up a Reverse Proxy (Nginx & Apache)

Reverse proxy positions ahead of a web server and get all the requests before reaching the origin server. This proxy functions identically to a forward proxy, apart from the case that is the webserver utilizing the broker instead of the client or user. Usually, reverse proxies are used to boost the performance, reliability, and security of the webserver.

Also Read: How to Edit or Change Your WordPress Homepage

To understand more, for instance, you can host a non-WordPress site on example.com domain on say Server A and let its blog running on the WordPress setup at example.com/blog URL that is hosted on say Server B. This is easy to achieve by adding a reverse proxy for that server hosting your top site. It is possible to configure the reverse proxy to pass on requests to the blog to a different server.

The present article discusses the fundamentals of reverse proxy servers, how they function, their key benefits, and how you can use them to quicken and secure your WordPress site.

Related: Best Practices to Setup W3 Total Cache Plugin

What Is a Reverse Proxy?

To get knowledge on a reverse proxy server, firstly, you need to know its role and know about all its associated terms.

Whenever you browse the web in general by typing in a domain name or clicking a link, the website’s server gets directly connected to your browser or device. Subsequently, it begins the download process of its resources.

If you intend to anonymize your IP address directly from those websites you visit, there is an option to use a proxy server to send all your requests to it first. Next, it will promote your requests to the DNS resolver. Subsequently, it will download the resources of the website from its root server.

A reverse proxy is a server that sits in front of web servers and forwards client (e.g., a web browser) requests to those web servers. Reverse proxies are typically implemented to help increase security, performance, and reliability. To better understand how a reverse proxy works and the benefits it can provide, let us first define what a proxy server is.

Later, it will forward those resources towards your device, which is termed a forward proxy.

You are entirely concealed from the website because it assumes that your request comes from the forward proxy.

Info:

The way few hosting providers like Web hosting companies calculate site visits, they demand the users put a header to inform their actual IP address to the root server. Thus, the privacy advantages do not apply in some instances like these.

In addition to improving user privacy, using a forward proxy is primarily to avoid geographical content limitations. For example, you desire to watch a blocked video in that region, then a forward proxy and an IP address are helpful. On this IP address, you can watch the video.

Forward proxy functions are nearly identical to a Virtual Private Network (VPN). However, both are different technologies with specific use cases (however, they may occasionally overlap).

Reverse Proxy Server vs. Forward Proxy Server:

A reverse proxy server functions in the form of a front for the root servers to uphold anonymity and boost security. It is identical to how a user or client uses a forward proxy to attain the same result. It makes sure no client or user directly communicates with the root server.

Though the difference between forward and reverse proxy is slight, they work uniquely.

Both of them can work collectively because there is no overlap among their functioning. Generally, users or clients utilize a forward proxy, whereas the root servers use a reverse proxy.

Because a server admin can manage the way reverse proxy would function, you can utilize it to allow several valuable features.

All its advantages will be discussed later in this article.

Why Use a Reverse Proxy?

Several businesses, massive enterprises, use personalized websites that are custom-made to their unique requirements. Moreover, they are not operating on WordPress. Certain instances include websites focused on banks and insurance.

In another case, a business may host their website on an external service that disallows them to install external software. Typically, they are small to average-sized retailers who use an e-commerce platform like Shopify.

Because WordPress possesses powerful CMS features, several businesses, including big enterprises with personalized websites, may host their blogs through WordPress setup.

One effective way to solve this issue is to set up WordPress on the subdomain of the primary website and organize the navigation menus so that users can easily toggle between the primary website and the blog.

The subdomains act in the form of a unique domain to influence the SEO of your site. Though Google equally considers subdomains and subdirectories, it needs more effort to optimize any website for SEO rankings if the hosting is done on a subdomain than a subdirectory.

Google has again confirmed that it equally considers both subdirectories and subdomains. However, certain SEO experts conflict with it. Even if it does no influence the SEO of your site, a site that is hosted within a subdirectory is relatively simpler to maintain.

This is why you could use a reverse proxy to forward requests to the blog of the site hosted on a separate server. To understand clearly, for instance, a bank can securely host its primary website on its servers. However, they can even host their WordPress-driven blog distinctly on a managed WordPress host such as Web hosting companies.

Combining 2 various sites within a single domain name is an excellent benefit of using a reverse proxy. Moreover, it assists the brands to let their site stay ordered, look professional, and uphold credibility.

Now let’s learn how a reverse proxy can boost security, performance, and reliability.

Advantages of Using a Reverse Proxy:

Apart from the above use case, the reverse proxies too offer several other advantages. The below section discusses a few of their key benefits:

Load Balancing:

A single root server cannot manage all the traffic incoming for a website having millions of visitors daily. Especially in such cases, you can smartly allocate the traffic amongst a group of multiple servers. Typically, every server will host identical content to discard a single point of breakdown. Hence, the particular website turns more reliable.

Generally, a reverse proxy is found to be an excellent way to install this. This is because it can collect the incoming traffic before it goes into the root server. If the root server is overloaded or falls short completely, it can allow the distribution of the traffic to other servers. During this process, it makes sure the site’s functionality is unaffected.

Reverse proxies are also capable of forwarding incoming requests to multiple servers. In these cases, every server performs an explicit function for which they are optimized. Subsequently, the reverse proxy can amass responses from every server and submits them to the client.

Because we utilize the most famous reverse proxies chiefly for load balancing, they are too regarded as Load Balancers.

Global Server Load Balancing (GSLB):

GSLB is well-known as an advanced load balancing system for allocating website traffic among multiple servers strategically organized all over the globe. Usually, it is accomplished through the anycast routing technique. In this technique, the reverse proxy chooses the server node depending on the quickest travel time between the server and the client.

Apart from boosting the reliability and security of the website, GSLB also decreases latency and load times. Henceforth, it enhances the user experience. It is allowed to use GSLB with some other network optimization methods like Spoon Feeding. When you use it with such scenarios, the computational resources of the origin servers will be freed up.

You can manually set up GSLB on your server, but dedicated CDNs like Cloudflare and KeyCDN typically monitor it. Web hosting companies serve every website hosted via a Load Balancer (powered by Google Cloud Platform).

Enhanced Security:

Reverse proxies can hide the IP address as well as some other aspects of origin servers. So, the origin server of your website can better uphold its anonymity and thus significantly boosting its security.

As the reverse proxy would get all the traffic before it goes into the primary server, hackers or attackers will perceive it more challenging to target your site with security threats like DDoS attacks.

A strict firewall can strengthen the reverse proxy with more robust security to resist the general cyber-attacks. If a reverse proxy is not installed, it is hard to discard malware or begin takedowns.

Info:

Web hosting companies utilize reverse proxies within its backend architecture and provides free WordPress hack solutions to every website it hosts.

A reverse proxy, including HAProxy, can add basic HTTP access authentication into a web server that is not enabled. Also, you can use a reverse proxy to include centralized verification for different kinds of requests.

Powerful Caching:

A reverse proxy is also helpful in increasing the speed of the website. It accomplished this by caching static and dynamic content. As a result, there will be a reduction of the origin server load, which leads to a faster website.

Consider an example in which your origin server is based in the USA and suppose a user living in Europe visits your website. In this case, you can provide a cached version of your website from the convenience of a reverse proxy server located in Europe. Because the reverse proxy is situated nearer to the user than the origin server, the website takes time to load. Hence, performance is efficient.

Varnish and Nginx FastCGI are well-known examples of reverse proxies that are useful for caching web content. When you choose Kista as the host of your site, you can stay stress-free about caching. This is because Web hosting companies look after all the caching groundwork to reduce your effort.

Superior Compression:

Generally, server responses utilize a much amount of bandwidth. If the server responses are compressed before delivering them to the client, it can decrease the bandwidth needed. Hence, the server responses will speed up across the network.

A reverse proxy works perfectly to compress server responses because it is positioned amongst the client and the origin servers.

Optimized SSL Encryption:

For the origin server, encrypting and decrypting the SSL/TLS requests for every client can be highly taxing. This task can be handled by a reverse proxy to free up the resources of the origin server. The idea behind freeing up is to focus on other significant tasks like serving content.

Another benefit of delegating SSL/TSL encryption & decryption is to decrease latency for clients who are physically far from the origin server.

There is an option to choose a reverse proxy with dedicated SSL/TLS acceleration hardware to optimize this task even more. This kind of reverse proxy is termed an SSL/TLS termination proxy. Few servers like Varnish are not compatible with the SSL/TSL protocols. Hence, an SSL/TSL termination reverse proxy could assist in securing the traffic through them.

Better A/B Testing:

The majority of the A/B testing tools demand you to use the external JavaScript libraries for loading their functions. But, the process of loading third-party scripts can result in slowing down the page load times. Also, it can lead to a weird experience for users.

A reverse proxy can be helpful to make two distinct flows at the server level as an alternative. For instance, you can use split_clients or sticky route methods of Nginx to manage traffic redirection.

Go through the tutorials on freeCodeCamp and Nginx to know more about carrying out A/B testing through a reverse proxy.

Monitoring and Logging Traffic:

Whatever requests go across a reverse proxy is being captured. So, you can utilize them as a fundamental hub to supervise and record traffic. Irrespective of you using single or multiple web servers for hosting all components of your website, using a reverse proxy makes it simpler to supervise all the incoming & outgoing data from your website.

The Most Popular Reverse Proxies:

According to W3Techs, nearly 83% of the websites utilize no reverse proxy services, which they examine.

Out of the 17% of websites using a reverse proxy, you will observe that majority of them are CDNs. The reason is a majority of the reverse proxies, by default, conceal their existence for a safety measure. Therefore, you cannot trust website monitoring services such as W3Techs to discover which reverse proxies are the most famous ones.

Based on our research and knowledge, the most famous reverse proxies valid presently are
Nginx, Varnish, Apache Traffic Server, and HAProxy. They are discussed below:

Nginx:

Nginx is famously known as an open-source web server capable of working as a reverse proxy. In addition to working as a host for websites, it is one of the most extensively used reverse proxy and load balancing solutions. According to Netcraft, more than 479 million web servers were utilizing Nginx in December 2019. This makes it the front-runner in the webserver market share.

This proxy offers every reverse proxy benefit described above. Furthermore, it boosts web performance, reliability, security, and scalability. It is easy to configure Nginx through its configuration file.

The Nginx Plus, a commercial offering, is only helpful to gain access to the API-based configuration options and other functionalities appropriate for big enterprise websites.

Web hosting companies control all their websites via Nginx. It got rank in Top Tier web hosting status by Review Signal in every category it participated in. Few other leading companies that make use of Nginx are Netflix, MaxCDN, and Cloudflare.

It is easy to set up Nginx as a fundamental reverse proxy. Moreover, Nginx also offers you various directives to tailor your server’s reverse proxy according to your needs. The way to accomplish it is discussed in a later section. A Web hosting companies customer can learn how to use a reverse proxy for websites hosted via Web hosting companies in that section.

The Advantages of Using Nginx Reverse Proxy

Let’s delve into the reasons explaining why this tool is so popular:

  • It is simple to implement and provides the user with high-end security against Web server attacks such as DDoS and DoS
  • Nginx Reverse proxy helps create a balanced load among several back-end servers and provides caching for a slower back-end server
  • Nginx does not require setting up a new process for each web request from the client. Instead, the default configuration is to comprise one work process per CPU
  • It can act as a reverse proxy server for various protocols such as HTTP, HTTPS, TCP, UDP, SMTP, IMAP, and POP3
  • It can handle over 10000 connections with a low memory footprint. Nginx can operate multiple web servers via a single IP address and deliver each request to the correct server within a LAN
  • Nginx is one of the best web servers for improving the performance of static content. Additionally, it can also be helpful to serve cache content and perform SSL encryption to lower the load from the webserver
  • It can also be beneficial when optimizing content by compressing it to boost the loading time
  • Nginx can perform randomized experiments or A/B tests without placing JavaScript codes into pages.

Varnish:

Varnish is an open-source HTTP reverse proxy equipped with a cache engine. It is primarily created for high-traffic websites that serve dynamic content. Furthermore, you are free to use Varnish in the form of a load balancer, or a web app firewall (WAF), or an edge authentication and authorization server.

This proxy functions on all latest versions of Linux and FreeBSD, utilized primarily as a front for Apache or Nginx web servers. The efficient and flexible Varnish Configuration Language (VCL) allows you to define various features like managing HTTP requests, caching, and establishing connections to single or multiple web servers.

Due to this reason, several CDNs use Varnish in the form of their crucial foundation for sending content quickly.

Varnish supports Edge Side Includes (ESI), known as a language that assists you to reprocess sections of one web page in some other web pages. If your website uses plenty of recurring content on various pages, ESI can increase the speed of page load times of your site. It does this by caching recurrently used sections.

You can expand Varnish through its different modules (VMODs). Go through Varnish’s official tutorial to know how to set up Varnish in the form of a reverse proxy for WordPress.

Apache Traffic Server:

This is an open-source caching proxy server famous for its quick, scalable features. Formerly, it was a commercial product by Yahoo! However, they turned it to be open source and contributed it to the Apache Foundation for safeguarding.

Certain critical content networks and CDNs like Akamai, Yahoo, LinkedIn, and Apple utilize Apache Traffic Server to control their technology.

Also, you can use Apache HTTP Server (i.e., Apache HTTPd), known as an HTTP server daemon, for setting up a reverse proxy across your web server. Besides behaving as a virtual web server, it assists you in serving static and dynamic content to the users. The later section of the article discusses the setup process of Apache as a reverse proxy.

HAProxy:

HAProxy works as an open-source reverse proxy and also as a load balancer. It is created to incorporate the most prevalent web server architectures like cloud platforms and Linux distributions. Just like Nginx, HAProxy implements an event-driven I/O model. Furthermore, it supports splitting requests over numerous worker procedures.

For HTTP requests, HAProxy works efficiently even when subjected to heavy loads. Few of the substantial traffic websites on the Internet like Airbnb, Instagram, Reddit, Tumblr, Stack Overflow, GitHub, and Imgur use HAProxy to deliver their websites efficiently.

The process to implement HAProxy is beyond the reach of the article. However, you can go through their documentation to know how it works.

Note: Envoy and Traefik are two more open-source substitutes to HAProxy. Both of them are efficient reverse proxies and load balancers with several cutting-edge features.

Few other famous reverse proxies are GLBC, AWS Elastic Load Balancer, Google Cloud Load Balancer, and DigitalOcean Load Balancer. To know about an in-depth list of the premium reverse proxies and load balancers currently in use, check out Stackshare.io.

Reverse Proxy: Use Cases for WordPress Sites:

Chiefly, there are 3 use cases for implementing a reverse proxy for all WordPress sites.

For this example, only Nginx is used because it is the most famous reverse proxy for WordPress sites. However, the same fundamental principles will be valid to other reverse proxies.

Reverse proxies are usually difficult to install, organize, and support. So, Web hosting companies provide a $50 add-on subscription monthly for every reverse proxy that you need assistance with installation. Get further details from the support team of Web hosting companies.

1. Main and Proxied Sites Hosted on the Same Server:

If both the proxy and leading site are hosted on a similar server, the main one can execute a WordPress installation. In contrast, a typical WordPress installation controls the proxy site.

Since you possess access to the sites and their shared web server, it is easy to install the reverse proxy rules for the main website. Subsequently, you can configure the proxy site to process from the reverse proxy.

If both the sites are being hosted at Web hosting companies, you can contact Web hosting companies’ support team. Next, you can request them to install the reverse proxy. The process is as below:

  • Ensure that both the main and the proxy sites are hosted at Web hosting companies. But if not, then you can transfer both sites to Web hosting companies’ setup. You can do that either manually or after delivering a migration request.
  • Use a support ticket to submit a description of the domain configuration to the support team of Web hosting companies. It usually takes one business day to set up the reverse proxy.
  • Web hosting companies will install the appropriate reverse proxy rules on the leading site. Also, it will configure the proxy site to process the reverse proxy.

Below are the standard Nginx reverse proxy directives that Web hosting companies uses to load a subdirectory site across a reverse proxy:

location ^~ /subfolder/ {


proxy_pass http://subfolder.domain.com;


proxy_set_header X-Real-IP $remote_addr;


proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


proxy_set_header X-Forwarded-Proto $scheme;


}

In this code, substitute the /subfolder/ placeholder with the real subdirectory name. Moreover, the http://subfolder.domain.com subdomain must match the URL being used to direct the reverse proxy at the proxied site.

The caret and tilde symbols (^~) are present in the location directive. They inform Nginx that if it comes across the string defined, it must prevent the searching process for subsequent matches and finally use the commands mentioned here. Know in detail on reverse proxy directives of Nginx in its documentation.

After that, configure the proxied site for loading across the reverse proxy. Below are the standard steps that Web hosting companies follows to organize the proxied site:

  • From the location where the proxied site is loaded, you have to make a subdirectory. Every file of the proxied website is shifted to this subdirectory.
  • Revise the configuration files of the webserver to label the new subdirectory as the root directory for that proxied site. Also, you have to add a rewrite rule to discard the subdirectory from the request URL for every request coming in.
  • Revise every URL in the database of the proxied site to be equivalent to the live site URLs (e.g., example.com/blog).
  • Edit the wp-config.php file of the proxied site with $_SERVER[‘HTTP_HOST’] definition, directing to the URL of the main site.
  • If you use an SSL certificate, define rigid rules in the wp-config.php file to prevent redirection loops.

Note: A proxied site cannot make URLs that replica the similar subdirectory within which the proxied site processes. For example, a proxied site at example.com/blog cannot make a directory or page at example.com/blog/blog.

2. Only the Proxied Site Hosted on Your Server:

If there is access only to the proxied site and the corresponding web server, you have to contact the leading site’s server admin. They will help you to set up the reverse proxy rules.

For that, you should implement the same steps mentioned above. Apart from this case, you should configure the rules on two diverse servers.

For hosting your proxied site through Web hosting companies, you need to add a domain to the site that will direct to the reverse proxy. Typically, the subdomain fulfills this purpose (e.g., blog. example.com) to process the proxied site on a subdirectory link (e.g., example.com/blog).

Once your proxied site gets set up on Web hosting companies, feel free to contact the Web hosting companies support team for configuring the proxied site to load on a reverse proxy. During this time, the support team needs the actual IP of your for completion of the setup process to count visits properly. If you cannot provide a static IP because of the dynamic IP restrictions from several providers (like AWS CloudFront), your plan gets transferred to an equivalent bandwidth-based plan.

Finally, the process of the setup of the reverse proxy on your server is not in the scope of Web hosting companies’ support. This is because only the server admin can look after it.

3. Only the Main Site Hosted on Your Server:

If there is access only to the main site and equivalent web server, it is necessary to set up the reverse proxy. Next, construct its rules for loading the proxied site from an outside host. The installation and configuration of the proxied site for loading across the reverse proxy is the duty of the admin of the secondary server.

When your main site is being hosted at Web hosting companies, there will be access to the support team of Web hosting companies. You can create a support ticket to include the standard reverse proxy rules mentioned previously in the article. If needed, you can add some more customizations to those rules.

In the present circumstances, you are entirely accountable for the configuration of the proxied site to load it on the reverse proxy correctly.

How to Set Up Nginx as a Reverse Proxy:

If the situation is such that Web hosting companies do not host your website and the management of servers is your duty, then you should set up the reverse proxy on your own. Also, configure it to direct at the proxied site.

Based on the operating system of your web server, you can install Nginx another way. When using Linux distributions, various Nginx packages can be used depending on the version of your Linux distribution.

In the below example, the primary site is installed at example.com domain name. On the other hand, the proxied WordPress site is set up at subdomain, i.e., blog.domain.com. Both of them are controlled by Apache on a web server operating on Ubuntu 18.04. Moreover, in this example, Nginx is installed and configured in a reverse proxy on the main server.

Firstly, access your server’s terminal through SSH. Next, use the apt-get command for updating the packages list of your distribution and then install Nginx on the webserver you use. Follow the below commands:

sudo apt update
sudo apt install nginx

Now you have to configure Nginx to proxy requests for those domains that are hosted on Apache. For that, prepare a new virtual host file. The present example uses the nano editor to include the code. However, you can use any code editor you like.

sudo nano /etc/nginx/sites-available/example.com.conf

Now set Nginx directives to direct requests to Apache after adding the below server {…} and location blocks:

server {
listen      80;
server_name example.com www.example.com;
index       index.php;
root        /var/www/example.com/public    # fallback for index.php
location / {
try_files $uri $uri/ /index.php?$query_string;
}location /blog {
proxy_pass http://blog.domain.com;proxy_http_version                 1.1;
proxy_cache_bypass                 $http_upgrade;
# Proxy headers
proxy_set_header Upgrade           $http_upgrade;
proxy_set_header Connection        "upgrade";
proxy_set_header Host              $host;
proxy_set_header X-Real-IP         $remote_addr;
proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host  $host;
proxy_set_header X-Forwarded-Port  $server_port;
# Proxy timeouts
proxy_connect_timeout              60s;
proxy_send_timeout                 60s;
proxy_read_timeout                 60s;
}

A subdirectory link, i.e., example.com/blog, is defined in the above code, and it will be hand out by the Apache server. Ensure that you use the public IP address (or URL) of your proxied website in the proxy_pass directive. For this example, the proxied website is hosted over the blog.domain.com subdomain.

Note: Ensure that the proxied website is set up and all set to be served before you make any modifications.

Learn more about every reverse proxy directive used here in Nginx’s complete index of directives.

Now save the virtual host file. Next, activate the fresh virtual host by making a symlink for the files entitled example.com.conf in the /etc/Nginx/sites-available and the /etc/Nginx/sites-enabled directories.

sudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/example.com.conf

After that, test Nginx for any configuration errors.

sudo nginx -t

If there are no errors, reload Nginx to enforce the changes.

sudo systemctl reload nginx

Nginx is now successfully set up to function as a reverse proxy. For confirmation, you can use the phpinfo() function. It helps you to check the PHP variables loaded whenever you visit your proxied site.

Within the SERVER_SOFTWARE and DOCUMENT_ROOT PHP variables, Apache hands out this domain across the backend. However, PHP variables like HTTP_X_REAL_IP and HTTP_X_FORWARDED_FOR validate that Nginx was used as a reverse proxy to direct the requests.

It is possible to enhance the speed of serving the WordPress site on Nginx with the help of the fastcgi_cache and ngx_cache_purge modules. The first module would cache your website, whereas the second module automatically cleans out the cache depending on specific events. The related events can be editing or publishing a WordPress post.

The Nginx Cache Controller WordPress plugin is useful to directly manage the proxy server cache of Nginx from your WordPress admin dashboard. But if you are currently using a WordPress Multisite installation, you have the freedom to use the Nginx Helper plugin.

How to Set up Apache as a Reverse Proxy:

First of all, confirm that you have two websites set up and operating at example.com and blog.domain.com. The first website doesn’t need to be a WordPress site. However, the second one must be a WordPress site because it is primarily used to load the blog of the root domain at the subdirectory link of example.com/blog.

Begin configuration of Apache by opening your server’s terminal through SSH and permitting proxy module of Apache.

sudo a2enmod proxy proxy_http ssl

Executing the above command will most probably restart Apache for reloading the freshly defined directives.

Now, you have to edit the virtual host file of your central server to make a reverse proxy. Below is the code to add:

<VirtualHost *>
DocumentRoot /var/www/app/public
SSLProxyEngine On    ProxyRequests off
ProxyPass /blog http://blog.domain.com
ProxyPassReverse /blog  http://blog.domain.com
</VirtualHost>

The ProxyPass directive creates a reverse proxy for the specified paths. On the other hand, the ProxyPassReverse command will interrupt the HTTP response headers delivered through this reverse proxy and rewrite them to go with the Apache server.

Once the file is saved, edit your wp-config.php file after adding the below code before the line asking you to prevent editing.

# ProxyPass Settings
# overrides the variables below to ensure that any
# request to /blog/* subdirectory is taken care of properly
$_SERVER['REQUEST_URI'] = '/blog' . $_SERVER['REQUEST_URI'];
$_SERVER['SCRIPT_NAME'] = '/blog' . $_SERVER['SCRIPT_NAME'];
$_SERVER['PHP_SELF'] = '/blog' . $_SERVER['PHP_SELF'];

Lastly, you have to update the database of your WordPress site to include the configuration values for /blog subdirectory link. For that, run the below SQL query:

UPDATE wp_options SET option_value = 'https://www.example.com/blog' WHERE option_name IN( 'siteurl', 'home' );

Now you can visit the https://www.example.com/blog URL and host your WordPress site at http://blog.domain.com subdomain load without altering its URL. You can carry on using WordPress as normal for browsing, writing, editing, and managing your site.

Limitations of a Reverse Proxy:

  • A reverse proxy causes a major security risk because it can read and modify all the traffic going through it. When you pass HTTPS traffic via the reverse proxy, it has to decrypt and encrypt the passing data. It implies that it should own the private keys of the SSL/TLS certificate. Hence, if any nasty party can negotiate your reverse proxy, it is allowed to log passwords and insert malware in your websites.
  • If you or your users can’t access your main server directly, using a reverse proxy leads to a single point of failure. To further understand, if you use a reverse proxy as a front to hand out multiple domains, its disconnection turns all the domains offline at once.
  • If you depend on a third-party reverse proxy like Cloudflare, keep in mind that you pass over sensitive info about your site to them. Though they are reliable, it is unpredictable what can be the outcome.
  • Bringing back the backups or letting staging sites go live on websites that load on a reverse proxy stops the proper loading of the proxied site.
  • The process of loading a WordPress Multisite installation on a reverse proxy can prove to be complex and challenging to maintain. That’s why Web hosting companies don’t allow the use of WordPress Multisite on a reverse proxy. But an individual WordPress subdirectory Multisite installation is helpful as an option to proxied sites.

Info:

Web hosting companies CDN possesses extremely low TTFB and famous for significantly improving your site’s performance. Each Web hosting companies account includes a free tier of Web hosting companies CDN. It is easy to set it up in a few seconds.

The majority of the advantages given by CDNs are identical to those offered by the reverse proxies. Now the question is – which one to choose among CDN and a reverse proxy?

You can settle with anyone as per your needs. If a reverse proxy is already installed, you will still notice an improvement in performance and speed from using a CDN. Both of them efficiently caches layer. Moreover, if there are any particular request handling requirements, you can easily configure it with a few custom headers directed by the reverse proxy or the CDN.

Summary:

The above article helps you to learn the complete setup process of a reverse proxy. Being highly flexible, WordPress is helpful as a blog or an e-commerce site, or a Learning Management System. Moreover, in a majority of cases, it is easy to customize WordPress to fulfill your requirements.

Occasionally you might need to use a distinct domain or a secondary server for hosting an extra site. It may be due to different technology stacks, especially for a large enterprise site, or setting up a WordPress blog for a previously set up non-WordPress website.

In both the above cases, a reverse proxy can prove helpful. So, you can gain the maximum benefit of WordPress without any compromise with the main website.