Proxying a subdirectory to a remote site

The goal

Make all requests to a previously static page at https://www.example.com/sub/folder on server 1 (Proxy) ACTUALLY go to a Drupal site at https://other.example.com on server 2 (Origin)

This is also getting setup as a multisite, because there are sub/folder2, sub/folder3, etc. that will need to be converted to Drupal sites. I don’t think this has anything to do with the problem, but for the sake of completeness, I’m adding the sites.php changes too below.

What I’ve done so far

Changes on Server 1 (Proxy): Apache config

RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} ^/sub/folder RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} SSLProxyEngine On <Location /sub/folder>   ProxyPass https://other.example.com/   ProxyPassReverse https://other.example.com/   ProxyPassReverseCookiePath / /sub/folder </Location> 

Changes on Server 2 (Origin): settings.php and sites.php

sites.php (because of multisite; and sites/sitename/settings.php is the file I’ll be referencing below)

$sites['other.example.com'] = 'sitename'; $sites['www.example.com.sub.folder'] = 'sitename'; // I don't think this one is necessary, but just in case? 

Aside from the standard DB setup in settings.php, the following has been added:

// $base_url allows for links/URIs to be generated properly // Changing the REQUEST_URI seems to have fixed form issues, like the search block/form // Not sure if the cookie_domain is doing anything/working properly if (isset($_SERVER['HTTP_X_FORWARDED_HOST']) && $_SERVER['HTTP_X_FORWARDED_HOST'] == 'www.example.com') {   $base_url = 'https://www.example.com/sub/folder'; // NO trailing slash!   $_SERVER['REQUEST_URI'] = '/sub/folder' . $_SERVER['REQUEST_URI'];   // (Edit) note don't put 'http' in front of this   $cookie_domain = '.other.example.com'; } ... $conf['reverse_proxy'] = TRUE; ... $conf['reverse_proxy_addresses'] = array('ip.of.origin.server'); 

The problems

  1. Trying to login through www.example.com/sub/folder/user validates (according to Drupal log)… but then it treats the page re-load as an anonymous user and fails access. Presumably, the cookie gets broke/lost/invalidated somehow in between. So, authenticated access to the server has to be done through other.example.com Not a huge problem (since the average Joe won’t be logging in), but…
  2. There’s just a lot of annoying things occuring having to deal with fixing user/content created links and URIs. Currently, links that are first viewed after a cache clear are cached as whatever domain they’re being viewed from. (This happened from using Pathologic module to force absolute URLs.) I realize this might not have been the BEST solution–using Pathologic–but if I fix problem 1., this should become a moot point.

So, I think I’ve got some kind of SSL/Proxy cookie issue at this point… any suggestions?

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Proxying a subdirectory to a remote site

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.