- 07 Jul 2022
- 3 Minutes to read
HubSpot Optimization with Aria
- Updated on 07 Jul 2022
- 3 Minutes to read
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 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.
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.
Please install the Balancer and Accelrator plugin from the Setup -> Modules & Plugins page.
Reverse Proxy Configuration
Go to Balancer -> Group Management and create a HTTP load balancer group using the "Add a Group" tab.
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:
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.
Proceed to Step 2 and:
- Turn Re-encrypt (SSL) on and check the "No Verify/CA file" box.
- Turn "Server side SNI" on.
Save then edit the server entry again and set a SNI hostname in the "Specify Host (Optional)" field.
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.
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.
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.
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.
Go to Accelerator -> Configuration -> Pagespeed and enable Pagespeed globally.
Reload the accelerator or start it if not already running.
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.
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.