Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serve content from external server via apache

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.

like image 425
Steve Robinson Avatar asked Feb 25 '18 17:02

Steve Robinson


People also ask

How do I serve static content from Apache web server?

Create a directory (also known as a folder) called static in the location of the script that runs the web.py server. Then place the static files you wish to serve in the static folder. For example, the URL http://localhost/static/logo.png will send the image ./static/logo. png to the client.

Where does Apache serve files from?

All the configuration files for Apache are located in /etc/httpd/conf and /etc/httpd/conf. d . The data for websites you'll run with Apache is located in /var/www by default, but you can change that if you want.

How run HTML on Apache server?

Put your HTML files in the C:\Program Files\Apache Group\Apache2\htdocs directory. Let's say you put file test. html there. You can then access it from the browser by typing http://localhost:8080/test.html in the URL area.


2 Answers

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.

like image 95
Elvis Plesky Avatar answered Sep 24 '22 09:09

Elvis Plesky


Not sure whether ask was for a redirection to abc.squarespace.com or proxy the call internally, here are the solutions for both

Redirection : browser will hit abc.com/landing and get a 301 redirect which changes url changes to abc.squarespace.com/landing

Add rule to httd.conf or included vhost file :

RewriteEngine on
RewriteRule   "^/landing/(.+)"  "http://abc.squarespace.com/landing/$1"  [R,L]

Proxy : the abc.squarespace.com under abc.com > browser will not no that the page is served from any downstream domain.

Option 1: Use a rewrite rule with P(proxy) switch

RewriteEngine on
RewriteRule   "^/landing/(.+)"  "http://abc.squarespace.com/landing/$1"  [P]

Option 2: Use a proxypass

ProxyPass "/landing" "http://abc.squarespace.com/landing"
ProxyPassReverse "/landing" "http://abc.squarespace.com/landing"

Additionally, timeout can be specified if needed and also a ProxyRemote can be configured if routing over any internet proxy is needed

Good References

  • https://httpd.apache.org/docs/2.4/rewrite/remapping.html https://httpd.apache.org/docs/2.4/rewrite/flags.html https://httpd.apache.org/docs/2.4/mod/mod_proxy.html
like image 24
Sandeep Nair Avatar answered Sep 21 '22 09:09

Sandeep Nair