Documentation

Set-up the WP Hide PRO on Apache/Nginx Reverse Proxy

Posted in: Getting Started (3) Plugin Options Explained (32) Actions / Filters (25) How To (12)   

This functionality is available for PRO version.

Lately, the Reverse Proxy set-up type for an Apache / Nginx server type become a good alternative to standard set-up to achieve better performance and security:

  • Load Balancing: A reverse proxy can perform load balancing which helps distribute client requests evenly across backend servers. It also improves redundancy as if one server encounter techincal dificulties, the reverse proxy will simply reroute requests to a different server.
  • Helpful when optimizing content by compressing it to boost the loading time
  • Does not require setting up a new process for each web request from the client. Rather, the default configuration is to comprise one work process per CPU
  • Mitigating DDoS Attacks – You can limit the incoming requests and number of connections per single IP address to a value typical for regular users. Nginx also allows you to block or restrict access based on the client location, and the value of the request headers such as “User-Agent” and “Referer”.
  • Increased Security: A reverse proxy also acts as a line of defense for your backend servers. Configuring a reverse proxy ensures that the identity of your backend servers remains unknown.
  • Better Performance: For Nginx has been known to perform better in delivering static content file and analyze URLs
  • Can act as a reverse proxy server for various protocols such as HTTP, HTTPS, TCP, UDP, SMTP, IMAP, and POP3
  • Encrypted Connection By encrypting the connection between the client and the Nginx reverse Proxy with TLS, it will handle and decrypt incoming SSL connections and encrypt the proxied server’s responses..

The most common set-up type is when Main Site and the Proxied Site are located on the same server, this is the easiest to configure and maintain. Generally, the proxied site is deployed within a subdirectory, for our example let’s use /subfolder/

After deploying WP-Hide PRO plugin, the set-up works the very same as on a regular server. Just, the code can’t identify the server-side configuration, so it still generates rewrite rules that include the base /subfolder/ which when using Reverse Proxy is not necessary.

A programmable filter can be used to make adjustments to the rewrites and remove the unwanted prefix. The following example can be used for Nginx server types:



    /**
    * Ensure to change the blog with your own location of WordPress which is being used for the Reverse Proxy set-up
    * 
    * @var mixed
    */
    define ( 'ReverseProxySubdirectoryBase', 'subdomain' );
    
    /**
    * Stripp out the unwanted prefix    
    */
    add_filter( 'wp-hide/mod_rewrite_rules', '_wp_hide_mod_rewrite_rules', 10, 2 );
    function _wp_hide_mod_rewrite_rules( $readable_rules, $server_type )
        {
            
            if ( $server_type   != 'nginx'  ||  ! is_array ( $readable_rules ) ||   count ( $readable_rules ) < 1 )
                return $readable_rules;
                
            foreach ( $readable_rules   as  $key    =>  $data )
                {
                    $readable_rules[ $key ] =   str_replace ( '/' . ReverseProxySubdirectoryBase . '/' , '/' , $data );
                }
            
            return $readable_rules;
               
        }
        
    
    /**
    * Return the rewrite test url
    * 
    * @param mixed $rewrite_test_url
    */
    add_filter( 'wp-hide/nginx_test_sample_rewrite/url', '_wp_hide_nginx_test_sample_rewrite_url' );
    function _wp_hide_nginx_test_sample_rewrite_url( $rewrite_test_url )
        {
            $rewrite_test_url   =   str_replace ( '/' . ReverseProxySubdirectoryBase . '/' , '/' ,  $rewrite_test_url );
            
            return $rewrite_test_url;
        }    
    
    /**
    * Update the used flag time from last to break
    */
    add_filter( 'wp-hide/nginx_flag_type', '_wp_hide_nginx_flag_type' );
    function _wp_hide_nginx_flag_type( $flag_type )
        {
            
            $flag_type  =   'break';
            
            return $flag_type;    
            
        }
        

*The subdomain within ReverseProxySubdirectoryBase constant should be updated accordingly to server proxy set-up.
*The code should be placed within a custom file on /wp-content/mu-plugins/ folder or a custom plugin.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn
Scroll to top