4

I'm more of an engineer than a devops guy, so please excuse me if this is extremely basic.

My situation: I have a server on the example.edu network, so I don't control the main DNS interface to example.edu. Therefore I don't believe I can use DNSSimple or Zerigo. I do however have root on the server, and it has the following two hostnames:

foo.example.edu
bar.example.edu

My goal is to set up Apache to do the following.

  • First, when a visitor types in foo.example.edu they should see a static webpage:

    http://foo.example.edu -> serve up a static webpage

  • Then, if the visitor types in bar.example.edu a URL rewrite should be executed and they should be viewing the HTTPS version of the site hosted on Heroku, as follows:

    http://bar.example.edu -> https://bar-example-edu.herokuapp.com https://bar.example.edu -> https://bar-example-edu.herokuapp.com https://bar.example.edu/some/url -> https://bar-example-edu.herokuapp.com/some/url

  • In particular, this should be a URL rewrite, so in the browser's address bar a visitor would see https://bar.example.edu/some/url rather than https://bar-example-edu.herokuapp.com/some/url.

How do I go about this? I figure I should use Apache mod_rewrite, and edit httpd.conf. I have just started looking at tutorials, but the main tricky part is that I don't have full control over the domain and want to make sure I set things up right.

2 Answers 2

2

Assuming you already have all the necessary Apache VirtualHost directive in place, you basically need to add the following to the port 80 and port 443 VirtualHost directives for "bar.example.com"... (pick one or the other)

OPTION 1: Rewrite Rule Since you indicated you were looking for a rewrite rule, I will post this, but as noted in the reference link below, it is not the best performing way to do this.

RewriteEngine on
RewriteRule ^(.*)$   https://bar-example-edu.herokuapp.com/$1   [P]

REFERENCE: http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p

OPTION 2: Use mod_proxy directly

ProxyPass / https://bar-example-edu.herokuapp.com/
ProxyPassReverse  / https://bar-example-edu.herokuapp.com/

REFERENCE: http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypass

... on a side note, given that the heroku app is using https (SSL), you should probably just put the proxy configuration in the port 443 (ssl) VirtualHost directive, and have the following line in the port 80 VirtualHost:

Redirect / https://bar.example.edu/

... which should direct your visitors to https before they start.

0

Apache configuration for the static site is straight forward (I have left out standard irrelevant lines)

<VirtualHost *:80>
    ServerName foo.example.edu
    DocumentRoot /var/www/foo.example.edu   
</VirtualHost>

The redirect of bar.example.edu can follow the apache guidelines for ssl redirect. I would use the built in redirect as mod_rewrite is not needed in this simple use case.

<VirtualHost *:80>
    ServerName bar.example.edu
    Redirect permanent / https://bar.example.edu/
 </VirtualHost>

And for the redirection to Heroku I would use mod_proxy_http to redirect. The encrypted virtual host can be something like

ProxyRequests Off
<Proxy *>
    AddDefaultCharset off
    Order deny,allow
    Deny from none
</Proxy>
ProxyVia On
<VirtualHost *:443>
    ServerName bar.example.edu
    SSLEngine On 
    SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
    SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
    ProxyPass / https://bar-example-edu.herokuapp.com/
    ProxyPassReverse  / https://bar-example-edu.herokuapp.com/
    ProxyPassReverseCookieDomain  / https://bar-example-edu.herokuapp.com/
 </VirtualHost>

On the Heroku side in your app source code you would create an application with:

 heroku create bar-example-edu

And configure their Custom Domain add-on with

 heroku domains:add bar.example.edu

Adapted slightly from a section of a document I wrote regarding proxying to Heroku.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .