Wednesday, March 7, 2018

Serve content from external server via apache

Leave a Comment

I am running my web app at abc.com with apache as the web server.

I have some static pages hosted on SquareSpace... eg. abc.squarespace.com/landing

I want to configure apache to serve content from abc.squarespace.com when it get's a request for abc.com/landing

I've done this in nginx by using proxy_pass with the backend as abc.squarespace.com for location /landing. But I'm not sure how to do this in Apache. No luck doing research on the web as well.

Thanks in advance.

1 Answers

Answers 1

Message body cannot contain URLs with abc.com, so I will be using example.com and example.squarespace.com.

I believe you are looking for frame forwarding. In order to implement it, use the following steps:

  1. On example.squarespace.com allow frame forwarding from example.com by setting the appropriate HTTP headers via web server configuration:

X-Frame-Options: ALLOW-FROM https://example.com/

For detailed explanation refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options

  1. Verify that Apache mod_proxy_http is enabled at example.com:

# apachectl -M | grep proxy_http proxy_http_module (shared)

  1. Set the following rewrite rules in Apache configuration or .htaccess file to serve content from http://example.squarespace.com/landing

<IfModule proxy_http_module> RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC] RewriteRule ^landing(.*) http://example.squarespace.com/landing [P] </IfModule>

The syntax here is the same as for Apache mod_rewrite.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment