HubSpot Optimization with Aria
  • 07 Jul 2022
  • 3 Minutes to read
  • Dark
    Light

HubSpot Optimization with Aria

  • Dark
    Light

This guide is based on this HubSpot reverse proxy article and can help to implement the HubSpot reverse proxying requirements on Aria.

Aria can both proxy and optimize traffic for HubSpot sites, employing techniques such as on-the-fly pagespeed web asset optimization, compression as well as static and dynamic caching.

HubSpot Requirements

HubSpot origin domain

HubSpot provides several origin domains where HubSpot user sites can be accessed. This can be worked out using your HubID. See information from HubSpot here for determining what your HubSpot sites proxy domain address should be. It should be of the format - XXXXXXX.sites-proxy.hscoscdnXX.net. This is used as the backend server address in the Balancer Configuration section below.

HubSpot Site Domain Registration

If not already registered on your HubSpot account, register the domain you expect your users will use to access your HubSpot site via the Aria proxy. See HubSpot's instructions on this here.
www.example.com is used as an example for the purposes of this guide and will be seen in instructions to follow below.
Once the domain registration on your HubSpot account has been successfully completed, the user access domain e.g. www.example.com can be pointed to your Snapt instance's IP address using a DNS A record on your public DNS provider platform.

Aria Requirements

SSL Certificate

An SSL certificate is required for HTTPS termination. You can upload your own PEM formatted crt and key files for use for SSL termination on Aria. See option 2 on this page for more information for uploading your SSL certificate and key files for use by the Aria accelerator.

Alternatively, Aria's Let's Encrypt v2 plugin can be used to obtain a publicly valid certificate right on the Aria instance. Please see the Let's Encrypt v2 usage guide here.

Required Plugins

Please install the Balancer and Accelrator plugin from the Setup -> Modules & Plugins page.

Reverse Proxy Configuration

Balancer Configuration

Go to Balancer -> Group Management and create a HTTP load balancer group using the "Add a Group" tab.

Screenshot 2022-06-03 201411

Provide a name for the group, select the "127.0.0.1" listening IP address and set an unused port number e.g. 2000.

Proceed to Step 2 and set the group's balance method and mode as shown below:

Screenshot 2022-06-03 201608

Save then add the HubSpot upstream server information. Use the HubSpot domain allocated to your account as determined by the HubSpot site proxy setup guide here in the "IP Address" field, and port 443.

Screenshot 2022-06-03 201859

Proceed to Step 2 and:

  • Turn Re-encrypt (SSL) on and check the "No Verify/CA file" box.
  • Turn "Server side SNI" on.

Screenshot 2022-06-03 223347

Save then edit the server entry again and set a SNI hostname in the "Specify Host (Optional)" field.

Screenshot 2022-06-03 223700

Save the change and reload the balancer if running or start it otherwise.

Web Accelerator Configuration

Go to Accelerator -> Create an Accelerator.
Name the accelerator frontend and select the IP that will be exposed for user connections on the Aria machine. Set the port to 443 and select your certificate and key files. Enable pagespeed and caching on the frontend. With the Upstream option set to Balancer, select the Balancer Group that was created above.

Screenshot 2022-06-03 202655

Then edit the accelerator frontend created, add the Hubspot domain for your site to the "Server (Host) Name" field, enable underscores in headers and HTTP/2.

Screenshot 2022-06-03 202838

Caching Profile, Pagespeed and Insertion of required headers for HubSpot site proxying

Go to Accelerator -> Caching -> Cache Profiles and add a new cache profile. Name the cache profile and proceed to replace the content of the "Custom Headers (Advanced)" field with the following, making sure to use the appropriate domain for your HubSpot site instead of www.example.com.

Accept-Encoding ""
Host $http_host
X-HS-Public-Host www.example.com
X-HubSpot-Trust-Forwarded-For true
X-Real-IP $proxy_protocol_addr
X-Forwarded-Proto $scheme
X-Forwarded-For $proxy_add_x_forwarded_for
X-HubSpot-Client-IP $proxy_protocol_addr

Change the value of the "Cache Key [Advanced]" field to $host$request_uri.

Screenshot 2022-06-03 230942

Then go to Accelerator -> SSL Frontends, edit the frontend previously created and select the newly created cache profile in the cache options section of the accelerator frontend settings.

Screenshot 2022-06-03 203503

Go to Accelerator -> Configuration -> Pagespeed and enable Pagespeed globally.

Screenshot 2022-06-03 205859

Reload the accelerator or start it if not already running.

Testing

Once the domain registered with Hubspot for accessing (www.example.com in this example) is resolving to the IP of the Aria instance configured via a DNS A record, visit the foloowing pages for some diagnostic information about the proxy setup.

https://www.example.com/_hcms/diagnostics
https://www.example.com/_hcms/_worker/headers

Or via CLI using curl:

curl -k --resolve www.example.com:443:<ARIA IP> https://www.example.com/_hcms/diagnostics

curl -k --resolve www.example.com:443:<ARIA IP> https://www.example.com/_hcms/_worker/headers

HubSpot provides information for confirming that proxying has been properly setup here based on the responses from the diagnostics links above.